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; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 126 | class LocalContext; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 128 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 130 | class ObjectOperationDescriptor; |
| 131 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 133 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 135 | class StackFrame; |
| 136 | class StackTrace; |
| 137 | class String; |
| 138 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 139 | class Symbol; |
| 140 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 141 | class Uint32; |
| 142 | class Utils; |
| 143 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | template <class T> class Handle; |
| 145 | template <class T> class Local; |
| 146 | template <class T> class Persistent; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 148 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 149 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 150 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | class HeapObject; |
| 152 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 153 | class Object; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 154 | } |
| 155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 157 | /** |
| 158 | * General purpose unique identifier. |
| 159 | */ |
| 160 | class UniqueId { |
| 161 | public: |
| 162 | explicit UniqueId(intptr_t data) |
| 163 | : data_(data) {} |
| 164 | |
| 165 | bool operator==(const UniqueId& other) const { |
| 166 | return data_ == other.data_; |
| 167 | } |
| 168 | |
| 169 | bool operator!=(const UniqueId& other) const { |
| 170 | return data_ != other.data_; |
| 171 | } |
| 172 | |
| 173 | bool operator<(const UniqueId& other) const { |
| 174 | return data_ < other.data_; |
| 175 | } |
| 176 | |
| 177 | private: |
| 178 | intptr_t data_; |
| 179 | }; |
| 180 | |
| 181 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 182 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | |
| 184 | |
| 185 | /** |
| 186 | * A weak reference callback function. |
| 187 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 188 | * This callback should either explicitly invoke Dispose on |object| if |
| 189 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 190 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | * \param object the weak global object to be reclaimed by the garbage collector |
| 192 | * \param parameter the value passed in when making the weak global object |
| 193 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 194 | template<typename T, typename P> |
| 195 | class WeakReferenceCallbacks { |
| 196 | public: |
| 197 | typedef void (*Revivable)(Isolate* isolate, |
| 198 | Persistent<T>* object, |
| 199 | P* parameter); |
| 200 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 202 | // TODO(svenpanne) Temporary definition until Chrome is in sync. |
| 203 | typedef void (*NearDeathCallback)(Isolate* isolate, |
| 204 | Persistent<Value> object, |
| 205 | void* parameter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 207 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 209 | #define TYPE_CHECK(T, S) \ |
| 210 | while (false) { \ |
| 211 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | } |
| 213 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 214 | |
| 215 | #define V8_USE_UNSAFE_HANDLES |
| 216 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | /** |
| 218 | * An object reference managed by the v8 garbage collector. |
| 219 | * |
| 220 | * All objects returned from v8 have to be tracked by the garbage |
| 221 | * collector so that it knows that the objects are still alive. Also, |
| 222 | * because the garbage collector may move objects, it is unsafe to |
| 223 | * point directly to an object. Instead, all objects are stored in |
| 224 | * handles which are known by the garbage collector and updated |
| 225 | * whenever an object moves. Handles should always be passed by value |
| 226 | * (except in cases like out-parameters) and they should never be |
| 227 | * allocated on the heap. |
| 228 | * |
| 229 | * There are two types of handles: local and persistent handles. |
| 230 | * Local handles are light-weight and transient and typically used in |
| 231 | * local operations. They are managed by HandleScopes. Persistent |
| 232 | * handles can be used when storing objects across several independent |
| 233 | * operations and have to be explicitly deallocated when they're no |
| 234 | * longer used. |
| 235 | * |
| 236 | * It is safe to extract the object stored in the handle by |
| 237 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 238 | * 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] | 239 | * behind the scenes and the same rules apply to these values as to |
| 240 | * their handles. |
| 241 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 242 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | /** |
| 245 | * Creates an empty handle. |
| 246 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 247 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 249 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | /** |
| 251 | * Creates a new handle for the specified value. |
| 252 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 253 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 254 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Creates a handle for the contents of the specified handle. This |
| 258 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 259 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 261 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | * between compatible handles, for instance assigning a |
| 263 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 264 | * because String is a subclass of Value. |
| 265 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 266 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | : val_(reinterpret_cast<T*>(*that)) { |
| 268 | /** |
| 269 | * This check fails when trying to convert between incompatible |
| 270 | * handles. For example, converting from a Handle<String> to a |
| 271 | * Handle<Number>. |
| 272 | */ |
| 273 | TYPE_CHECK(T, S); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Returns true if the handle is empty. |
| 278 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 279 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | /** |
| 282 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 283 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 284 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 285 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 286 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 287 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 288 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * Checks whether two handles are the same. |
| 292 | * Returns true if both are empty, or if the objects |
| 293 | * to which they refer are identical. |
| 294 | * The handles' references are not checked. |
| 295 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 296 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 297 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 298 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | if (a == 0) return b == 0; |
| 300 | if (b == 0) return false; |
| 301 | return *a == *b; |
| 302 | } |
| 303 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 304 | #ifndef V8_USE_UNSAFE_HANDLES |
| 305 | template <class S> V8_INLINE( |
| 306 | bool operator==(const Persistent<S>& that) const) { |
| 307 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 308 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 309 | if (a == 0) return b == 0; |
| 310 | if (b == 0) return false; |
| 311 | return *a == *b; |
| 312 | } |
| 313 | #endif |
| 314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | /** |
| 316 | * Checks whether two handles are different. |
| 317 | * Returns true if only one of the handles is empty, or if |
| 318 | * the objects to which they refer are different. |
| 319 | * The handles' references are not checked. |
| 320 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 321 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | return !operator==(that); |
| 323 | } |
| 324 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 325 | 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] | 326 | #ifdef V8_ENABLE_CHECKS |
| 327 | // If we're going to perform the type check then we have to check |
| 328 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 329 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 330 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | return Handle<T>(T::Cast(*that)); |
| 332 | } |
| 333 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 334 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 335 | return Handle<S>::Cast(*this); |
| 336 | } |
| 337 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 338 | #ifndef V8_USE_UNSAFE_HANDLES |
| 339 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 340 | return New(isolate, that.val_); |
| 341 | } |
| 342 | // TODO(dcarney): remove before cutover |
| 343 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 344 | return New(isolate, that.val_); |
| 345 | } |
| 346 | |
| 347 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 350 | #endif |
| 351 | /** |
| 352 | * Creates a new handle for the specified value. |
| 353 | */ |
| 354 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 355 | #endif |
| 356 | |
| 357 | private: |
| 358 | template<class F> |
| 359 | friend class Persistent; |
| 360 | template<class F> |
| 361 | friend class Local; |
| 362 | friend class Arguments; |
| 363 | friend class String; |
| 364 | friend class Object; |
| 365 | friend class AccessorInfo; |
| 366 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 367 | friend Handle<Primitive> Null(Isolate* isolate); |
| 368 | friend Handle<Boolean> True(Isolate* isolate); |
| 369 | friend Handle<Boolean> False(Isolate* isolate); |
| 370 | friend class Context; |
| 371 | friend class InternalHandleHelper; |
| 372 | friend class LocalContext; |
| 373 | |
| 374 | #ifndef V8_USE_UNSAFE_HANDLES |
| 375 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 376 | #endif |
| 377 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | T* val_; |
| 379 | }; |
| 380 | |
| 381 | |
| 382 | /** |
| 383 | * A light-weight stack-allocated object handle. All operations |
| 384 | * that return objects from within v8 return them in local handles. They |
| 385 | * are created within HandleScopes, and all local handles allocated within a |
| 386 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 387 | * is not necessary to explicitly deallocate local handles. |
| 388 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 389 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 390 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 392 | V8_INLINE(Local()); |
| 393 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 395 | /** |
| 396 | * This check fails when trying to convert between incompatible |
| 397 | * handles. For example, converting from a Handle<String> to a |
| 398 | * Handle<Number>. |
| 399 | */ |
| 400 | TYPE_CHECK(T, S); |
| 401 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 402 | |
| 403 | |
| 404 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 405 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 406 | #endif |
| 407 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 408 | 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] | 409 | #ifdef V8_ENABLE_CHECKS |
| 410 | // If we're going to perform the type check then we have to check |
| 411 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 413 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | return Local<T>(T::Cast(*that)); |
| 415 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 416 | #ifndef V8_USE_UNSAFE_HANDLES |
| 417 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 418 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 419 | TYPE_CHECK(T, S); |
| 420 | } |
| 421 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 422 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 423 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 424 | return Local<S>::Cast(*this); |
| 425 | } |
| 426 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 427 | /** |
| 428 | * Create a local handle for the content of another handle. |
| 429 | * The referee is kept alive by the local handle even when |
| 430 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 432 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 433 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 434 | #ifndef V8_USE_UNSAFE_HANDLES |
| 435 | // TODO(dcarney): remove before cutover |
| 436 | V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 438 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 439 | |
| 440 | private: |
| 441 | #endif |
| 442 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 443 | #endif |
| 444 | |
| 445 | private: |
| 446 | template<class F> |
| 447 | friend class Persistent; |
| 448 | template<class F> |
| 449 | friend class Handle; |
| 450 | friend class Arguments; |
| 451 | friend class String; |
| 452 | friend class Object; |
| 453 | friend class AccessorInfo; |
| 454 | friend class Context; |
| 455 | friend class InternalHandleHelper; |
| 456 | friend class LocalContext; |
| 457 | |
| 458 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 459 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 463 | * 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] | 464 | * allocated, a Persistent handle remains valid until it is explicitly |
| 465 | * disposed. |
| 466 | * |
| 467 | * A persistent handle contains a reference to a storage cell within |
| 468 | * the v8 engine which holds an object value and which is updated by |
| 469 | * the garbage collector whenever the object is moved. A new storage |
| 470 | * cell can be created using Persistent::New and existing handles can |
| 471 | * be disposed using Persistent::Dispose. Since persistent handles |
| 472 | * are passed by value you may have many persistent handle objects |
| 473 | * that point to the same storage cell. For instance, if you pass a |
| 474 | * persistent handle as an argument to a function you will not get two |
| 475 | * different storage cells but rather two references to the same |
| 476 | * storage cell. |
| 477 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 478 | template <class T> class Persistent // NOLINT |
| 479 | #ifdef V8_USE_UNSAFE_HANDLES |
| 480 | : public Handle<T> { |
| 481 | #else |
| 482 | { // NOLINT |
| 483 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 485 | #ifndef V8_USE_UNSAFE_HANDLES |
| 486 | V8_INLINE(Persistent()) : val_(0) { } |
| 487 | V8_INLINE(~Persistent()) { |
| 488 | // TODO(dcarney): add this back before cutover. |
| 489 | // Dispose(); |
| 490 | } |
| 491 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 492 | // TODO(dcarney): remove somehow before cutover |
| 493 | // The handle should either be 0, or a pointer to a live cell. |
| 494 | V8_INLINE(void Clear()) { val_ = 0; } |
| 495 | |
| 496 | /** |
| 497 | * A constructor that creates a new global cell pointing to that. In contrast |
| 498 | * to the copy constructor, this creates a new persistent handle which needs |
| 499 | * to be separately disposed. |
| 500 | */ |
| 501 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 502 | : val_(*New(isolate, that)) { } |
| 503 | |
| 504 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 505 | /** |
| 506 | * Creates an empty persistent handle that doesn't point to any |
| 507 | * storage cell. |
| 508 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 509 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | |
| 511 | /** |
| 512 | * Creates a persistent handle for the same storage cell as the |
| 513 | * specified handle. This constructor allows you to pass persistent |
| 514 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 515 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 516 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 517 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | * between compatible persistent handles, for instance assigning a |
| 519 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 520 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 522 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 524 | /** |
| 525 | * This check fails when trying to convert between incompatible |
| 526 | * handles. For example, converting from a Handle<String> to a |
| 527 | * Handle<Number>. |
| 528 | */ |
| 529 | TYPE_CHECK(T, S); |
| 530 | } |
| 531 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 532 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 534 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 535 | * A constructor that creates a new global cell pointing to that. In contrast |
| 536 | * to the copy constructor, this creates a new persistent handle which needs |
| 537 | * to be separately disposed. |
| 538 | */ |
| 539 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 540 | : Handle<T>(New(isolate, that)) { } |
| 541 | |
| 542 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 543 | * "Casts" a plain handle which is known to be a persistent handle |
| 544 | * to a persistent handle. |
| 545 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 546 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | : Handle<T>(*that) { } |
| 548 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 549 | #endif |
| 550 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 551 | 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] | 552 | #ifdef V8_ENABLE_CHECKS |
| 553 | // If we're going to perform the type check then we have to check |
| 554 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 556 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | return Persistent<T>(T::Cast(*that)); |
| 558 | } |
| 559 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 560 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 561 | return Persistent<S>::Cast(*this); |
| 562 | } |
| 563 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 564 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 565 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 567 | * 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] | 568 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 569 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 570 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 571 | #ifndef V8_USE_UNSAFE_HANDLES |
| 572 | // TODO(dcarney): remove before cutover |
| 573 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 574 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 575 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 576 | #ifndef V8_USE_UNSAFE_HANDLES |
| 577 | template <class S> V8_INLINE( |
| 578 | bool operator==(const Persistent<S>& that) const) { |
| 579 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 580 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 581 | if (a == 0) return b == 0; |
| 582 | if (b == 0) return false; |
| 583 | return *a == *b; |
| 584 | } |
| 585 | |
| 586 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 587 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 588 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 589 | if (a == 0) return b == 0; |
| 590 | if (b == 0) return false; |
| 591 | return *a == *b; |
| 592 | } |
| 593 | #endif |
| 594 | |
| 595 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * Releases the storage cell referenced by this persistent handle. |
| 599 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 600 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | * cell remain and IsEmpty will still return false. |
| 602 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 603 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 604 | V8_INLINE(void Dispose(Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 606 | template<typename S, typename P> |
| 607 | V8_INLINE(void MakeWeak( |
| 608 | Isolate* isolate, |
| 609 | P* parameters, |
| 610 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 611 | |
| 612 | template<typename P> |
| 613 | V8_INLINE(void MakeWeak( |
| 614 | Isolate* isolate, |
| 615 | P* parameters, |
| 616 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 617 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | /** |
| 619 | * Make the reference to this object weak. When only weak handles |
| 620 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 621 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | * it the object reference and the given parameters. |
| 623 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 624 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 625 | V8_INLINE(void MakeWeak(Isolate* isolate, |
| 626 | void* parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 627 | NearDeathCallback callback)); |
| 628 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 629 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 631 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 632 | V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 633 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 634 | V8_INLINE(void MarkIndependent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | |
| 636 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 637 | * Marks the reference to this object independent. Garbage collector is free |
| 638 | * to ignore any object groups containing this object. Weak callback for an |
| 639 | * independent handle should not assume that it will be preceded by a global |
| 640 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 641 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 642 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 643 | V8_INLINE(void MarkIndependent(Isolate* isolate)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 644 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 645 | V8_INLINE(void MarkPartiallyDependent()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 646 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 647 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 648 | * Marks the reference to this object partially dependent. Partially dependent |
| 649 | * handles only depend on other partially dependent handles and these |
| 650 | * dependencies are provided through object groups. It provides a way to build |
| 651 | * smaller object groups for young objects that represent only a subset of all |
| 652 | * external dependencies. This mark is automatically cleared after each |
| 653 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 654 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 655 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 656 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 657 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 658 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 659 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 660 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 661 | V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 662 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 663 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 664 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 665 | /** Checks if the handle holds the only reference to an object. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 666 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 667 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 668 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 669 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 671 | /** Returns true if the handle's reference is weak. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 672 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 673 | V8_INLINE(bool IsWeak(Isolate* isolate) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 675 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 676 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 677 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 678 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 679 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 680 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 681 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 682 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 683 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 684 | V8_INLINE(uint16_t WrapperClassId() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 685 | |
| 686 | /** |
| 687 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 688 | * was previously assigned. |
| 689 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 690 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 691 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 692 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 693 | /** |
| 694 | * Disposes the current contents of the handle and replaces it. |
| 695 | */ |
| 696 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 697 | |
| 698 | #ifndef V8_USE_UNSAFE_HANDLES |
| 699 | |
| 700 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 701 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 703 | #endif |
| 704 | // TODO(dcarney): make unlinkable before cutover |
| 705 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 706 | // TODO(dcarney): make unlinkable before cutover |
| 707 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 708 | this->val_ = that.val_; |
| 709 | return *this; |
| 710 | } |
| 711 | |
| 712 | public: |
| 713 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 714 | |
| 715 | private: |
| 716 | #endif |
| 717 | // TODO(dcarney): remove before cutover |
| 718 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 719 | // TODO(dcarney): remove before cutover |
| 720 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 721 | : val_(*that) { |
| 722 | TYPE_CHECK(T, S); |
| 723 | } |
| 724 | // TODO(dcarney): remove before cutover |
| 725 | V8_INLINE(T* operator*() const) { return val_; } |
| 726 | public: |
| 727 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 728 | |
| 729 | private: |
| 730 | #endif |
| 731 | // TODO(dcarney): remove before cutover |
| 732 | V8_INLINE(T* operator->() const) { return val_; } |
| 733 | public: |
| 734 | #endif |
| 735 | |
| 736 | private: |
| 737 | template<class F> |
| 738 | friend class Handle; |
| 739 | template<class F> |
| 740 | friend class Local; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 741 | friend class ImplementationUtilities; |
| 742 | friend class ObjectTemplate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 743 | friend class Context; |
| 744 | friend class InternalHandleHelper; |
| 745 | friend class LocalContext; |
| 746 | |
| 747 | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 748 | |
| 749 | #ifndef V8_USE_UNSAFE_HANDLES |
| 750 | T* val_; |
| 751 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
| 754 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 755 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 756 | * A stack-allocated class that governs a number of local handles. |
| 757 | * After a handle scope has been created, all local handles will be |
| 758 | * allocated within that handle scope until either the handle scope is |
| 759 | * deleted or another handle scope is created. If there is already a |
| 760 | * 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] | 761 | * 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] | 762 | * new handles will again be allocated in the original handle scope. |
| 763 | * |
| 764 | * After the handle scope of a local handle has been deleted the |
| 765 | * garbage collector will no longer track the object stored in the |
| 766 | * handle and may deallocate it. The behavior of accessing a handle |
| 767 | * for which the handle scope has been deleted is undefined. |
| 768 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 769 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 770 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 771 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 772 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 774 | HandleScope(Isolate* isolate); |
| 775 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 776 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | |
| 778 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 779 | * Closes the handle scope and returns the value as a handle in the |
| 780 | * previous scope, which is the new current scope after the call. |
| 781 | */ |
| 782 | template <class T> Local<T> Close(Handle<T> value); |
| 783 | |
| 784 | /** |
| 785 | * Counts the number of allocated handles. |
| 786 | */ |
| 787 | static int NumberOfHandles(); |
| 788 | |
| 789 | /** |
| 790 | * Creates a new handle with the given value. |
| 791 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 792 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 793 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 794 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 795 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 796 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | |
| 798 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 799 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 800 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 801 | HandleScope(const HandleScope&); |
| 802 | void operator=(const HandleScope&); |
| 803 | void* operator new(size_t size); |
| 804 | void operator delete(void*, size_t); |
| 805 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 806 | // This Data class is accessible internally as HandleScopeData through a |
| 807 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 808 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 809 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 810 | internal::Object** next; |
| 811 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 812 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 813 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 815 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 816 | } |
| 817 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 818 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 819 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 820 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 822 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 823 | internal::Object** prev_next_; |
| 824 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 825 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 826 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 827 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 828 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 829 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | friend class ImplementationUtilities; |
| 832 | }; |
| 833 | |
| 834 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 835 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 836 | |
| 837 | |
| 838 | /** |
| 839 | * The superclass of values and API object templates. |
| 840 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 841 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | private: |
| 843 | Data(); |
| 844 | }; |
| 845 | |
| 846 | |
| 847 | /** |
| 848 | * Pre-compilation data that can be associated with a script. This |
| 849 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 850 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 851 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 853 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 854 | public: |
| 855 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 856 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 857 | /** |
| 858 | * Pre-compiles the specified script (context-independent). |
| 859 | * |
| 860 | * \param input Pointer to UTF-8 script source code. |
| 861 | * \param length Length of UTF-8 script source code. |
| 862 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 865 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 866 | * Pre-compiles the specified script (context-independent). |
| 867 | * |
| 868 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 869 | * without using Lockers. |
| 870 | * |
| 871 | * \param source Script source code. |
| 872 | */ |
| 873 | static ScriptData* PreCompile(Handle<String> source); |
| 874 | |
| 875 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 876 | * Load previous pre-compilation data. |
| 877 | * |
| 878 | * \param data Pointer to data returned by a call to Data() of a previous |
| 879 | * ScriptData. Ownership is not transferred. |
| 880 | * \param length Length of data. |
| 881 | */ |
| 882 | static ScriptData* New(const char* data, int length); |
| 883 | |
| 884 | /** |
| 885 | * Returns the length of Data(). |
| 886 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 888 | |
| 889 | /** |
| 890 | * Returns a serialized representation of this ScriptData that can later be |
| 891 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 892 | */ |
| 893 | virtual const char* Data() = 0; |
| 894 | |
| 895 | /** |
| 896 | * Returns true if the source code could not be parsed. |
| 897 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 898 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | }; |
| 900 | |
| 901 | |
| 902 | /** |
| 903 | * The origin, within a file, of a script. |
| 904 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 905 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 906 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 907 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 908 | Handle<Value> resource_name, |
| 909 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 910 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | : resource_name_(resource_name), |
| 912 | resource_line_offset_(resource_line_offset), |
| 913 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 914 | V8_INLINE(Handle<Value> ResourceName() const); |
| 915 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 916 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 917 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 918 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 919 | Handle<Integer> resource_line_offset_; |
| 920 | Handle<Integer> resource_column_offset_; |
| 921 | }; |
| 922 | |
| 923 | |
| 924 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 925 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 926 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 927 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 928 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 929 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 930 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 931 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 932 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 933 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 934 | * when New() returns |
| 935 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 936 | * using pre_data speeds compilation if it's done multiple times. |
| 937 | * Owned by caller, no references are kept when New() returns. |
| 938 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 939 | * 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] | 940 | * available to compile event handlers. |
| 941 | * \return Compiled script object (context independent; when run it |
| 942 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 944 | static Local<Script> New(Handle<String> source, |
| 945 | ScriptOrigin* origin = NULL, |
| 946 | ScriptData* pre_data = NULL, |
| 947 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 949 | /** |
| 950 | * Compiles the specified script using the specified file name |
| 951 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 952 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 953 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 954 | * \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] | 955 | * as the script's origin. |
| 956 | * \return Compiled script object (context independent; when run it |
| 957 | * will use the currently entered context). |
| 958 | */ |
| 959 | static Local<Script> New(Handle<String> source, |
| 960 | Handle<Value> file_name); |
| 961 | |
| 962 | /** |
| 963 | * Compiles the specified script (bound to current context). |
| 964 | * |
| 965 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 966 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 967 | * when Compile() returns |
| 968 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 969 | * using pre_data speeds compilation if it's done multiple times. |
| 970 | * Owned by caller, no references are kept when Compile() returns. |
| 971 | * \param script_data Arbitrary data associated with script. Using |
| 972 | * this has same effect as calling SetData(), but makes data available |
| 973 | * earlier (i.e. to compile event handlers). |
| 974 | * \return Compiled script object, bound to the context that was active |
| 975 | * when this function was called. When run it will always use this |
| 976 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 977 | */ |
| 978 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 979 | ScriptOrigin* origin = NULL, |
| 980 | ScriptData* pre_data = NULL, |
| 981 | Handle<String> script_data = Handle<String>()); |
| 982 | |
| 983 | /** |
| 984 | * Compiles the specified script using the specified file name |
| 985 | * object (typically a string) as the script's origin. |
| 986 | * |
| 987 | * \param source Script source code. |
| 988 | * \param file_name File name to use as script's origin |
| 989 | * \param script_data Arbitrary data associated with script. Using |
| 990 | * this has same effect as calling SetData(), but makes data available |
| 991 | * earlier (i.e. to compile event handlers). |
| 992 | * \return Compiled script object, bound to the context that was active |
| 993 | * when this function was called. When run it will always use this |
| 994 | * context. |
| 995 | */ |
| 996 | static Local<Script> Compile(Handle<String> source, |
| 997 | Handle<Value> file_name, |
| 998 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 999 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1000 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1001 | * Runs the script returning the resulting value. If the script is |
| 1002 | * context independent (created using ::New) it will be run in the |
| 1003 | * currently entered context. If it is context specific (created |
| 1004 | * using ::Compile) it will be run in the context in which it was |
| 1005 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1006 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1007 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1008 | |
| 1009 | /** |
| 1010 | * Returns the script id value. |
| 1011 | */ |
| 1012 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1013 | |
| 1014 | /** |
| 1015 | * Associate an additional data object with the script. This is mainly used |
| 1016 | * with the debugger as this data object is only available through the |
| 1017 | * debugger API. |
| 1018 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1019 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1020 | |
| 1021 | /** |
| 1022 | * Returns the name value of one Script. |
| 1023 | */ |
| 1024 | Handle<Value> GetScriptName(); |
| 1025 | |
| 1026 | /** |
| 1027 | * Returns zero based line number of the code_pos location in the script. |
| 1028 | * -1 will be returned if no information available. |
| 1029 | */ |
| 1030 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | }; |
| 1032 | |
| 1033 | |
| 1034 | /** |
| 1035 | * An error message. |
| 1036 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1037 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1038 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1039 | Local<String> Get() const; |
| 1040 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1041 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1042 | /** |
| 1043 | * Returns the resource name for the script from where the function causing |
| 1044 | * the error originates. |
| 1045 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1046 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1048 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1049 | * Returns the resource data for the script from where the function causing |
| 1050 | * the error originates. |
| 1051 | */ |
| 1052 | Handle<Value> GetScriptData() const; |
| 1053 | |
| 1054 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1055 | * Exception stack trace. By default stack traces are not captured for |
| 1056 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1057 | * to change this option. |
| 1058 | */ |
| 1059 | Handle<StackTrace> GetStackTrace() const; |
| 1060 | |
| 1061 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1062 | * Returns the number, 1-based, of the line where the error occurred. |
| 1063 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1064 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1065 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1066 | /** |
| 1067 | * Returns the index within the script of the first character where |
| 1068 | * the error occurred. |
| 1069 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1070 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1071 | |
| 1072 | /** |
| 1073 | * Returns the index within the script of the last character where |
| 1074 | * the error occurred. |
| 1075 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1076 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1077 | |
| 1078 | /** |
| 1079 | * Returns the index within the line of the first character where |
| 1080 | * the error occurred. |
| 1081 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1082 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1083 | |
| 1084 | /** |
| 1085 | * Returns the index within the line of the last character where |
| 1086 | * the error occurred. |
| 1087 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1088 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1089 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1091 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1092 | |
| 1093 | static const int kNoLineNumberInfo = 0; |
| 1094 | static const int kNoColumnInfo = 0; |
| 1095 | }; |
| 1096 | |
| 1097 | |
| 1098 | /** |
| 1099 | * Representation of a JavaScript stack trace. The information collected is a |
| 1100 | * snapshot of the execution stack and the information remains valid after |
| 1101 | * execution continues. |
| 1102 | */ |
| 1103 | class V8EXPORT StackTrace { |
| 1104 | public: |
| 1105 | /** |
| 1106 | * Flags that determine what information is placed captured for each |
| 1107 | * StackFrame when grabbing the current stack trace. |
| 1108 | */ |
| 1109 | enum StackTraceOptions { |
| 1110 | kLineNumber = 1, |
| 1111 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1112 | kScriptName = 1 << 2, |
| 1113 | kFunctionName = 1 << 3, |
| 1114 | kIsEval = 1 << 4, |
| 1115 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1116 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1117 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1118 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1119 | }; |
| 1120 | |
| 1121 | /** |
| 1122 | * Returns a StackFrame at a particular index. |
| 1123 | */ |
| 1124 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1125 | |
| 1126 | /** |
| 1127 | * Returns the number of StackFrames. |
| 1128 | */ |
| 1129 | int GetFrameCount() const; |
| 1130 | |
| 1131 | /** |
| 1132 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1133 | */ |
| 1134 | Local<Array> AsArray(); |
| 1135 | |
| 1136 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1137 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1138 | * |
| 1139 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1140 | * \param options Enumerates the set of things we will capture for each |
| 1141 | * StackFrame. |
| 1142 | */ |
| 1143 | static Local<StackTrace> CurrentStackTrace( |
| 1144 | int frame_limit, |
| 1145 | StackTraceOptions options = kOverview); |
| 1146 | }; |
| 1147 | |
| 1148 | |
| 1149 | /** |
| 1150 | * A single JavaScript stack frame. |
| 1151 | */ |
| 1152 | class V8EXPORT StackFrame { |
| 1153 | public: |
| 1154 | /** |
| 1155 | * Returns the number, 1-based, of the line for the associate function call. |
| 1156 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1157 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1158 | * when capturing the StackTrace. |
| 1159 | */ |
| 1160 | int GetLineNumber() const; |
| 1161 | |
| 1162 | /** |
| 1163 | * Returns the 1-based column offset on the line for the associated function |
| 1164 | * call. |
| 1165 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1166 | * the column number, or if kColumnOffset was not passed as an option when |
| 1167 | * capturing the StackTrace. |
| 1168 | */ |
| 1169 | int GetColumn() const; |
| 1170 | |
| 1171 | /** |
| 1172 | * Returns the name of the resource that contains the script for the |
| 1173 | * function for this StackFrame. |
| 1174 | */ |
| 1175 | Local<String> GetScriptName() const; |
| 1176 | |
| 1177 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1178 | * Returns the name of the resource that contains the script for the |
| 1179 | * function for this StackFrame or sourceURL value if the script name |
| 1180 | * is undefined and its source ends with //@ sourceURL=... string. |
| 1181 | */ |
| 1182 | Local<String> GetScriptNameOrSourceURL() const; |
| 1183 | |
| 1184 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1185 | * Returns the name of the function associated with this stack frame. |
| 1186 | */ |
| 1187 | Local<String> GetFunctionName() const; |
| 1188 | |
| 1189 | /** |
| 1190 | * Returns whether or not the associated function is compiled via a call to |
| 1191 | * eval(). |
| 1192 | */ |
| 1193 | bool IsEval() const; |
| 1194 | |
| 1195 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1196 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1197 | * constructor via "new". |
| 1198 | */ |
| 1199 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1200 | }; |
| 1201 | |
| 1202 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1203 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1204 | |
| 1205 | |
| 1206 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1207 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1208 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1209 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1210 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1211 | /** |
| 1212 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1213 | * 4.3.10. |
| 1214 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1215 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1216 | |
| 1217 | /** |
| 1218 | * Returns true if this value is the null value. See ECMA-262 |
| 1219 | * 4.3.11. |
| 1220 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1221 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1222 | |
| 1223 | /** |
| 1224 | * Returns true if this value is true. |
| 1225 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1226 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1227 | |
| 1228 | /** |
| 1229 | * Returns true if this value is false. |
| 1230 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1231 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1232 | |
| 1233 | /** |
| 1234 | * Returns true if this value is an instance of the String type. |
| 1235 | * See ECMA-262 8.4. |
| 1236 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1237 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | |
| 1239 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1240 | * Returns true if this value is a symbol. |
| 1241 | * This is an experimental feature. |
| 1242 | */ |
| 1243 | bool IsSymbol() const; |
| 1244 | |
| 1245 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | * Returns true if this value is a function. |
| 1247 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1248 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | |
| 1250 | /** |
| 1251 | * Returns true if this value is an array. |
| 1252 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1253 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1254 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1255 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1256 | * Returns true if this value is an object. |
| 1257 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1258 | bool IsObject() 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 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | * Returns true if this value is boolean. |
| 1262 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1263 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1264 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1265 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | * Returns true if this value is a number. |
| 1267 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1268 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1270 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | * Returns true if this value is external. |
| 1272 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1273 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1275 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | * Returns true if this value is a 32-bit signed integer. |
| 1277 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1278 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1279 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1280 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1281 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1282 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1283 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1284 | |
| 1285 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1286 | * Returns true if this value is a Date. |
| 1287 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1288 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1289 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1290 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1291 | * Returns true if this value is a Boolean object. |
| 1292 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1293 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1294 | |
| 1295 | /** |
| 1296 | * Returns true if this value is a Number object. |
| 1297 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1298 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1299 | |
| 1300 | /** |
| 1301 | * Returns true if this value is a String object. |
| 1302 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1303 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1304 | |
| 1305 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1306 | * Returns true if this value is a Symbol object. |
| 1307 | * This is an experimental feature. |
| 1308 | */ |
| 1309 | bool IsSymbolObject() const; |
| 1310 | |
| 1311 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1312 | * Returns true if this value is a NativeError. |
| 1313 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1314 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1315 | |
| 1316 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1317 | * Returns true if this value is a RegExp. |
| 1318 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1319 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1320 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1321 | |
| 1322 | /** |
| 1323 | * Returns true if this value is an ArrayBuffer. |
| 1324 | * This is an experimental feature. |
| 1325 | */ |
| 1326 | bool IsArrayBuffer() const; |
| 1327 | |
| 1328 | /** |
| 1329 | * Returns true if this value is one of TypedArrays. |
| 1330 | * This is an experimental feature. |
| 1331 | */ |
| 1332 | bool IsTypedArray() const; |
| 1333 | |
| 1334 | /** |
| 1335 | * Returns true if this value is an Uint8Array. |
| 1336 | * This is an experimental feature. |
| 1337 | */ |
| 1338 | bool IsUint8Array() const; |
| 1339 | |
| 1340 | /** |
| 1341 | * Returns true if this value is an Uint8ClampedArray. |
| 1342 | * This is an experimental feature. |
| 1343 | */ |
| 1344 | bool IsUint8ClampedArray() const; |
| 1345 | |
| 1346 | /** |
| 1347 | * Returns true if this value is an Int8Array. |
| 1348 | * This is an experimental feature. |
| 1349 | */ |
| 1350 | bool IsInt8Array() const; |
| 1351 | |
| 1352 | /** |
| 1353 | * Returns true if this value is an Uint16Array. |
| 1354 | * This is an experimental feature. |
| 1355 | */ |
| 1356 | bool IsUint16Array() const; |
| 1357 | |
| 1358 | /** |
| 1359 | * Returns true if this value is an Int16Array. |
| 1360 | * This is an experimental feature. |
| 1361 | */ |
| 1362 | bool IsInt16Array() const; |
| 1363 | |
| 1364 | /** |
| 1365 | * Returns true if this value is an Uint32Array. |
| 1366 | * This is an experimental feature. |
| 1367 | */ |
| 1368 | bool IsUint32Array() const; |
| 1369 | |
| 1370 | /** |
| 1371 | * Returns true if this value is an Int32Array. |
| 1372 | * This is an experimental feature. |
| 1373 | */ |
| 1374 | bool IsInt32Array() const; |
| 1375 | |
| 1376 | /** |
| 1377 | * Returns true if this value is a Float32Array. |
| 1378 | * This is an experimental feature. |
| 1379 | */ |
| 1380 | bool IsFloat32Array() const; |
| 1381 | |
| 1382 | /** |
| 1383 | * Returns true if this value is a Float64Array. |
| 1384 | * This is an experimental feature. |
| 1385 | */ |
| 1386 | bool IsFloat64Array() const; |
| 1387 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1388 | Local<Boolean> ToBoolean() const; |
| 1389 | Local<Number> ToNumber() const; |
| 1390 | Local<String> ToString() const; |
| 1391 | Local<String> ToDetailString() const; |
| 1392 | Local<Object> ToObject() const; |
| 1393 | Local<Integer> ToInteger() const; |
| 1394 | Local<Uint32> ToUint32() const; |
| 1395 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1396 | |
| 1397 | /** |
| 1398 | * Attempts to convert a string to an array index. |
| 1399 | * Returns an empty handle if the conversion fails. |
| 1400 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1401 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1402 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1403 | bool BooleanValue() const; |
| 1404 | double NumberValue() const; |
| 1405 | int64_t IntegerValue() const; |
| 1406 | uint32_t Uint32Value() const; |
| 1407 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1408 | |
| 1409 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1410 | bool Equals(Handle<Value> that) const; |
| 1411 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1412 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1413 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1414 | V8_INLINE(bool QuickIsUndefined() const); |
| 1415 | V8_INLINE(bool QuickIsNull() const); |
| 1416 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1417 | bool FullIsUndefined() const; |
| 1418 | bool FullIsNull() const; |
| 1419 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1420 | }; |
| 1421 | |
| 1422 | |
| 1423 | /** |
| 1424 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1425 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1426 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1427 | |
| 1428 | |
| 1429 | /** |
| 1430 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1431 | * or false value. |
| 1432 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1433 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1434 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1435 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1436 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | }; |
| 1438 | |
| 1439 | |
| 1440 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1441 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1442 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1443 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1445 | enum Encoding { |
| 1446 | UNKNOWN_ENCODING = 0x1, |
| 1447 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1448 | ASCII_ENCODING = 0x4, |
| 1449 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1450 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1451 | /** |
| 1452 | * Returns the number of characters in this string. |
| 1453 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1454 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1455 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1456 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1457 | * Returns the number of bytes in the UTF-8 encoded |
| 1458 | * representation of this string. |
| 1459 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1460 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1461 | |
| 1462 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1463 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1464 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1465 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1466 | |
| 1467 | /** |
| 1468 | * Returns whether this string contains only one byte data. |
| 1469 | */ |
| 1470 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1471 | |
| 1472 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1473 | * Write the contents of the string to an external buffer. |
| 1474 | * If no arguments are given, expects the buffer to be large |
| 1475 | * enough to hold the entire string and NULL terminator. Copies |
| 1476 | * the contents of the string and the NULL terminator into the |
| 1477 | * buffer. |
| 1478 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1479 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1480 | * before the end of the buffer. |
| 1481 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1482 | * Copies up to length characters into the output buffer. |
| 1483 | * Only null-terminates if there is enough space in the buffer. |
| 1484 | * |
| 1485 | * \param buffer The buffer into which the string will be copied. |
| 1486 | * \param start The starting position within the string at which |
| 1487 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1488 | * \param length The number of characters to copy from the string. For |
| 1489 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1490 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1491 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1492 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1493 | * \return The number of characters copied to the buffer excluding the null |
| 1494 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1495 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1496 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1497 | enum WriteOptions { |
| 1498 | NO_OPTIONS = 0, |
| 1499 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1500 | NO_NULL_TERMINATION = 2, |
| 1501 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1502 | }; |
| 1503 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1504 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1505 | int Write(uint16_t* buffer, |
| 1506 | int start = 0, |
| 1507 | int length = -1, |
| 1508 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1509 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1510 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1511 | int start = 0, |
| 1512 | int length = -1, |
| 1513 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1514 | // One byte characters. |
| 1515 | int WriteOneByte(uint8_t* buffer, |
| 1516 | int start = 0, |
| 1517 | int length = -1, |
| 1518 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1519 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1520 | int WriteUtf8(char* buffer, |
| 1521 | int length = -1, |
| 1522 | int* nchars_ref = NULL, |
| 1523 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1524 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1525 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1526 | * A zero length string. |
| 1527 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1528 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1529 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1530 | |
| 1531 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1532 | * Returns true if the string is external |
| 1533 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1534 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1535 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1536 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1537 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1538 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1539 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1540 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1541 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1542 | public: |
| 1543 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1544 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1545 | protected: |
| 1546 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1547 | |
| 1548 | /** |
| 1549 | * Internally V8 will call this Dispose method when the external string |
| 1550 | * resource is no longer needed. The default implementation will use the |
| 1551 | * delete operator. This method can be overridden in subclasses to |
| 1552 | * control how allocated external string resources are disposed. |
| 1553 | */ |
| 1554 | virtual void Dispose() { delete this; } |
| 1555 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1556 | private: |
| 1557 | // Disallow copying and assigning. |
| 1558 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1559 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1560 | |
| 1561 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1562 | }; |
| 1563 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1564 | /** |
| 1565 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1566 | * buffer that resides outside V8's heap. Implement an |
| 1567 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1568 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1569 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1570 | class V8EXPORT ExternalStringResource |
| 1571 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1572 | public: |
| 1573 | /** |
| 1574 | * Override the destructor to manage the life cycle of the underlying |
| 1575 | * buffer. |
| 1576 | */ |
| 1577 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1578 | |
| 1579 | /** |
| 1580 | * The string data from the underlying buffer. |
| 1581 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1582 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1583 | |
| 1584 | /** |
| 1585 | * The length of the string. That is, the number of two-byte characters. |
| 1586 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1587 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1588 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1589 | protected: |
| 1590 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1591 | }; |
| 1592 | |
| 1593 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1594 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1595 | * string buffer that resides outside V8's heap. Implement an |
| 1596 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1597 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1598 | * 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] | 1599 | * UTF-8, which would require special treatment internally in the |
| 1600 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1601 | * 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] | 1602 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1603 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1604 | class V8EXPORT ExternalAsciiStringResource |
| 1605 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | public: |
| 1607 | /** |
| 1608 | * Override the destructor to manage the life cycle of the underlying |
| 1609 | * buffer. |
| 1610 | */ |
| 1611 | virtual ~ExternalAsciiStringResource() {} |
| 1612 | /** The string data from the underlying buffer.*/ |
| 1613 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1614 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1615 | virtual size_t length() const = 0; |
| 1616 | protected: |
| 1617 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1618 | }; |
| 1619 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1620 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1621 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1622 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1623 | * If the string is an external string, return the ExternalStringResourceBase |
| 1624 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1625 | * string is returned in encoding_out. |
| 1626 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1627 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1628 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1629 | |
| 1630 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1631 | * Get the ExternalStringResource for an external string. Returns |
| 1632 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1634 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1635 | |
| 1636 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1637 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1638 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1639 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1640 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1641 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1642 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1643 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1644 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1646 | * 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] | 1647 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1648 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1649 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1650 | 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] | 1651 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1652 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1653 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1654 | 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] | 1655 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1656 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1657 | /** |
| 1658 | * Creates an internalized string (historically called a "symbol", |
| 1659 | * 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] | 1660 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1661 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1662 | |
| 1663 | enum NewStringType { |
| 1664 | kNormalString, kInternalizedString, kUndetectableString |
| 1665 | }; |
| 1666 | |
| 1667 | /** Allocates a new string from UTF-8 data.*/ |
| 1668 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1669 | const char* data, |
| 1670 | NewStringType type = kNormalString, |
| 1671 | int length = -1); |
| 1672 | |
| 1673 | /** Allocates a new string from Latin-1 data.*/ |
| 1674 | static Local<String> NewFromOneByte( |
| 1675 | Isolate* isolate, |
| 1676 | const uint8_t* data, |
| 1677 | NewStringType type = kNormalString, |
| 1678 | int length = -1); |
| 1679 | |
| 1680 | /** Allocates a new string from UTF-16 data.*/ |
| 1681 | static Local<String> NewFromTwoByte( |
| 1682 | Isolate* isolate, |
| 1683 | const uint16_t* data, |
| 1684 | NewStringType type = kNormalString, |
| 1685 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1687 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1688 | * Creates a new string by concatenating the left and the right strings |
| 1689 | * passed in as parameters. |
| 1690 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1691 | 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] | 1692 | |
| 1693 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1694 | * 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] | 1695 | * 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] | 1696 | * resource will be disposed by calling its Dispose method. The caller of |
| 1697 | * this function should not otherwise delete or modify the resource. Neither |
| 1698 | * should the underlying buffer be deallocated or modified except through the |
| 1699 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1700 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1701 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1702 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1703 | /** |
| 1704 | * Associate an external string resource with this string by transforming it |
| 1705 | * in place so that existing references to this string in the JavaScript heap |
| 1706 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1707 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1708 | * 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] | 1709 | * The string is not modified if the operation fails. See NewExternal for |
| 1710 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1711 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1712 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1713 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1714 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1715 | * 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] | 1716 | * 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] | 1717 | * resource will be disposed by calling its Dispose method. The caller of |
| 1718 | * this function should not otherwise delete or modify the resource. Neither |
| 1719 | * should the underlying buffer be deallocated or modified except through the |
| 1720 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1721 | */ |
| 1722 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1723 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1724 | /** |
| 1725 | * Associate an external string resource with this string by transforming it |
| 1726 | * in place so that existing references to this string in the JavaScript heap |
| 1727 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1728 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1729 | * 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] | 1730 | * The string is not modified if the operation fails. See NewExternal for |
| 1731 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1732 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1733 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1735 | /** |
| 1736 | * Returns true if this string can be made external. |
| 1737 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1738 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1739 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1740 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1741 | /** 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] | 1742 | V8_INLINE( |
| 1743 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1744 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1745 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1746 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1747 | V8_INLINE(static Local<String> NewUndetectable( |
| 1748 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1749 | |
| 1750 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1751 | * 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] | 1752 | * 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] | 1753 | * (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] | 1754 | * then the length() method returns 0 and the * operator returns |
| 1755 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1756 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1757 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1758 | public: |
| 1759 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1760 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1761 | char* operator*() { return str_; } |
| 1762 | const char* operator*() const { return str_; } |
| 1763 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1764 | private: |
| 1765 | char* str_; |
| 1766 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1767 | |
| 1768 | // Disallow copying and assigning. |
| 1769 | Utf8Value(const Utf8Value&); |
| 1770 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1771 | }; |
| 1772 | |
| 1773 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1774 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1775 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1776 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1777 | * method of the object) then the length() method returns 0 and the * operator |
| 1778 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1779 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1780 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1781 | public: |
| 1782 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1783 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1784 | char* operator*() { return str_; } |
| 1785 | const char* operator*() const { return str_; } |
| 1786 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1787 | private: |
| 1788 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1789 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1790 | |
| 1791 | // Disallow copying and assigning. |
| 1792 | AsciiValue(const AsciiValue&); |
| 1793 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1794 | }; |
| 1795 | |
| 1796 | /** |
| 1797 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1798 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1799 | * method of the object) then the length() method returns 0 and the * operator |
| 1800 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1801 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1802 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | public: |
| 1804 | explicit Value(Handle<v8::Value> obj); |
| 1805 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1806 | uint16_t* operator*() { return str_; } |
| 1807 | const uint16_t* operator*() const { return str_; } |
| 1808 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1809 | private: |
| 1810 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1811 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1812 | |
| 1813 | // Disallow copying and assigning. |
| 1814 | Value(const Value&); |
| 1815 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1817 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1818 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1819 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1820 | Encoding encoding) const; |
| 1821 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1822 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1823 | }; |
| 1824 | |
| 1825 | |
| 1826 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1827 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1828 | * |
| 1829 | * This is an experimental feature. Use at your own risk. |
| 1830 | */ |
| 1831 | class V8EXPORT Symbol : public Primitive { |
| 1832 | public: |
| 1833 | // Returns the print name string of the symbol, or undefined if none. |
| 1834 | Local<Value> Name() const; |
| 1835 | |
| 1836 | // Create a symbol without a print name. |
| 1837 | static Local<Symbol> New(Isolate* isolate); |
| 1838 | |
| 1839 | // Create a symbol with a print name. |
| 1840 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1841 | |
| 1842 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1843 | private: |
| 1844 | Symbol(); |
| 1845 | static void CheckCast(v8::Value* obj); |
| 1846 | }; |
| 1847 | |
| 1848 | |
| 1849 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1850 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1851 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1852 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1853 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1854 | double Value() const; |
| 1855 | static Local<Number> New(double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1856 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1857 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1858 | Number(); |
| 1859 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1860 | }; |
| 1861 | |
| 1862 | |
| 1863 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1864 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1865 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1866 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1867 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1868 | static Local<Integer> New(int32_t value); |
| 1869 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1870 | static Local<Integer> New(int32_t value, Isolate*); |
| 1871 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1872 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1873 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1874 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1875 | Integer(); |
| 1876 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1877 | }; |
| 1878 | |
| 1879 | |
| 1880 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1881 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1882 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1883 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1885 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1887 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | }; |
| 1889 | |
| 1890 | |
| 1891 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1892 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1893 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1894 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1895 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1896 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1898 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | }; |
| 1900 | |
| 1901 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1902 | enum PropertyAttribute { |
| 1903 | None = 0, |
| 1904 | ReadOnly = 1 << 0, |
| 1905 | DontEnum = 1 << 1, |
| 1906 | DontDelete = 1 << 2 |
| 1907 | }; |
| 1908 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1909 | enum ExternalArrayType { |
| 1910 | kExternalByteArray = 1, |
| 1911 | kExternalUnsignedByteArray, |
| 1912 | kExternalShortArray, |
| 1913 | kExternalUnsignedShortArray, |
| 1914 | kExternalIntArray, |
| 1915 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1916 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1917 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1918 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1919 | }; |
| 1920 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1922 | * Accessor[Getter|Setter] are used as callback functions when |
| 1923 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1924 | * method SetAccessor. |
| 1925 | */ |
| 1926 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1927 | const AccessorInfo& info); |
| 1928 | |
| 1929 | |
| 1930 | typedef void (*AccessorSetter)(Local<String> property, |
| 1931 | Local<Value> value, |
| 1932 | const AccessorInfo& info); |
| 1933 | |
| 1934 | |
| 1935 | /** |
| 1936 | * Access control specifications. |
| 1937 | * |
| 1938 | * Some accessors should be accessible across contexts. These |
| 1939 | * accessors have an explicit access control parameter which specifies |
| 1940 | * the kind of cross-context access that should be allowed. |
| 1941 | * |
| 1942 | * Additionally, for security, accessors can prohibit overwriting by |
| 1943 | * accessors defined in JavaScript. For objects that have such |
| 1944 | * accessors either locally or in their prototype chain it is not |
| 1945 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1946 | * __defineSetter__ from JavaScript code. |
| 1947 | */ |
| 1948 | enum AccessControl { |
| 1949 | DEFAULT = 0, |
| 1950 | ALL_CAN_READ = 1, |
| 1951 | ALL_CAN_WRITE = 1 << 1, |
| 1952 | PROHIBITS_OVERWRITING = 1 << 2 |
| 1953 | }; |
| 1954 | |
| 1955 | |
| 1956 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1957 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1958 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1959 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1960 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1961 | bool Set(Handle<Value> key, |
| 1962 | Handle<Value> value, |
| 1963 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1964 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1965 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1966 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1967 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1968 | // overriding accessors or read-only properties. |
| 1969 | // |
| 1970 | // Note that if the object has an interceptor the property will be set |
| 1971 | // locally, but since the interceptor takes precedence the local property |
| 1972 | // will only be returned if the interceptor doesn't return a value. |
| 1973 | // |
| 1974 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1975 | bool ForceSet(Handle<Value> key, |
| 1976 | Handle<Value> value, |
| 1977 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1978 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1979 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1980 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1981 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1982 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1983 | /** |
| 1984 | * Gets the property attributes of a property which can be None or |
| 1985 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 1986 | * None when the property doesn't exist. |
| 1987 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1988 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1989 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1990 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1991 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1992 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1993 | |
| 1994 | // Delete a property on this object bypassing interceptors and |
| 1995 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1996 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1997 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1998 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1999 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2000 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2001 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2002 | bool SetAccessor(Handle<String> name, |
| 2003 | AccessorGetter getter, |
| 2004 | AccessorSetter setter = 0, |
| 2005 | Handle<Value> data = Handle<Value>(), |
| 2006 | AccessControl settings = DEFAULT, |
| 2007 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2008 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2009 | // This function is not yet stable and should not be used at this time. |
| 2010 | bool SetAccessor(Handle<String> name, |
| 2011 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2012 | AccessControl settings = DEFAULT, |
| 2013 | PropertyAttribute attribute = None); |
| 2014 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2015 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2016 | * Returns an array containing the names of the enumerable properties |
| 2017 | * of this object, including properties from prototype objects. The |
| 2018 | * array returned by this method contains the same values as would |
| 2019 | * be enumerated by a for-in statement over this object. |
| 2020 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2021 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2022 | |
| 2023 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2024 | * This function has the same functionality as GetPropertyNames but |
| 2025 | * the returned array doesn't contain the names of properties from |
| 2026 | * prototype objects. |
| 2027 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2028 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2029 | |
| 2030 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | * Get the prototype object. This does not skip objects marked to |
| 2032 | * be skipped by __proto__ and it does not consult the security |
| 2033 | * handler. |
| 2034 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2035 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2036 | |
| 2037 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2038 | * Set the prototype object. This does not skip objects marked to |
| 2039 | * be skipped by __proto__ and it does not consult the security |
| 2040 | * handler. |
| 2041 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2042 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2043 | |
| 2044 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2045 | * Finds an instance of the given function template in the prototype |
| 2046 | * chain. |
| 2047 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2048 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2049 | |
| 2050 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2051 | * Call builtin Object.prototype.toString on this object. |
| 2052 | * This is different from Value::ToString() that may call |
| 2053 | * user-defined toString function. This one does not. |
| 2054 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2055 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2057 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2058 | * Returns the function invoked as a constructor for this object. |
| 2059 | * May be the null value. |
| 2060 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2061 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2062 | |
| 2063 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2064 | * Returns the name of the function invoked as a constructor for this object. |
| 2065 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2066 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2067 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2068 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2069 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2070 | |
| 2071 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2072 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2073 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2074 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2075 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2076 | |
| 2077 | /** |
| 2078 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2079 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2080 | * leads to undefined behavior. |
| 2081 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2082 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2083 | |
| 2084 | /** |
| 2085 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2086 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2087 | * leads to undefined behavior. |
| 2088 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2089 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2092 | bool HasOwnProperty(Handle<String> key); |
| 2093 | bool HasRealNamedProperty(Handle<String> key); |
| 2094 | bool HasRealIndexedProperty(uint32_t index); |
| 2095 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2096 | |
| 2097 | /** |
| 2098 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2099 | * This means interceptors in the prototype chain are not called. |
| 2100 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2101 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2102 | |
| 2103 | /** |
| 2104 | * If result.IsEmpty() no real property was located on the object or |
| 2105 | * in the prototype chain. |
| 2106 | * This means interceptors in the prototype chain are not called. |
| 2107 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2108 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2109 | |
| 2110 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2111 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2112 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2113 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2114 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2115 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2116 | /** |
| 2117 | * Turns on access check on the object if the object is an instance of |
| 2118 | * a template that has access check callbacks. If an object has no |
| 2119 | * access check info, the object cannot be accessed by anyone. |
| 2120 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2121 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2122 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2123 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2124 | * Returns the identity hash for this object. The current implementation |
| 2125 | * 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] | 2126 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2127 | * 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] | 2128 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2129 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2130 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2131 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2132 | /** |
| 2133 | * Access hidden properties on JavaScript objects. These properties are |
| 2134 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2135 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2136 | * identity hash) are prefixed with "v8::". |
| 2137 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2138 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2139 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2140 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2141 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2142 | /** |
| 2143 | * Returns true if this is an instance of an api function (one |
| 2144 | * created from a function created from a function template) and has |
| 2145 | * been modified since it was created. Note that this method is |
| 2146 | * conservative and may return true for objects that haven't actually |
| 2147 | * been modified. |
| 2148 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2149 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2150 | |
| 2151 | /** |
| 2152 | * Clone this object with a fast but shallow copy. Values will point |
| 2153 | * to the same values as the original object. |
| 2154 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2155 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2156 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2157 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2158 | * Returns the context in which the object was created. |
| 2159 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2160 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2161 | |
| 2162 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2163 | * Set the backing store of the indexed properties to be managed by the |
| 2164 | * embedding layer. Access to the indexed properties will follow the rules |
| 2165 | * spelled out in CanvasPixelArray. |
| 2166 | * Note: The embedding program still owns the data and needs to ensure that |
| 2167 | * the backing store is preserved while V8 has a reference. |
| 2168 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2169 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2170 | bool HasIndexedPropertiesInPixelData(); |
| 2171 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2172 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2173 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2174 | /** |
| 2175 | * Set the backing store of the indexed properties to be managed by the |
| 2176 | * embedding layer. Access to the indexed properties will follow the rules |
| 2177 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2178 | * Note: The embedding program still owns the data and needs to ensure that |
| 2179 | * the backing store is preserved while V8 has a reference. |
| 2180 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2181 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2182 | ExternalArrayType array_type, |
| 2183 | int number_of_elements); |
| 2184 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2185 | void* GetIndexedPropertiesExternalArrayData(); |
| 2186 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2187 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2188 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2189 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2190 | * Checks whether a callback is set by the |
| 2191 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2192 | * When an Object is callable this method returns true. |
| 2193 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2194 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2195 | |
| 2196 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2197 | * 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] | 2198 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2199 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2200 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2201 | int argc, |
| 2202 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2203 | |
| 2204 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2205 | * 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] | 2206 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2207 | * Note: This method behaves like the Function::NewInstance method. |
| 2208 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2209 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2210 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2211 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2212 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2213 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2214 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2215 | Object(); |
| 2216 | static void CheckCast(Value* obj); |
| 2217 | Local<Value> SlowGetInternalField(int index); |
| 2218 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2219 | }; |
| 2220 | |
| 2221 | |
| 2222 | /** |
| 2223 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2224 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2225 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2226 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2227 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2228 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2229 | /** |
| 2230 | * Clones an element at index |index|. Returns an empty |
| 2231 | * handle if cloning fails (for any reason). |
| 2232 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2233 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2234 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2235 | /** |
| 2236 | * Creates a JavaScript array with the given length. If the length |
| 2237 | * is negative the returned array will have length 0. |
| 2238 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2239 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2240 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2241 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2242 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2243 | Array(); |
| 2244 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2245 | }; |
| 2246 | |
| 2247 | |
| 2248 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2249 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2250 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2251 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2252 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2253 | Local<Object> NewInstance() const; |
| 2254 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2255 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2256 | void SetName(Handle<String> name); |
| 2257 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2258 | |
| 2259 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2260 | * Name inferred from variable or property assignment of this function. |
| 2261 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2262 | * in an OO style, where many functions are anonymous but are assigned |
| 2263 | * to object properties. |
| 2264 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2265 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2266 | |
| 2267 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2268 | * Returns zero based line number of function body and |
| 2269 | * kLineOffsetNotFound if no information available. |
| 2270 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2271 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2272 | /** |
| 2273 | * Returns zero based column number of function body and |
| 2274 | * kLineOffsetNotFound if no information available. |
| 2275 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2276 | int GetScriptColumnNumber() const; |
| 2277 | Handle<Value> GetScriptId() const; |
| 2278 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2279 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2280 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2282 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2283 | Function(); |
| 2284 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2285 | }; |
| 2286 | |
| 2287 | |
| 2288 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2289 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2290 | * This API is experimental and may change significantly. |
| 2291 | */ |
| 2292 | class V8EXPORT ArrayBuffer : public Object { |
| 2293 | public: |
| 2294 | /** |
| 2295 | * Data length in bytes. |
| 2296 | */ |
| 2297 | size_t ByteLength() const; |
| 2298 | /** |
| 2299 | * Raw pointer to the array buffer data |
| 2300 | */ |
| 2301 | void* Data() const; |
| 2302 | |
| 2303 | /** |
| 2304 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2305 | * Allocated memory will be owned by a created ArrayBuffer and |
| 2306 | * will be deallocated when it is garbage-collected. |
| 2307 | */ |
| 2308 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2309 | |
| 2310 | /** |
| 2311 | * Create a new ArrayBuffer over an existing memory block. |
| 2312 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2313 | * is garbage-collected. |
| 2314 | */ |
| 2315 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2316 | |
| 2317 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2318 | |
| 2319 | private: |
| 2320 | ArrayBuffer(); |
| 2321 | static void CheckCast(Value* obj); |
| 2322 | }; |
| 2323 | |
| 2324 | |
| 2325 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2326 | * A base class for an instance of TypedArray series of constructors |
| 2327 | * (ES6 draft 15.13.6). |
| 2328 | * This API is experimental and may change significantly. |
| 2329 | */ |
| 2330 | class V8EXPORT TypedArray : public Object { |
| 2331 | public: |
| 2332 | /** |
| 2333 | * Returns underlying ArrayBuffer. |
| 2334 | */ |
| 2335 | Local<ArrayBuffer> Buffer(); |
| 2336 | /** |
| 2337 | * Byte offset in |Buffer| |
| 2338 | */ |
| 2339 | size_t ByteOffset(); |
| 2340 | /** |
| 2341 | * Numbe of elements in this typed array. |
| 2342 | */ |
| 2343 | size_t Length(); |
| 2344 | /** |
| 2345 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2346 | */ |
| 2347 | size_t ByteLength(); |
| 2348 | /** |
| 2349 | * Base address of typed array. |
| 2350 | */ |
| 2351 | void* BaseAddress(); |
| 2352 | |
| 2353 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2354 | |
| 2355 | private: |
| 2356 | TypedArray(); |
| 2357 | static void CheckCast(Value* obj); |
| 2358 | }; |
| 2359 | |
| 2360 | |
| 2361 | /** |
| 2362 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2363 | * This API is experimental and may change significantly. |
| 2364 | */ |
| 2365 | class V8EXPORT Uint8Array : public TypedArray { |
| 2366 | public: |
| 2367 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2368 | size_t byte_offset, size_t length); |
| 2369 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2370 | |
| 2371 | private: |
| 2372 | Uint8Array(); |
| 2373 | static void CheckCast(Value* obj); |
| 2374 | }; |
| 2375 | |
| 2376 | |
| 2377 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 2378 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2379 | * This API is experimental and may change significantly. |
| 2380 | */ |
| 2381 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2382 | public: |
| 2383 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2384 | size_t byte_offset, size_t length); |
| 2385 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2386 | |
| 2387 | private: |
| 2388 | Uint8ClampedArray(); |
| 2389 | static void CheckCast(Value* obj); |
| 2390 | }; |
| 2391 | |
| 2392 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2393 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2394 | * This API is experimental and may change significantly. |
| 2395 | */ |
| 2396 | class V8EXPORT Int8Array : public TypedArray { |
| 2397 | public: |
| 2398 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2399 | size_t byte_offset, size_t length); |
| 2400 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2401 | |
| 2402 | private: |
| 2403 | Int8Array(); |
| 2404 | static void CheckCast(Value* obj); |
| 2405 | }; |
| 2406 | |
| 2407 | |
| 2408 | /** |
| 2409 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2410 | * This API is experimental and may change significantly. |
| 2411 | */ |
| 2412 | class V8EXPORT Uint16Array : public TypedArray { |
| 2413 | public: |
| 2414 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2415 | size_t byte_offset, size_t length); |
| 2416 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2417 | |
| 2418 | private: |
| 2419 | Uint16Array(); |
| 2420 | static void CheckCast(Value* obj); |
| 2421 | }; |
| 2422 | |
| 2423 | |
| 2424 | /** |
| 2425 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2426 | * This API is experimental and may change significantly. |
| 2427 | */ |
| 2428 | class V8EXPORT Int16Array : public TypedArray { |
| 2429 | public: |
| 2430 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2431 | size_t byte_offset, size_t length); |
| 2432 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2433 | |
| 2434 | private: |
| 2435 | Int16Array(); |
| 2436 | static void CheckCast(Value* obj); |
| 2437 | }; |
| 2438 | |
| 2439 | |
| 2440 | /** |
| 2441 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2442 | * This API is experimental and may change significantly. |
| 2443 | */ |
| 2444 | class V8EXPORT Uint32Array : public TypedArray { |
| 2445 | public: |
| 2446 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2447 | size_t byte_offset, size_t length); |
| 2448 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2449 | |
| 2450 | private: |
| 2451 | Uint32Array(); |
| 2452 | static void CheckCast(Value* obj); |
| 2453 | }; |
| 2454 | |
| 2455 | |
| 2456 | /** |
| 2457 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2458 | * This API is experimental and may change significantly. |
| 2459 | */ |
| 2460 | class V8EXPORT Int32Array : public TypedArray { |
| 2461 | public: |
| 2462 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2463 | size_t byte_offset, size_t length); |
| 2464 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2465 | |
| 2466 | private: |
| 2467 | Int32Array(); |
| 2468 | static void CheckCast(Value* obj); |
| 2469 | }; |
| 2470 | |
| 2471 | |
| 2472 | /** |
| 2473 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2474 | * This API is experimental and may change significantly. |
| 2475 | */ |
| 2476 | class V8EXPORT Float32Array : public TypedArray { |
| 2477 | public: |
| 2478 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2479 | size_t byte_offset, size_t length); |
| 2480 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2481 | |
| 2482 | private: |
| 2483 | Float32Array(); |
| 2484 | static void CheckCast(Value* obj); |
| 2485 | }; |
| 2486 | |
| 2487 | |
| 2488 | /** |
| 2489 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2490 | * This API is experimental and may change significantly. |
| 2491 | */ |
| 2492 | class V8EXPORT Float64Array : public TypedArray { |
| 2493 | public: |
| 2494 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2495 | size_t byte_offset, size_t length); |
| 2496 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2497 | |
| 2498 | private: |
| 2499 | Float64Array(); |
| 2500 | static void CheckCast(Value* obj); |
| 2501 | }; |
| 2502 | |
| 2503 | |
| 2504 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2505 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2506 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2507 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2508 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2509 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2510 | |
| 2511 | /** |
| 2512 | * A specialization of Value::NumberValue that is more efficient |
| 2513 | * because we know the structure of this object. |
| 2514 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2515 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2516 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2517 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2518 | |
| 2519 | /** |
| 2520 | * Notification that the embedder has changed the time zone, |
| 2521 | * daylight savings time, or other date / time configuration |
| 2522 | * parameters. V8 keeps a cache of various values used for |
| 2523 | * date / time computation. This notification will reset |
| 2524 | * those cached values for the current context so that date / |
| 2525 | * time configuration changes would be reflected in the Date |
| 2526 | * object. |
| 2527 | * |
| 2528 | * This API should not be called more than needed as it will |
| 2529 | * negatively impact the performance of date operations. |
| 2530 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2531 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2532 | |
| 2533 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2534 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2535 | }; |
| 2536 | |
| 2537 | |
| 2538 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2539 | * A Number object (ECMA-262, 4.3.21). |
| 2540 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2541 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2542 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2543 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2544 | |
| 2545 | /** |
| 2546 | * Returns the Number held by the object. |
| 2547 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2548 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2549 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2550 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2551 | |
| 2552 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2553 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2554 | }; |
| 2555 | |
| 2556 | |
| 2557 | /** |
| 2558 | * A Boolean object (ECMA-262, 4.3.15). |
| 2559 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2560 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2561 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2562 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2563 | |
| 2564 | /** |
| 2565 | * Returns the Boolean held by the object. |
| 2566 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2567 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2568 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2569 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2570 | |
| 2571 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2572 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2573 | }; |
| 2574 | |
| 2575 | |
| 2576 | /** |
| 2577 | * A String object (ECMA-262, 4.3.18). |
| 2578 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2579 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2580 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2581 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2582 | |
| 2583 | /** |
| 2584 | * Returns the String held by the object. |
| 2585 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2586 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2587 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2588 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2589 | |
| 2590 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2591 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2592 | }; |
| 2593 | |
| 2594 | |
| 2595 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2596 | * A Symbol object (ECMA-262 edition 6). |
| 2597 | * |
| 2598 | * This is an experimental feature. Use at your own risk. |
| 2599 | */ |
| 2600 | class V8EXPORT SymbolObject : public Object { |
| 2601 | public: |
| 2602 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2603 | |
| 2604 | /** |
| 2605 | * Returns the Symbol held by the object. |
| 2606 | */ |
| 2607 | Local<Symbol> SymbolValue() const; |
| 2608 | |
| 2609 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2610 | |
| 2611 | private: |
| 2612 | static void CheckCast(v8::Value* obj); |
| 2613 | }; |
| 2614 | |
| 2615 | |
| 2616 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2617 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2618 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2619 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2620 | public: |
| 2621 | /** |
| 2622 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2623 | * of flags. |
| 2624 | */ |
| 2625 | enum Flags { |
| 2626 | kNone = 0, |
| 2627 | kGlobal = 1, |
| 2628 | kIgnoreCase = 2, |
| 2629 | kMultiline = 4 |
| 2630 | }; |
| 2631 | |
| 2632 | /** |
| 2633 | * Creates a regular expression from the given pattern string and |
| 2634 | * the flags bit field. May throw a JavaScript exception as |
| 2635 | * described in ECMA-262, 15.10.4.1. |
| 2636 | * |
| 2637 | * For example, |
| 2638 | * RegExp::New(v8::String::New("foo"), |
| 2639 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2640 | * is equivalent to evaluating "/foo/gm". |
| 2641 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2642 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2643 | |
| 2644 | /** |
| 2645 | * Returns the value of the source property: a string representing |
| 2646 | * the regular expression. |
| 2647 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2648 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2649 | |
| 2650 | /** |
| 2651 | * Returns the flags bit field. |
| 2652 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2653 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2654 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2655 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2656 | |
| 2657 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2658 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2659 | }; |
| 2660 | |
| 2661 | |
| 2662 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2663 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2664 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2665 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2666 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2667 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2668 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2669 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2670 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2671 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2672 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2673 | }; |
| 2674 | |
| 2675 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2676 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2677 | |
| 2678 | |
| 2679 | /** |
| 2680 | * The superclass of object and function templates. |
| 2681 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2682 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2683 | public: |
| 2684 | /** Adds a property to each instance created by this template.*/ |
| 2685 | void Set(Handle<String> name, Handle<Data> value, |
| 2686 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2687 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2688 | private: |
| 2689 | Template(); |
| 2690 | |
| 2691 | friend class ObjectTemplate; |
| 2692 | friend class FunctionTemplate; |
| 2693 | }; |
| 2694 | |
| 2695 | |
| 2696 | /** |
| 2697 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2698 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2699 | * including the receiver, the number and values of arguments, and |
| 2700 | * the holder of the function. |
| 2701 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2702 | class V8EXPORT Arguments { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2704 | V8_INLINE(int Length() const); |
| 2705 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2706 | V8_INLINE(Local<Function> Callee() const); |
| 2707 | V8_INLINE(Local<Object> This() const); |
| 2708 | V8_INLINE(Local<Object> Holder() const); |
| 2709 | V8_INLINE(bool IsConstructCall() const); |
| 2710 | V8_INLINE(Local<Value> Data() const); |
| 2711 | V8_INLINE(Isolate* GetIsolate() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2712 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2713 | private: |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2714 | static const int kIsolateIndex = 0; |
| 2715 | static const int kDataIndex = -1; |
| 2716 | static const int kCalleeIndex = -2; |
| 2717 | static const int kHolderIndex = -3; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2718 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2719 | friend class ImplementationUtilities; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2720 | V8_INLINE(Arguments(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2721 | internal::Object** values, |
| 2722 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2723 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2724 | internal::Object** implicit_args_; |
| 2725 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2726 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2727 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | }; |
| 2729 | |
| 2730 | |
| 2731 | /** |
| 2732 | * The information passed to an accessor callback about the context |
| 2733 | * of the property access. |
| 2734 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2735 | class V8EXPORT AccessorInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2736 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2737 | V8_INLINE(AccessorInfo(internal::Object** args)) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2738 | : args_(args) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2739 | V8_INLINE(Isolate* GetIsolate() const); |
| 2740 | V8_INLINE(Local<Value> Data() const); |
| 2741 | V8_INLINE(Local<Object> This() const); |
| 2742 | V8_INLINE(Local<Object> Holder() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2743 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2744 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2745 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2746 | }; |
| 2747 | |
| 2748 | |
| 2749 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
| 2750 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2751 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2752 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2753 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2754 | */ |
| 2755 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2756 | const AccessorInfo& info); |
| 2757 | |
| 2758 | |
| 2759 | /** |
| 2760 | * Returns the value if the setter intercepts the request. |
| 2761 | * Otherwise, returns an empty handle. |
| 2762 | */ |
| 2763 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2764 | Local<Value> value, |
| 2765 | const AccessorInfo& info); |
| 2766 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2767 | /** |
| 2768 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2769 | * The result is an integer encoding property attributes (like v8::None, |
| 2770 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2771 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2772 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2773 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2774 | |
| 2775 | |
| 2776 | /** |
| 2777 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2778 | * The return value is true if the property could be deleted and false |
| 2779 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2780 | */ |
| 2781 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2782 | const AccessorInfo& info); |
| 2783 | |
| 2784 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2785 | * Returns an array containing the names of the properties the named |
| 2786 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2787 | */ |
| 2788 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
| 2789 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2790 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2791 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2792 | * Returns the value of the property if the getter intercepts the |
| 2793 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2794 | */ |
| 2795 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 2796 | const AccessorInfo& info); |
| 2797 | |
| 2798 | |
| 2799 | /** |
| 2800 | * Returns the value if the setter intercepts the request. |
| 2801 | * Otherwise, returns an empty handle. |
| 2802 | */ |
| 2803 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 2804 | Local<Value> value, |
| 2805 | const AccessorInfo& info); |
| 2806 | |
| 2807 | |
| 2808 | /** |
| 2809 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2810 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2811 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2812 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 2813 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2814 | |
| 2815 | /** |
| 2816 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2817 | * The return value is true if the property could be deleted and false |
| 2818 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2819 | */ |
| 2820 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 2821 | const AccessorInfo& info); |
| 2822 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2823 | /** |
| 2824 | * Returns an array containing the indices of the properties the |
| 2825 | * indexed property getter intercepts. |
| 2826 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2827 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
| 2828 | |
| 2829 | |
| 2830 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2831 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2832 | */ |
| 2833 | enum AccessType { |
| 2834 | ACCESS_GET, |
| 2835 | ACCESS_SET, |
| 2836 | ACCESS_HAS, |
| 2837 | ACCESS_DELETE, |
| 2838 | ACCESS_KEYS |
| 2839 | }; |
| 2840 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2841 | |
| 2842 | /** |
| 2843 | * 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] | 2844 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2845 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2846 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | Local<Value> key, |
| 2848 | AccessType type, |
| 2849 | Local<Value> data); |
| 2850 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2851 | |
| 2852 | /** |
| 2853 | * 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] | 2854 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2855 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2856 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2857 | uint32_t index, |
| 2858 | AccessType type, |
| 2859 | Local<Value> data); |
| 2860 | |
| 2861 | |
| 2862 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2863 | * A FunctionTemplate is used to create functions at runtime. There |
| 2864 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2865 | * context. The lifetime of the created function is equal to the |
| 2866 | * lifetime of the context. So in case the embedder needs to create |
| 2867 | * temporary functions that can be collected using Scripts is |
| 2868 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2869 | * |
| 2870 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2871 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2872 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2873 | * A FunctionTemplate has a corresponding instance template which is |
| 2874 | * used to create object instances when the function is used as a |
| 2875 | * constructor. Properties added to the instance template are added to |
| 2876 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2877 | * |
| 2878 | * A FunctionTemplate can have a prototype template. The prototype template |
| 2879 | * is used to create the prototype object of the function. |
| 2880 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2881 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2882 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2883 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 2885 | * t->Set("func_property", v8::Number::New(1)); |
| 2886 | * |
| 2887 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 2888 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 2889 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 2890 | * |
| 2891 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 2892 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 2893 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 2894 | * instance_t->Set("instance_property", Number::New(3)); |
| 2895 | * |
| 2896 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 2897 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2898 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2899 | * |
| 2900 | * 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] | 2901 | * and "instance" for the instance object created above. The function |
| 2902 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2903 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2904 | * \code |
| 2905 | * func_property in function == true; |
| 2906 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2907 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2908 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 2909 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2911 | * instance instanceof function == true; |
| 2912 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 2913 | * instance.instance_property == 3; |
| 2914 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2915 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2916 | * A FunctionTemplate can inherit from another one by calling the |
| 2917 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 2918 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2919 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2920 | * \code |
| 2921 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 2922 | * ^ ^ |
| 2923 | * | Inherit(Parent) | .__proto__ |
| 2924 | * | | |
| 2925 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 2926 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2927 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2928 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 2929 | * object of the Child() function has __proto__ pointing to the |
| 2930 | * Parent() function's prototype object. An instance of the Child |
| 2931 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2932 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2933 | * Let Parent be the FunctionTemplate initialized in the previous |
| 2934 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2935 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2936 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2937 | * Local<FunctionTemplate> parent = t; |
| 2938 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 2939 | * child->Inherit(parent); |
| 2940 | * |
| 2941 | * Local<Function> child_function = child->GetFunction(); |
| 2942 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2943 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2944 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2945 | * The Child function and Child instance will have the following |
| 2946 | * properties: |
| 2947 | * |
| 2948 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2949 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2950 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2951 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2952 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2953 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2954 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | public: |
| 2956 | /** Creates a function template.*/ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2957 | static Local<FunctionTemplate> New( |
| 2958 | InvocationCallback callback = 0, |
| 2959 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2960 | Handle<Signature> signature = Handle<Signature>(), |
| 2961 | int length = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | /** Returns the unique function instance in the current execution context.*/ |
| 2963 | Local<Function> GetFunction(); |
| 2964 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2965 | /** |
| 2966 | * Set the call-handler callback for a FunctionTemplate. This |
| 2967 | * callback is called whenever the function created from this |
| 2968 | * FunctionTemplate is called. |
| 2969 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | void SetCallHandler(InvocationCallback callback, |
| 2971 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2972 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2973 | /** Set the predefined length property for the FunctionTemplate. */ |
| 2974 | void SetLength(int length); |
| 2975 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2976 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2977 | Local<ObjectTemplate> InstanceTemplate(); |
| 2978 | |
| 2979 | /** Causes the function template to inherit from a parent function template.*/ |
| 2980 | void Inherit(Handle<FunctionTemplate> parent); |
| 2981 | |
| 2982 | /** |
| 2983 | * A PrototypeTemplate is the template used to create the prototype object |
| 2984 | * of the function created by this template. |
| 2985 | */ |
| 2986 | Local<ObjectTemplate> PrototypeTemplate(); |
| 2987 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2988 | /** |
| 2989 | * Set the class name of the FunctionTemplate. This is used for |
| 2990 | * printing objects created with the function created from the |
| 2991 | * FunctionTemplate as its constructor. |
| 2992 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2993 | void SetClassName(Handle<String> name); |
| 2994 | |
| 2995 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2996 | * Determines whether the __proto__ accessor ignores instances of |
| 2997 | * the function template. If instances of the function template are |
| 2998 | * ignored, __proto__ skips all instances and instead returns the |
| 2999 | * next object in the prototype chain. |
| 3000 | * |
| 3001 | * Call with a value of true to make the __proto__ accessor ignore |
| 3002 | * instances of the function template. Call with a value of false |
| 3003 | * to make the __proto__ accessor not ignore instances of the |
| 3004 | * function template. By default, instances of a function template |
| 3005 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3006 | */ |
| 3007 | void SetHiddenPrototype(bool value); |
| 3008 | |
| 3009 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3010 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3011 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3012 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3013 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3014 | |
| 3015 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3016 | * Returns true if the given object is an instance of this function |
| 3017 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3018 | */ |
| 3019 | bool HasInstance(Handle<Value> object); |
| 3020 | |
| 3021 | private: |
| 3022 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3023 | void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, |
| 3024 | NamedPropertySetter setter, |
| 3025 | NamedPropertyQuery query, |
| 3026 | NamedPropertyDeleter remover, |
| 3027 | NamedPropertyEnumerator enumerator, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3028 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3029 | void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, |
| 3030 | IndexedPropertySetter setter, |
| 3031 | IndexedPropertyQuery query, |
| 3032 | IndexedPropertyDeleter remover, |
| 3033 | IndexedPropertyEnumerator enumerator, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3034 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3035 | void SetInstanceCallAsFunctionHandler(InvocationCallback callback, |
| 3036 | Handle<Value> data); |
| 3037 | |
| 3038 | friend class Context; |
| 3039 | friend class ObjectTemplate; |
| 3040 | }; |
| 3041 | |
| 3042 | |
| 3043 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3044 | * An ObjectTemplate is used to create objects at runtime. |
| 3045 | * |
| 3046 | * Properties added to an ObjectTemplate are added to each object |
| 3047 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3048 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3049 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3050 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3051 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3052 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3053 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3054 | /** Creates a new instance of this template.*/ |
| 3055 | Local<Object> NewInstance(); |
| 3056 | |
| 3057 | /** |
| 3058 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3059 | * |
| 3060 | * Whenever the property with the given name is accessed on objects |
| 3061 | * created from this ObjectTemplate the getter and setter callbacks |
| 3062 | * are called instead of getting and setting the property directly |
| 3063 | * on the JavaScript object. |
| 3064 | * |
| 3065 | * \param name The name of the property for which an accessor is added. |
| 3066 | * \param getter The callback to invoke when getting the property. |
| 3067 | * \param setter The callback to invoke when setting the property. |
| 3068 | * \param data A piece of data that will be passed to the getter and setter |
| 3069 | * callbacks whenever they are invoked. |
| 3070 | * \param settings Access control settings for the accessor. This is a bit |
| 3071 | * field consisting of one of more of |
| 3072 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3073 | * The default is to not allow cross-context access. |
| 3074 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3075 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3076 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3077 | * cross-context access. |
| 3078 | * \param attribute The attributes of the property for which an accessor |
| 3079 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3080 | * \param signature The signature describes valid receivers for the accessor |
| 3081 | * and is used to perform implicit instance checks against them. If the |
| 3082 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3083 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3084 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3085 | */ |
| 3086 | void SetAccessor(Handle<String> name, |
| 3087 | AccessorGetter getter, |
| 3088 | AccessorSetter setter = 0, |
| 3089 | Handle<Value> data = Handle<Value>(), |
| 3090 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3091 | PropertyAttribute attribute = None, |
| 3092 | Handle<AccessorSignature> signature = |
| 3093 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3094 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3095 | // This function is not yet stable and should not be used at this time. |
| 3096 | bool SetAccessor(Handle<String> name, |
| 3097 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3098 | AccessControl settings = DEFAULT, |
| 3099 | PropertyAttribute attribute = None, |
| 3100 | Handle<AccessorSignature> signature = |
| 3101 | Handle<AccessorSignature>()); |
| 3102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3103 | /** |
| 3104 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3105 | * |
| 3106 | * Whenever a named property is accessed on objects created from |
| 3107 | * this object template, the provided callback is invoked instead of |
| 3108 | * accessing the property directly on the JavaScript object. |
| 3109 | * |
| 3110 | * \param getter The callback to invoke when getting a property. |
| 3111 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3112 | * \param query The callback to invoke to check if a property is present, |
| 3113 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3114 | * \param deleter The callback to invoke when deleting a property. |
| 3115 | * \param enumerator The callback to invoke to enumerate all the named |
| 3116 | * properties of an object. |
| 3117 | * \param data A piece of data that will be passed to the callbacks |
| 3118 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3119 | */ |
| 3120 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3121 | NamedPropertySetter setter = 0, |
| 3122 | NamedPropertyQuery query = 0, |
| 3123 | NamedPropertyDeleter deleter = 0, |
| 3124 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3125 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3126 | |
| 3127 | /** |
| 3128 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3129 | * |
| 3130 | * Whenever an indexed property is accessed on objects created from |
| 3131 | * this object template, the provided callback is invoked instead of |
| 3132 | * accessing the property directly on the JavaScript object. |
| 3133 | * |
| 3134 | * \param getter The callback to invoke when getting a property. |
| 3135 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3136 | * \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] | 3137 | * \param deleter The callback to invoke when deleting a property. |
| 3138 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3139 | * properties of an object. |
| 3140 | * \param data A piece of data that will be passed to the callbacks |
| 3141 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3142 | */ |
| 3143 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3144 | IndexedPropertySetter setter = 0, |
| 3145 | IndexedPropertyQuery query = 0, |
| 3146 | IndexedPropertyDeleter deleter = 0, |
| 3147 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3148 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3149 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3150 | /** |
| 3151 | * Sets the callback to be used when calling instances created from |
| 3152 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3153 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3154 | * function. |
| 3155 | */ |
| 3156 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3157 | Handle<Value> data = Handle<Value>()); |
| 3158 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3159 | /** |
| 3160 | * Mark object instances of the template as undetectable. |
| 3161 | * |
| 3162 | * In many ways, undetectable objects behave as though they are not |
| 3163 | * there. They behave like 'undefined' in conditionals and when |
| 3164 | * printed. However, properties can be accessed and called as on |
| 3165 | * normal objects. |
| 3166 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3167 | void MarkAsUndetectable(); |
| 3168 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3169 | /** |
| 3170 | * Sets access check callbacks on the object template. |
| 3171 | * |
| 3172 | * When accessing properties on instances of this object template, |
| 3173 | * the access check callback will be called to determine whether or |
| 3174 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3175 | * The last parameter specifies whether access checks are turned |
| 3176 | * on by default on instances. If access checks are off by default, |
| 3177 | * they can be turned on on individual instances by calling |
| 3178 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3179 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3180 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3181 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3182 | Handle<Value> data = Handle<Value>(), |
| 3183 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3184 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3185 | /** |
| 3186 | * Gets the number of internal fields for objects generated from |
| 3187 | * this template. |
| 3188 | */ |
| 3189 | int InternalFieldCount(); |
| 3190 | |
| 3191 | /** |
| 3192 | * Sets the number of internal fields for objects generated from |
| 3193 | * this template. |
| 3194 | */ |
| 3195 | void SetInternalFieldCount(int value); |
| 3196 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3197 | private: |
| 3198 | ObjectTemplate(); |
| 3199 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3200 | friend class FunctionTemplate; |
| 3201 | }; |
| 3202 | |
| 3203 | |
| 3204 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3205 | * A Signature specifies which receivers and arguments are valid |
| 3206 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3208 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3209 | public: |
| 3210 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3211 | Handle<FunctionTemplate>(), |
| 3212 | int argc = 0, |
| 3213 | Handle<FunctionTemplate> argv[] = 0); |
| 3214 | private: |
| 3215 | Signature(); |
| 3216 | }; |
| 3217 | |
| 3218 | |
| 3219 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3220 | * An AccessorSignature specifies which receivers are valid parameters |
| 3221 | * to an accessor callback. |
| 3222 | */ |
| 3223 | class V8EXPORT AccessorSignature : public Data { |
| 3224 | public: |
| 3225 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3226 | Handle<FunctionTemplate>()); |
| 3227 | private: |
| 3228 | AccessorSignature(); |
| 3229 | }; |
| 3230 | |
| 3231 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3232 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3233 | private: |
| 3234 | DeclaredAccessorDescriptor(); |
| 3235 | }; |
| 3236 | |
| 3237 | |
| 3238 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3239 | public: |
| 3240 | // This function is not yet stable and should not be used at this time. |
| 3241 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3242 | Isolate* isolate, |
| 3243 | int internal_field); |
| 3244 | private: |
| 3245 | ObjectOperationDescriptor(); |
| 3246 | }; |
| 3247 | |
| 3248 | |
| 3249 | enum DeclaredAccessorDescriptorDataType { |
| 3250 | kDescriptorBoolType, |
| 3251 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3252 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3253 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3254 | kDescriptorFloatType, kDescriptorDoubleType |
| 3255 | }; |
| 3256 | |
| 3257 | |
| 3258 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3259 | public: |
| 3260 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3261 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3262 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3263 | int16_t byte_offset); |
| 3264 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3265 | void* compare_value); |
| 3266 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3267 | Isolate* isolate, |
| 3268 | DeclaredAccessorDescriptorDataType data_type, |
| 3269 | uint8_t bool_offset = 0); |
| 3270 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3271 | uint8_t bitmask, |
| 3272 | uint8_t compare_value); |
| 3273 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3274 | Isolate* isolate, |
| 3275 | uint16_t bitmask, |
| 3276 | uint16_t compare_value); |
| 3277 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3278 | Isolate* isolate, |
| 3279 | uint32_t bitmask, |
| 3280 | uint32_t compare_value); |
| 3281 | |
| 3282 | private: |
| 3283 | RawOperationDescriptor(); |
| 3284 | }; |
| 3285 | |
| 3286 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3287 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3288 | * A utility for determining the type of objects based on the template |
| 3289 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3290 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3291 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3292 | public: |
| 3293 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3294 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3295 | int match(Handle<Value> value); |
| 3296 | private: |
| 3297 | TypeSwitch(); |
| 3298 | }; |
| 3299 | |
| 3300 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3301 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3302 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3303 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3304 | : public String::ExternalAsciiStringResource { |
| 3305 | public: |
| 3306 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3307 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3308 | : data_(data), length_(length) {} |
| 3309 | const char* data() const { return data_; } |
| 3310 | size_t length() const { return length_; } |
| 3311 | |
| 3312 | private: |
| 3313 | const char* data_; |
| 3314 | size_t length_; |
| 3315 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3316 | |
| 3317 | /** |
| 3318 | * Ignore |
| 3319 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3320 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3321 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3322 | // Note that the strings passed into this constructor must live as long |
| 3323 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3324 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3325 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3326 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3327 | const char** deps = 0, |
| 3328 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3329 | virtual ~Extension() { } |
| 3330 | virtual v8::Handle<v8::FunctionTemplate> |
| 3331 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3332 | return v8::Handle<v8::FunctionTemplate>(); |
| 3333 | } |
| 3334 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3335 | const char* name() const { return name_; } |
| 3336 | size_t source_length() const { return source_length_; } |
| 3337 | const String::ExternalAsciiStringResource* source() const { |
| 3338 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3339 | int dependency_count() { return dep_count_; } |
| 3340 | const char** dependencies() { return deps_; } |
| 3341 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3342 | bool auto_enable() { return auto_enable_; } |
| 3343 | |
| 3344 | private: |
| 3345 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3346 | size_t source_length_; // expected to initialize before source_ |
| 3347 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3348 | int dep_count_; |
| 3349 | const char** deps_; |
| 3350 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3351 | |
| 3352 | // Disallow copying and assigning. |
| 3353 | Extension(const Extension&); |
| 3354 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3355 | }; |
| 3356 | |
| 3357 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3358 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3359 | |
| 3360 | |
| 3361 | /** |
| 3362 | * Ignore |
| 3363 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3364 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3365 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3366 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3367 | RegisterExtension(extension); |
| 3368 | } |
| 3369 | }; |
| 3370 | |
| 3371 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3372 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3373 | |
| 3374 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3375 | Handle<Primitive> V8EXPORT Undefined(); |
| 3376 | Handle<Primitive> V8EXPORT Null(); |
| 3377 | Handle<Boolean> V8EXPORT True(); |
| 3378 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3379 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3380 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3381 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3382 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3383 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3384 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3385 | |
| 3386 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3387 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3388 | * You must set the heap size before initializing the VM - the size cannot be |
| 3389 | * adjusted after the VM is initialized. |
| 3390 | * |
| 3391 | * If you are using threads then you should hold the V8::Locker lock while |
| 3392 | * setting the stack limit and you must set a non-default stack limit separately |
| 3393 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3395 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3396 | public: |
| 3397 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3398 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3399 | 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] | 3400 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3401 | 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] | 3402 | int max_executable_size() { return max_executable_size_; } |
| 3403 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3404 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3405 | // 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] | 3406 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3407 | private: |
| 3408 | int max_young_space_size_; |
| 3409 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3410 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3411 | uint32_t* stack_limit_; |
| 3412 | }; |
| 3413 | |
| 3414 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3415 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3416 | |
| 3417 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3418 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3419 | |
| 3420 | |
| 3421 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3422 | |
| 3423 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3424 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3425 | |
| 3426 | |
| 3427 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3428 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3429 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3430 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3431 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3432 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3433 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3434 | |
| 3435 | /** |
| 3436 | * Create new error objects by calling the corresponding error object |
| 3437 | * constructor with the message. |
| 3438 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3439 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3440 | public: |
| 3441 | static Local<Value> RangeError(Handle<String> message); |
| 3442 | static Local<Value> ReferenceError(Handle<String> message); |
| 3443 | static Local<Value> SyntaxError(Handle<String> message); |
| 3444 | static Local<Value> TypeError(Handle<String> message); |
| 3445 | static Local<Value> Error(Handle<String> message); |
| 3446 | }; |
| 3447 | |
| 3448 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3449 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3450 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3451 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3452 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3453 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3454 | int min, |
| 3455 | int max, |
| 3456 | size_t buckets); |
| 3457 | |
| 3458 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3459 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3460 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3461 | enum ObjectSpace { |
| 3462 | kObjectSpaceNewSpace = 1 << 0, |
| 3463 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3464 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3465 | kObjectSpaceCodeSpace = 1 << 3, |
| 3466 | kObjectSpaceMapSpace = 1 << 4, |
| 3467 | kObjectSpaceLoSpace = 1 << 5, |
| 3468 | |
| 3469 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3470 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3471 | kObjectSpaceLoSpace |
| 3472 | }; |
| 3473 | |
| 3474 | enum AllocationAction { |
| 3475 | kAllocationActionAllocate = 1 << 0, |
| 3476 | kAllocationActionFree = 1 << 1, |
| 3477 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3478 | }; |
| 3479 | |
| 3480 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3481 | AllocationAction action, |
| 3482 | int size); |
| 3483 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3484 | // --- Leave Script Callback --- |
| 3485 | typedef void (*CallCompletedCallback)(); |
| 3486 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3487 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3488 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3489 | AccessType type, |
| 3490 | Local<Value> data); |
| 3491 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3492 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3493 | |
| 3494 | /** |
| 3495 | * Callback to check if code generation from strings is allowed. See |
| 3496 | * Context::AllowCodeGenerationFromStrings. |
| 3497 | */ |
| 3498 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3499 | |
| 3500 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3501 | |
| 3502 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3503 | * Applications can register callback functions which will be called |
| 3504 | * before and after a garbage collection. Allocations are not |
| 3505 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3506 | * objects (set or delete properties for example) since it is possible |
| 3507 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3508 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3509 | enum GCType { |
| 3510 | kGCTypeScavenge = 1 << 0, |
| 3511 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3512 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3513 | }; |
| 3514 | |
| 3515 | enum GCCallbackFlags { |
| 3516 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3517 | kGCCallbackFlagCompacted = 1 << 0, |
| 3518 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3519 | }; |
| 3520 | |
| 3521 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3522 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3523 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3524 | typedef void (*GCCallback)(); |
| 3525 | |
| 3526 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3527 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3528 | * Collection of V8 heap information. |
| 3529 | * |
| 3530 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3531 | * get heap statistics from V8. |
| 3532 | */ |
| 3533 | class V8EXPORT HeapStatistics { |
| 3534 | public: |
| 3535 | HeapStatistics(); |
| 3536 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3537 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3538 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3539 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3540 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3541 | |
| 3542 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3543 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3544 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3545 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3546 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3547 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3548 | |
| 3549 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3550 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3551 | }; |
| 3552 | |
| 3553 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3554 | class RetainedObjectInfo; |
| 3555 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3556 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3557 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3558 | * isolates have completely separate states. Objects from one isolate |
| 3559 | * must not be used in other isolates. When V8 is initialized a |
| 3560 | * default isolate is implicitly created and entered. The embedder |
| 3561 | * can create additional isolates and use them in parallel in multiple |
| 3562 | * 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] | 3563 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3564 | */ |
| 3565 | class V8EXPORT Isolate { |
| 3566 | public: |
| 3567 | /** |
| 3568 | * Stack-allocated class which sets the isolate for all operations |
| 3569 | * executed within a local scope. |
| 3570 | */ |
| 3571 | class V8EXPORT Scope { |
| 3572 | public: |
| 3573 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3574 | isolate->Enter(); |
| 3575 | } |
| 3576 | |
| 3577 | ~Scope() { isolate_->Exit(); } |
| 3578 | |
| 3579 | private: |
| 3580 | Isolate* const isolate_; |
| 3581 | |
| 3582 | // Prevent copying of Scope objects. |
| 3583 | Scope(const Scope&); |
| 3584 | Scope& operator=(const Scope&); |
| 3585 | }; |
| 3586 | |
| 3587 | /** |
| 3588 | * Creates a new isolate. Does not change the currently entered |
| 3589 | * isolate. |
| 3590 | * |
| 3591 | * When an isolate is no longer used its resources should be freed |
| 3592 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3593 | */ |
| 3594 | static Isolate* New(); |
| 3595 | |
| 3596 | /** |
| 3597 | * Returns the entered isolate for the current thread or NULL in |
| 3598 | * case there is no current isolate. |
| 3599 | */ |
| 3600 | static Isolate* GetCurrent(); |
| 3601 | |
| 3602 | /** |
| 3603 | * Methods below this point require holding a lock (using Locker) in |
| 3604 | * a multi-threaded environment. |
| 3605 | */ |
| 3606 | |
| 3607 | /** |
| 3608 | * Sets this isolate as the entered one for the current thread. |
| 3609 | * Saves the previously entered one (if any), so that it can be |
| 3610 | * restored when exiting. Re-entering an isolate is allowed. |
| 3611 | */ |
| 3612 | void Enter(); |
| 3613 | |
| 3614 | /** |
| 3615 | * Exits this isolate by restoring the previously entered one in the |
| 3616 | * current thread. The isolate may still stay the same, if it was |
| 3617 | * entered more than once. |
| 3618 | * |
| 3619 | * Requires: this == Isolate::GetCurrent(). |
| 3620 | */ |
| 3621 | void Exit(); |
| 3622 | |
| 3623 | /** |
| 3624 | * Disposes the isolate. The isolate must not be entered by any |
| 3625 | * thread to be disposable. |
| 3626 | */ |
| 3627 | void Dispose(); |
| 3628 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3629 | /** |
| 3630 | * Associate embedder-specific data with the isolate |
| 3631 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3632 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3633 | |
| 3634 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3635 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3636 | * Returns NULL if SetData has never been called. |
| 3637 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3638 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3639 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3640 | /** |
| 3641 | * Get statistics about the heap memory usage. |
| 3642 | */ |
| 3643 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3644 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3645 | /** |
| 3646 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3647 | * indication of the amount of externally allocated memory that is kept alive |
| 3648 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3649 | * garbage collections. Registering externally allocated memory will trigger |
| 3650 | * global garbage collections more often than it would otherwise in an attempt |
| 3651 | * to garbage collect the JavaScript objects that keep the externally |
| 3652 | * allocated memory alive. |
| 3653 | * |
| 3654 | * \param change_in_bytes the change in externally allocated memory that is |
| 3655 | * kept alive by JavaScript objects. |
| 3656 | * \returns the adjusted value. |
| 3657 | */ |
| 3658 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3659 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3660 | /** |
| 3661 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3662 | * is initialized. |
| 3663 | */ |
| 3664 | HeapProfiler* GetHeapProfiler(); |
| 3665 | |
| 3666 | /** |
| 3667 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3668 | * is initialized. |
| 3669 | */ |
| 3670 | CpuProfiler* GetCpuProfiler(); |
| 3671 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3672 | /** Returns the context that is on the top of the stack. */ |
| 3673 | Local<Context> GetCurrentContext(); |
| 3674 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3675 | /** |
| 3676 | * Allows the host application to group objects together. If one |
| 3677 | * object in the group is alive, all objects in the group are alive. |
| 3678 | * After each garbage collection, object groups are removed. It is |
| 3679 | * intended to be used in the before-garbage-collection callback |
| 3680 | * function, for instance to simulate DOM tree connections among JS |
| 3681 | * wrapper objects. Object groups for all dependent handles need to |
| 3682 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3683 | * garbage collection types it is sufficient to provide object groups |
| 3684 | * for partially dependent handles only. |
| 3685 | */ |
| 3686 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3687 | UniqueId id); |
| 3688 | |
| 3689 | /** |
| 3690 | * Allows the host application to declare implicit references from an object |
| 3691 | * group to an object. If the objects of the object group are alive, the child |
| 3692 | * object is alive too. After each garbage collection, all implicit references |
| 3693 | * are removed. It is intended to be used in the before-garbage-collection |
| 3694 | * callback function. |
| 3695 | */ |
| 3696 | void SetReferenceFromGroup(UniqueId id, |
| 3697 | const Persistent<Value>& child); |
| 3698 | |
| 3699 | /** |
| 3700 | * Allows the host application to declare implicit references from an object |
| 3701 | * to another object. If the parent object is alive, the child object is alive |
| 3702 | * too. After each garbage collection, all implicit references are removed. It |
| 3703 | * is intended to be used in the before-garbage-collection callback function. |
| 3704 | */ |
| 3705 | void SetReference(const Persistent<Object>& parent, |
| 3706 | const Persistent<Value>& child); |
| 3707 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3708 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3709 | Isolate(); |
| 3710 | Isolate(const Isolate&); |
| 3711 | ~Isolate(); |
| 3712 | Isolate& operator=(const Isolate&); |
| 3713 | void* operator new(size_t size); |
| 3714 | void operator delete(void*, size_t); |
| 3715 | }; |
| 3716 | |
| 3717 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3718 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3719 | public: |
| 3720 | enum CompressionAlgorithm { |
| 3721 | kUncompressed, |
| 3722 | kBZip2 |
| 3723 | }; |
| 3724 | |
| 3725 | const char* data; |
| 3726 | int compressed_size; |
| 3727 | int raw_size; |
| 3728 | }; |
| 3729 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3730 | |
| 3731 | /** |
| 3732 | * A helper class for driving V8 startup data decompression. It is based on |
| 3733 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3734 | * for an embedder to use this class, instead, API functions can be used |
| 3735 | * directly. |
| 3736 | * |
| 3737 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3738 | */ |
| 3739 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 3740 | public: |
| 3741 | StartupDataDecompressor(); |
| 3742 | virtual ~StartupDataDecompressor(); |
| 3743 | int Decompress(); |
| 3744 | |
| 3745 | protected: |
| 3746 | virtual int DecompressData(char* raw_data, |
| 3747 | int* raw_data_size, |
| 3748 | const char* compressed_data, |
| 3749 | int compressed_data_size) = 0; |
| 3750 | |
| 3751 | private: |
| 3752 | char** raw_data; |
| 3753 | }; |
| 3754 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3755 | |
| 3756 | /** |
| 3757 | * EntropySource is used as a callback function when v8 needs a source |
| 3758 | * of entropy. |
| 3759 | */ |
| 3760 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 3761 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3762 | |
| 3763 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3764 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 3765 | * resolving the location of a return address on the stack. Profilers that |
| 3766 | * change the return address on the stack can use this to resolve the stack |
| 3767 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3768 | * |
| 3769 | * \param return_addr_location points to a location on stack where a machine |
| 3770 | * return address resides. |
| 3771 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 3772 | * copy of the original return address. |
| 3773 | * |
| 3774 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3775 | */ |
| 3776 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 3777 | uintptr_t return_addr_location); |
| 3778 | |
| 3779 | |
| 3780 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3781 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 3782 | * any generated function when function-level profiling is enabled. |
| 3783 | * |
| 3784 | * \param function the address of the function that's being entered. |
| 3785 | * \param return_addr_location points to a location on stack where the machine |
| 3786 | * return address resides. This can be used to identify the caller of |
| 3787 | * \p function, and/or modified to divert execution when \p function exits. |
| 3788 | * |
| 3789 | * \note the entry hook must not cause garbage collection. |
| 3790 | */ |
| 3791 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 3792 | uintptr_t return_addr_location); |
| 3793 | |
| 3794 | |
| 3795 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3796 | * A JIT code event is issued each time code is added, moved or removed. |
| 3797 | * |
| 3798 | * \note removal events are not currently issued. |
| 3799 | */ |
| 3800 | struct JitCodeEvent { |
| 3801 | enum EventType { |
| 3802 | CODE_ADDED, |
| 3803 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3804 | CODE_REMOVED, |
| 3805 | CODE_ADD_LINE_POS_INFO, |
| 3806 | CODE_START_LINE_INFO_RECORDING, |
| 3807 | CODE_END_LINE_INFO_RECORDING |
| 3808 | }; |
| 3809 | // Definition of the code position type. The "POSITION" type means the place |
| 3810 | // in the source code which are of interest when making stack traces to |
| 3811 | // pin-point the source location of a stack frame as close as possible. |
| 3812 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 3813 | // statement, and is used to indicate possible break locations. |
| 3814 | enum PositionType { |
| 3815 | POSITION, |
| 3816 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3817 | }; |
| 3818 | |
| 3819 | // Type of event. |
| 3820 | EventType type; |
| 3821 | // Start of the instructions. |
| 3822 | void* code_start; |
| 3823 | // Size of the instructions. |
| 3824 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3825 | // Script info for CODE_ADDED event. |
| 3826 | Handle<Script> script; |
| 3827 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 3828 | // code line information which is returned from the |
| 3829 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 3830 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 3831 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3832 | |
| 3833 | union { |
| 3834 | // Only valid for CODE_ADDED. |
| 3835 | struct { |
| 3836 | // Name of the object associated with the code, note that the string is |
| 3837 | // not zero-terminated. |
| 3838 | const char* str; |
| 3839 | // Number of chars in str. |
| 3840 | size_t len; |
| 3841 | } name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3842 | |
| 3843 | // Only valid for CODE_ADD_LINE_POS_INFO |
| 3844 | struct { |
| 3845 | // PC offset |
| 3846 | size_t offset; |
| 3847 | // Code postion |
| 3848 | size_t pos; |
| 3849 | // The position type. |
| 3850 | PositionType position_type; |
| 3851 | } line_info; |
| 3852 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3853 | // New location of instructions. Only valid for CODE_MOVED. |
| 3854 | void* new_code_start; |
| 3855 | }; |
| 3856 | }; |
| 3857 | |
| 3858 | /** |
| 3859 | * Option flags passed to the SetJitCodeEventHandler function. |
| 3860 | */ |
| 3861 | enum JitCodeEventOptions { |
| 3862 | kJitCodeEventDefault = 0, |
| 3863 | // Generate callbacks for already existent code. |
| 3864 | kJitCodeEventEnumExisting = 1 |
| 3865 | }; |
| 3866 | |
| 3867 | |
| 3868 | /** |
| 3869 | * Callback function passed to SetJitCodeEventHandler. |
| 3870 | * |
| 3871 | * \param event code add, move or removal event. |
| 3872 | */ |
| 3873 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 3874 | |
| 3875 | |
| 3876 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3877 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3878 | */ |
| 3879 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 3880 | public: |
| 3881 | virtual ~ExternalResourceVisitor() {} |
| 3882 | virtual void VisitExternalString(Handle<String> string) {} |
| 3883 | }; |
| 3884 | |
| 3885 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3886 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3887 | * Interface for iterating through all the persistent handles in the heap. |
| 3888 | */ |
| 3889 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 3890 | public: |
| 3891 | virtual ~PersistentHandleVisitor() {} |
| 3892 | virtual void VisitPersistentHandle(Persistent<Value> value, |
| 3893 | uint16_t class_id) {} |
| 3894 | }; |
| 3895 | |
| 3896 | |
| 3897 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3898 | * Asserts that no action is performed that could cause a handle's value |
| 3899 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 3900 | * be performed. |
| 3901 | */ |
| 3902 | class V8EXPORT AssertNoGCScope { |
| 3903 | #ifndef DEBUG |
| 3904 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} |
| 3905 | #else |
| 3906 | AssertNoGCScope(Isolate* isolate); |
| 3907 | ~AssertNoGCScope(); |
| 3908 | private: |
| 3909 | Isolate* isolate_; |
| 3910 | bool last_state_; |
| 3911 | #endif |
| 3912 | }; |
| 3913 | |
| 3914 | |
| 3915 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3916 | * Container class for static utility functions. |
| 3917 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3918 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3919 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3920 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3921 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 3922 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3923 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3924 | * Set the callback to invoke to check if code generation from |
| 3925 | * strings should be allowed. |
| 3926 | */ |
| 3927 | static void SetAllowCodeGenerationFromStringsCallback( |
| 3928 | AllowCodeGenerationFromStringsCallback that); |
| 3929 | |
| 3930 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3931 | * Ignore out-of-memory exceptions. |
| 3932 | * |
| 3933 | * V8 running out of memory is treated as a fatal error by default. |
| 3934 | * This means that the fatal error handler is called and that V8 is |
| 3935 | * terminated. |
| 3936 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3937 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3938 | * out-of-memory situation as a fatal error. This way, the contexts |
| 3939 | * that did not cause the out of memory problem might be able to |
| 3940 | * continue execution. |
| 3941 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3942 | static void IgnoreOutOfMemoryException(); |
| 3943 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3944 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3945 | * 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] | 3946 | * fatal errors such as out-of-memory situations. |
| 3947 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3948 | static bool IsDead(); |
| 3949 | |
| 3950 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3951 | * The following 4 functions are to be used when V8 is built with |
| 3952 | * the 'compress_startup_data' flag enabled. In this case, the |
| 3953 | * embedder must decompress startup data prior to initializing V8. |
| 3954 | * |
| 3955 | * This is how interaction with V8 should look like: |
| 3956 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 3957 | * v8::StartupData* compressed_data = |
| 3958 | * new v8::StartupData[compressed_data_count]; |
| 3959 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 3960 | * ... decompress data (compressed_data can be updated in-place) ... |
| 3961 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 3962 | * ... now V8 can be initialized |
| 3963 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3964 | * |
| 3965 | * A helper class StartupDataDecompressor is provided. It implements |
| 3966 | * the protocol of the interaction described above, and can be used in |
| 3967 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3968 | */ |
| 3969 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 3970 | static int GetCompressedStartupDataCount(); |
| 3971 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 3972 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 3973 | |
| 3974 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3975 | * Adds a message listener. |
| 3976 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3977 | * 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] | 3978 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3979 | * |
| 3980 | * If data is specified, it will be passed to the callback when it is called. |
| 3981 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3982 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3983 | static bool AddMessageListener(MessageCallback that, |
| 3984 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3985 | |
| 3986 | /** |
| 3987 | * Remove all message listeners from the specified callback function. |
| 3988 | */ |
| 3989 | static void RemoveMessageListeners(MessageCallback that); |
| 3990 | |
| 3991 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3992 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 3993 | * and report it to the message listeners. The option is off by default. |
| 3994 | */ |
| 3995 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 3996 | bool capture, |
| 3997 | int frame_limit = 10, |
| 3998 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 3999 | |
| 4000 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4001 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4002 | */ |
| 4003 | static void SetFlagsFromString(const char* str, int length); |
| 4004 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4005 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4006 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4007 | */ |
| 4008 | static void SetFlagsFromCommandLine(int* argc, |
| 4009 | char** argv, |
| 4010 | bool remove_flags); |
| 4011 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4012 | /** Get the version string. */ |
| 4013 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4014 | |
| 4015 | /** |
| 4016 | * Enables the host application to provide a mechanism for recording |
| 4017 | * statistics counters. |
| 4018 | */ |
| 4019 | static void SetCounterFunction(CounterLookupCallback); |
| 4020 | |
| 4021 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4022 | * Enables the host application to provide a mechanism for recording |
| 4023 | * histograms. The CreateHistogram function returns a |
| 4024 | * histogram which will later be passed to the AddHistogramSample |
| 4025 | * function. |
| 4026 | */ |
| 4027 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4028 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4029 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4030 | /** Callback function for reporting failed access checks.*/ |
| 4031 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4032 | |
| 4033 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4034 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4035 | * garbage collection. Allocations are not allowed in the |
| 4036 | * callback function, you therefore cannot manipulate objects (set |
| 4037 | * or delete properties for example) since it is possible such |
| 4038 | * operations will result in the allocation of objects. It is possible |
| 4039 | * to specify the GCType filter for your callback. But it is not possible to |
| 4040 | * register the same callback function two times with different |
| 4041 | * GCType filters. |
| 4042 | */ |
| 4043 | static void AddGCPrologueCallback( |
| 4044 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4045 | |
| 4046 | /** |
| 4047 | * This function removes callback which was installed by |
| 4048 | * AddGCPrologueCallback function. |
| 4049 | */ |
| 4050 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4051 | |
| 4052 | /** |
| 4053 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4054 | * Enables the host application to receive a notification before a |
| 4055 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4056 | * callback function, you therefore cannot manipulate objects (set |
| 4057 | * or delete properties for example) since it is possible such |
| 4058 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4059 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4060 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4061 | |
| 4062 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4063 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4064 | * garbage collection. Allocations are not allowed in the |
| 4065 | * callback function, you therefore cannot manipulate objects (set |
| 4066 | * or delete properties for example) since it is possible such |
| 4067 | * operations will result in the allocation of objects. It is possible |
| 4068 | * to specify the GCType filter for your callback. But it is not possible to |
| 4069 | * register the same callback function two times with different |
| 4070 | * GCType filters. |
| 4071 | */ |
| 4072 | static void AddGCEpilogueCallback( |
| 4073 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4074 | |
| 4075 | /** |
| 4076 | * This function removes callback which was installed by |
| 4077 | * AddGCEpilogueCallback function. |
| 4078 | */ |
| 4079 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4080 | |
| 4081 | /** |
| 4082 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4083 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4084 | * major garbage collection. Allocations are not allowed in the |
| 4085 | * callback function, you therefore cannot manipulate objects (set |
| 4086 | * or delete properties for example) since it is possible such |
| 4087 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4088 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4089 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4090 | |
| 4091 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4092 | * Enables the host application to provide a mechanism to be notified |
| 4093 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4094 | */ |
| 4095 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4096 | ObjectSpace space, |
| 4097 | AllocationAction action); |
| 4098 | |
| 4099 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4100 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4101 | */ |
| 4102 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4103 | |
| 4104 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4105 | * Adds a callback to notify the host application when a script finished |
| 4106 | * running. If a script re-enters the runtime during executing, the |
| 4107 | * CallCompletedCallback is only invoked when the outer-most script |
| 4108 | * execution ends. Executing scripts inside the callback do not trigger |
| 4109 | * further callbacks. |
| 4110 | */ |
| 4111 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4112 | |
| 4113 | /** |
| 4114 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4115 | */ |
| 4116 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4117 | |
| 4118 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4119 | * Allows the host application to group objects together. If one |
| 4120 | * object in the group is alive, all objects in the group are alive. |
| 4121 | * After each garbage collection, object groups are removed. It is |
| 4122 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4123 | * function, for instance to simulate DOM tree connections among JS |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4124 | * wrapper objects. Object groups for all dependent handles need to |
| 4125 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 4126 | * garbage collection types it is sufficient to provide object groups |
| 4127 | * for partially dependent handles only. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4128 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4129 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4130 | // TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId and |
| 4131 | // HeapProfiler::SetRetainedObjectInfo instead. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4132 | static void AddObjectGroup(Persistent<Value>* objects, |
| 4133 | size_t length, |
| 4134 | RetainedObjectInfo* info = NULL); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4135 | static void AddObjectGroup(Isolate* isolate, |
| 4136 | Persistent<Value>* objects, |
| 4137 | size_t length, |
| 4138 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4139 | |
| 4140 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4141 | * Allows the host application to declare implicit references between |
| 4142 | * the objects: if |parent| is alive, all |children| are alive too. |
| 4143 | * After each garbage collection, all implicit references |
| 4144 | * are removed. It is intended to be used in the before-garbage-collection |
| 4145 | * callback function. |
| 4146 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4147 | // TODO(marja): Deprecate AddImplicitReferences. Use |
| 4148 | // Isolate::SetReferenceFromGroup instead. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4149 | static void AddImplicitReferences(Persistent<Object> parent, |
| 4150 | Persistent<Value>* children, |
| 4151 | size_t length); |
| 4152 | |
| 4153 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4154 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4155 | * initialize from scratch. This function is called implicitly if |
| 4156 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4157 | */ |
| 4158 | static bool Initialize(); |
| 4159 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4160 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4161 | * Allows the host application to provide a callback which can be used |
| 4162 | * as a source of entropy for random number generators. |
| 4163 | */ |
| 4164 | static void SetEntropySource(EntropySource source); |
| 4165 | |
| 4166 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4167 | * Allows the host application to provide a callback that allows v8 to |
| 4168 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4169 | */ |
| 4170 | static void SetReturnAddressLocationResolver( |
| 4171 | ReturnAddressLocationResolver return_address_resolver); |
| 4172 | |
| 4173 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4174 | * Allows the host application to provide the address of a function that's |
| 4175 | * invoked on entry to every V8-generated function. |
| 4176 | * Note that \p entry_hook is invoked at the very start of each |
| 4177 | * generated function. |
| 4178 | * |
| 4179 | * \param entry_hook a function that will be invoked on entry to every |
| 4180 | * V8-generated function. |
| 4181 | * \returns true on success on supported platforms, false on failure. |
| 4182 | * \note Setting a new entry hook function when one is already active will |
| 4183 | * fail. |
| 4184 | */ |
| 4185 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4186 | |
| 4187 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4188 | * Allows the host application to provide the address of a function that is |
| 4189 | * notified each time code is added, moved or removed. |
| 4190 | * |
| 4191 | * \param options options for the JIT code event handler. |
| 4192 | * \param event_handler the JIT code event handler, which will be invoked |
| 4193 | * each time code is added, moved or removed. |
| 4194 | * \note \p event_handler won't get notified of existent code. |
| 4195 | * \note since code removal notifications are not currently issued, the |
| 4196 | * \p event_handler may get notifications of code that overlaps earlier |
| 4197 | * code notifications. This happens when code areas are reused, and the |
| 4198 | * earlier overlapping code areas should therefore be discarded. |
| 4199 | * \note the events passed to \p event_handler and the strings they point to |
| 4200 | * are not guaranteed to live past each call. The \p event_handler must |
| 4201 | * copy strings and other parameters it needs to keep around. |
| 4202 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4203 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4204 | * new members. The \p event_handler function must ignore event codes |
| 4205 | * it does not recognize to maintain future compatibility. |
| 4206 | */ |
| 4207 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4208 | JitCodeEventHandler event_handler); |
| 4209 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4210 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4211 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4212 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4213 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4214 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4215 | /** |
| 4216 | * Suspends recording of tick samples in the profiler. |
| 4217 | * When the V8 profiling mode is enabled (usually via command line |
| 4218 | * switches) this function suspends recording of tick samples. |
| 4219 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4220 | * |
| 4221 | * See also the --prof and --prof_auto command line switches to |
| 4222 | * enable V8 profiling. |
| 4223 | */ |
| 4224 | static void PauseProfiler(); |
| 4225 | |
| 4226 | /** |
| 4227 | * Resumes recording of tick samples in the profiler. |
| 4228 | * See also PauseProfiler(). |
| 4229 | */ |
| 4230 | static void ResumeProfiler(); |
| 4231 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4232 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4233 | * Return whether profiler is currently paused. |
| 4234 | */ |
| 4235 | static bool IsProfilerPaused(); |
| 4236 | |
| 4237 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4238 | * Retrieve the V8 thread id of the calling thread. |
| 4239 | * |
| 4240 | * The thread id for a thread should only be retrieved after the V8 |
| 4241 | * lock has been acquired with a Locker object with that thread. |
| 4242 | */ |
| 4243 | static int GetCurrentThreadId(); |
| 4244 | |
| 4245 | /** |
| 4246 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4247 | * be used to terminate long-running scripts. |
| 4248 | * |
| 4249 | * TerminateExecution should only be called when then V8 lock has |
| 4250 | * been acquired with a Locker object. Therefore, in order to be |
| 4251 | * able to terminate long-running threads, preemption must be |
| 4252 | * enabled to allow the user of TerminateExecution to acquire the |
| 4253 | * lock. |
| 4254 | * |
| 4255 | * The termination is achieved by throwing an exception that is |
| 4256 | * uncatchable by JavaScript exception handlers. Termination |
| 4257 | * 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] | 4258 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4259 | * exception handler that catches an exception should check if that |
| 4260 | * exception is a termination exception and immediately return if |
| 4261 | * that is the case. Returning immediately in that case will |
| 4262 | * continue the propagation of the termination exception if needed. |
| 4263 | * |
| 4264 | * The thread id passed to TerminateExecution must have been |
| 4265 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4266 | * |
| 4267 | * \param thread_id The thread id of the thread to terminate. |
| 4268 | */ |
| 4269 | static void TerminateExecution(int thread_id); |
| 4270 | |
| 4271 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4272 | * Forcefully terminate the current thread of JavaScript execution |
| 4273 | * in the given isolate. If no isolate is provided, the default |
| 4274 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4275 | * |
| 4276 | * This method can be used by any thread even if that thread has not |
| 4277 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4278 | * |
| 4279 | * \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] | 4280 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4281 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4282 | |
| 4283 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4284 | * Is V8 terminating JavaScript execution. |
| 4285 | * |
| 4286 | * Returns true if JavaScript execution is currently terminating |
| 4287 | * because of a call to TerminateExecution. In that case there are |
| 4288 | * still JavaScript frames on the stack and the termination |
| 4289 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4290 | * |
| 4291 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4292 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4293 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4294 | |
| 4295 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4296 | * Resume execution capability in the given isolate, whose execution |
| 4297 | * was previously forcefully terminated using TerminateExecution(). |
| 4298 | * |
| 4299 | * When execution is forcefully terminated using TerminateExecution(), |
| 4300 | * the isolate can not resume execution until all JavaScript frames |
| 4301 | * have propagated the uncatchable exception which is generated. This |
| 4302 | * method allows the program embedding the engine to handle the |
| 4303 | * termination event and resume execution capability, even if |
| 4304 | * JavaScript frames remain on the stack. |
| 4305 | * |
| 4306 | * This method can be used by any thread even if that thread has not |
| 4307 | * acquired the V8 lock with a Locker object. |
| 4308 | * |
| 4309 | * \param isolate The isolate in which to resume execution capability. |
| 4310 | */ |
| 4311 | static void CancelTerminateExecution(Isolate* isolate); |
| 4312 | |
| 4313 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4314 | * Releases any resources used by v8 and stops any utility threads |
| 4315 | * that may be running. Note that disposing v8 is permanent, it |
| 4316 | * cannot be reinitialized. |
| 4317 | * |
| 4318 | * It should generally not be necessary to dispose v8 before exiting |
| 4319 | * a process, this should happen automatically. It is only necessary |
| 4320 | * to use if the process needs the resources taken up by v8. |
| 4321 | */ |
| 4322 | static bool Dispose(); |
| 4323 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4324 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4325 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4326 | |
| 4327 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4328 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4329 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4330 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4331 | */ |
| 4332 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4333 | |
| 4334 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4335 | * Iterates through all the persistent handles in the current isolate's heap |
| 4336 | * that have class_ids. |
| 4337 | */ |
| 4338 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4339 | |
| 4340 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4341 | * Iterates through all the persistent handles in the current isolate's heap |
| 4342 | * that have class_ids and are candidates to be marked as partially dependent |
| 4343 | * handles. This will visit handles to young objects created since the last |
| 4344 | * garbage collection but is free to visit an arbitrary superset of these |
| 4345 | * objects. |
| 4346 | */ |
| 4347 | static void VisitHandlesForPartialDependence( |
| 4348 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4349 | |
| 4350 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4351 | * Optional notification that the embedder is idle. |
| 4352 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4353 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4354 | * Returns true if the embedder should stop calling IdleNotification |
| 4355 | * until real work has been done. This indicates that V8 has done |
| 4356 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4357 | * |
| 4358 | * The hint argument specifies the amount of work to be done in the function |
| 4359 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4360 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4361 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4362 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4363 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4364 | /** |
| 4365 | * Optional notification that the system is running low on memory. |
| 4366 | * V8 uses these notifications to attempt to free memory. |
| 4367 | */ |
| 4368 | static void LowMemoryNotification(); |
| 4369 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4370 | /** |
| 4371 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4372 | * these notifications to guide the GC heuristic. Returns the number |
| 4373 | * of context disposals - including this one - since the last time |
| 4374 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4375 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4376 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4377 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4378 | private: |
| 4379 | V8(); |
| 4380 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4381 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4382 | internal::Object** handle); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4383 | static void DisposeGlobal(internal::Isolate* isolate, |
| 4384 | internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4385 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4386 | static void MakeWeak(internal::Isolate* isolate, |
| 4387 | internal::Object** global_handle, |
| 4388 | void* data, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4389 | RevivableCallback weak_reference_callback, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4390 | NearDeathCallback near_death_callback); |
| 4391 | static void ClearWeak(internal::Isolate* isolate, |
| 4392 | internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4393 | |
| 4394 | template <class T> friend class Handle; |
| 4395 | template <class T> friend class Local; |
| 4396 | template <class T> friend class Persistent; |
| 4397 | friend class Context; |
| 4398 | }; |
| 4399 | |
| 4400 | |
| 4401 | /** |
| 4402 | * An external exception handler. |
| 4403 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4404 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4405 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4406 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4407 | * Creates a new try/catch block and registers it with v8. Note that |
| 4408 | * all TryCatch blocks should be stack allocated because the memory |
| 4409 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4410 | */ |
| 4411 | TryCatch(); |
| 4412 | |
| 4413 | /** |
| 4414 | * Unregisters and deletes this try/catch block. |
| 4415 | */ |
| 4416 | ~TryCatch(); |
| 4417 | |
| 4418 | /** |
| 4419 | * Returns true if an exception has been caught by this try/catch block. |
| 4420 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4421 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4422 | |
| 4423 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4424 | * 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] | 4425 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4426 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4427 | * cleanup needed and then return. If CanContinue returns false and |
| 4428 | * HasTerminated returns true, it is possible to call |
| 4429 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4430 | */ |
| 4431 | bool CanContinue() const; |
| 4432 | |
| 4433 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4434 | * Returns true if an exception has been caught due to script execution |
| 4435 | * being terminated. |
| 4436 | * |
| 4437 | * There is no JavaScript representation of an execution termination |
| 4438 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4439 | * methods are called to terminate a long-running script. |
| 4440 | * |
| 4441 | * If such an exception has been thrown, HasTerminated will return true, |
| 4442 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4443 | * to continue calling into the engine. |
| 4444 | */ |
| 4445 | bool HasTerminated() const; |
| 4446 | |
| 4447 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4448 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4449 | * it being caught again by this same TryCatch. As with ThrowException |
| 4450 | * it is illegal to execute any JavaScript operations after calling |
| 4451 | * ReThrow; the caller must return immediately to where the exception |
| 4452 | * is caught. |
| 4453 | */ |
| 4454 | Handle<Value> ReThrow(); |
| 4455 | |
| 4456 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4457 | * Returns the exception caught by this try/catch block. If no exception has |
| 4458 | * been caught an empty handle is returned. |
| 4459 | * |
| 4460 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4461 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4462 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4463 | |
| 4464 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4465 | * Returns the .stack property of the thrown object. If no .stack |
| 4466 | * property is present an empty handle is returned. |
| 4467 | */ |
| 4468 | Local<Value> StackTrace() const; |
| 4469 | |
| 4470 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4471 | * Returns the message associated with this exception. If there is |
| 4472 | * no message associated an empty handle is returned. |
| 4473 | * |
| 4474 | * The returned handle is valid until this TryCatch block has been |
| 4475 | * destroyed. |
| 4476 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4477 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4478 | |
| 4479 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4480 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4481 | * After this method has been called, HasCaught() will return false. |
| 4482 | * |
| 4483 | * It is not necessary to clear a try/catch block before using it again; if |
| 4484 | * another exception is thrown the previously caught exception will just be |
| 4485 | * overwritten. However, it is often a good idea since it makes it easier |
| 4486 | * to determine which operation threw a given exception. |
| 4487 | */ |
| 4488 | void Reset(); |
| 4489 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4490 | /** |
| 4491 | * Set verbosity of the external exception handler. |
| 4492 | * |
| 4493 | * By default, exceptions that are caught by an external exception |
| 4494 | * handler are not reported. Call SetVerbose with true on an |
| 4495 | * external exception handler to have exceptions caught by the |
| 4496 | * handler reported as if they were not caught. |
| 4497 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4498 | void SetVerbose(bool value); |
| 4499 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4500 | /** |
| 4501 | * Set whether or not this TryCatch should capture a Message object |
| 4502 | * which holds source information about where the exception |
| 4503 | * occurred. True by default. |
| 4504 | */ |
| 4505 | void SetCaptureMessage(bool value); |
| 4506 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4507 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4508 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4509 | TryCatch(const TryCatch&); |
| 4510 | void operator=(const TryCatch&); |
| 4511 | void* operator new(size_t size); |
| 4512 | void operator delete(void*, size_t); |
| 4513 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4514 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4515 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4516 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4517 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4518 | bool is_verbose_ : 1; |
| 4519 | bool can_continue_ : 1; |
| 4520 | bool capture_message_ : 1; |
| 4521 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4522 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4523 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4524 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4525 | }; |
| 4526 | |
| 4527 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4528 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4529 | |
| 4530 | |
| 4531 | /** |
| 4532 | * Ignore |
| 4533 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4534 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4535 | public: |
| 4536 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4537 | : name_count_(name_count), names_(names) { } |
| 4538 | private: |
| 4539 | friend class ImplementationUtilities; |
| 4540 | int name_count_; |
| 4541 | const char** names_; |
| 4542 | }; |
| 4543 | |
| 4544 | |
| 4545 | /** |
| 4546 | * A sandboxed execution context with its own set of built-in objects |
| 4547 | * and functions. |
| 4548 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4549 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4550 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4551 | /** |
| 4552 | * Returns the global proxy object or global object itself for |
| 4553 | * detached contexts. |
| 4554 | * |
| 4555 | * Global proxy object is a thin wrapper whose prototype points to |
| 4556 | * actual context's global object with the properties like Object, etc. |
| 4557 | * This is done that way for security reasons (for more details see |
| 4558 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4559 | * |
| 4560 | * Please note that changes to global proxy object prototype most probably |
| 4561 | * would break VM---v8 expects only global object as a prototype of |
| 4562 | * global proxy object. |
| 4563 | * |
| 4564 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4565 | * object until global is reattached with ReattachGlobal(). |
| 4566 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4567 | Local<Object> Global(); |
| 4568 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4569 | /** |
| 4570 | * Detaches the global object from its context before |
| 4571 | * the global object can be reused to create a new context. |
| 4572 | */ |
| 4573 | void DetachGlobal(); |
| 4574 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4575 | /** |
| 4576 | * Reattaches a global object to a context. This can be used to |
| 4577 | * restore the connection between a global object and a context |
| 4578 | * after DetachGlobal has been called. |
| 4579 | * |
| 4580 | * \param global_object The global object to reattach to the |
| 4581 | * context. For this to work, the global object must be the global |
| 4582 | * object that was associated with this context before a call to |
| 4583 | * DetachGlobal. |
| 4584 | */ |
| 4585 | void ReattachGlobal(Handle<Object> global_object); |
| 4586 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4587 | /** |
| 4588 | * Creates a new context and returns a handle to the newly allocated |
| 4589 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4590 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4591 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4592 | * |
| 4593 | * \param extensions An optional extension configuration containing |
| 4594 | * the extensions to be installed in the newly created context. |
| 4595 | * |
| 4596 | * \param global_template An optional object template from which the |
| 4597 | * global object for the newly created context will be created. |
| 4598 | * |
| 4599 | * \param global_object An optional global object to be reused for |
| 4600 | * the newly created context. This global object must have been |
| 4601 | * created by a previous call to Context::New with the same global |
| 4602 | * template. The state of the global object will be completely reset |
| 4603 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4604 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4605 | static Local<Context> New( |
| 4606 | Isolate* isolate, |
| 4607 | ExtensionConfiguration* extensions = NULL, |
| 4608 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4609 | Handle<Value> global_object = Handle<Value>()); |
| 4610 | |
| 4611 | /** Deprecated. Use Isolate version instead. */ |
| 4612 | // TODO(mstarzinger): Put this behind the V8_DEPRECATED guard. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4613 | static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4614 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4615 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4616 | Handle<Value> global_object = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4617 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4618 | /** Returns the last entered context. */ |
| 4619 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4620 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4621 | // TODO(svenpanne) Actually deprecate this. |
| 4622 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4623 | static Local<Context> GetCurrent(); |
| 4624 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4625 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4626 | * Returns the context of the calling JavaScript code. That is the |
| 4627 | * context of the top-most JavaScript frame. If there are no |
| 4628 | * JavaScript frames an empty handle is returned. |
| 4629 | */ |
| 4630 | static Local<Context> GetCalling(); |
| 4631 | |
| 4632 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4633 | * Sets the security token for the context. To access an object in |
| 4634 | * another context, the security tokens must match. |
| 4635 | */ |
| 4636 | void SetSecurityToken(Handle<Value> token); |
| 4637 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4638 | /** Restores the security token to the default value. */ |
| 4639 | void UseDefaultSecurityToken(); |
| 4640 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4641 | /** Returns the security token of this context.*/ |
| 4642 | Handle<Value> GetSecurityToken(); |
| 4643 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4644 | /** |
| 4645 | * Enter this context. After entering a context, all code compiled |
| 4646 | * and run is compiled and run in this context. If another context |
| 4647 | * is already entered, this old context is saved so it can be |
| 4648 | * restored when the new context is exited. |
| 4649 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4650 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4651 | |
| 4652 | /** |
| 4653 | * Exit this context. Exiting the current context restores the |
| 4654 | * context that was in place when entering the current context. |
| 4655 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4656 | void Exit(); |
| 4657 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4658 | /** 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] | 4659 | bool HasOutOfMemoryException(); |
| 4660 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4661 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4662 | static bool InContext(); |
| 4663 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4664 | /** Returns an isolate associated with a current context. */ |
| 4665 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4666 | |
| 4667 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4668 | * Gets the embedder data with the given index, which must have been set by a |
| 4669 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4670 | * currently has a special meaning for Chrome's debugger. |
| 4671 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4672 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4673 | |
| 4674 | /** |
| 4675 | * Sets the embedder data with the given index, growing the data as |
| 4676 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4677 | * debugger. |
| 4678 | */ |
| 4679 | void SetEmbedderData(int index, Handle<Value> value); |
| 4680 | |
| 4681 | /** |
| 4682 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4683 | * index, which must have bees set by a previous call to |
| 4684 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4685 | * currently has a special meaning for Chrome's debugger. |
| 4686 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4687 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4688 | |
| 4689 | /** |
| 4690 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4691 | * index, growing the data as needed. Note that index 0 currently has a |
| 4692 | * special meaning for Chrome's debugger. |
| 4693 | */ |
| 4694 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4695 | |
| 4696 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4697 | * Control whether code generation from strings is allowed. Calling |
| 4698 | * this method with false will disable 'eval' and the 'Function' |
| 4699 | * constructor for code running in this context. If 'eval' or the |
| 4700 | * 'Function' constructor are used an exception will be thrown. |
| 4701 | * |
| 4702 | * If code generation from strings is not allowed the |
| 4703 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4704 | * set before blocking the call to 'eval' or the 'Function' |
| 4705 | * constructor. If that callback returns true, the call will be |
| 4706 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4707 | * set an exception will be thrown. |
| 4708 | */ |
| 4709 | void AllowCodeGenerationFromStrings(bool allow); |
| 4710 | |
| 4711 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4712 | * Returns true if code generation from strings is allowed for the context. |
| 4713 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4714 | */ |
| 4715 | bool IsCodeGenerationFromStringsAllowed(); |
| 4716 | |
| 4717 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4718 | * Sets the error description for the exception that is thrown when |
| 4719 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4720 | * constructor are called. |
| 4721 | */ |
| 4722 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4723 | |
| 4724 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4725 | * Stack-allocated class which sets the execution context for all |
| 4726 | * operations executed within a local scope. |
| 4727 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4728 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4729 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4730 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4731 | context_->Enter(); |
| 4732 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4733 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4734 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4735 | : context_(Handle<Context>::New(isolate, context)) { |
| 4736 | #else |
| 4737 | : context_(Local<Context>::New(isolate, context)) { |
| 4738 | #endif |
| 4739 | context_->Enter(); |
| 4740 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4741 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4742 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4743 | private: |
| 4744 | Handle<Context> context_; |
| 4745 | }; |
| 4746 | |
| 4747 | private: |
| 4748 | friend class Value; |
| 4749 | friend class Script; |
| 4750 | friend class Object; |
| 4751 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4752 | |
| 4753 | Local<Value> SlowGetEmbedderData(int index); |
| 4754 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4755 | }; |
| 4756 | |
| 4757 | |
| 4758 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4759 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4760 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4761 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4762 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4763 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4764 | * constraint is not violated. In addition to any other synchronization |
| 4765 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4766 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4767 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4768 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4769 | * construction and destruction, the current thread is allowed to use the locked |
| 4770 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4771 | * 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] | 4772 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4773 | * Sample usage: |
| 4774 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4775 | * ... |
| 4776 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4777 | * v8::Locker locker(isolate); |
| 4778 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4779 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4780 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4781 | * ... |
| 4782 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4783 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4784 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4785 | * If you wish to stop using V8 in a thread A you can do this either by |
| 4786 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 4787 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4788 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4789 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4790 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4791 | * isolate->Exit(); |
| 4792 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4793 | * ... |
| 4794 | * // Code not using V8 goes here while V8 can run in another thread. |
| 4795 | * ... |
| 4796 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4797 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4798 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4799 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4800 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 4801 | * 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] | 4802 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4803 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 4804 | * given thread. This can be useful if you have code that can be called either |
| 4805 | * from code that holds the lock or from code that does not. The Unlocker is |
| 4806 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 4807 | * 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] | 4808 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4809 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 4810 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4811 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4812 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4813 | * // V8 not locked. |
| 4814 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4815 | * v8::Locker locker(isolate); |
| 4816 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4817 | * // V8 locked. |
| 4818 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4819 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4820 | * // V8 still locked (2 levels). |
| 4821 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4822 | * isolate->Exit(); |
| 4823 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4824 | * // V8 not locked. |
| 4825 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4826 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4827 | * // V8 locked again (2 levels). |
| 4828 | * } |
| 4829 | * // V8 still locked (1 level). |
| 4830 | * } |
| 4831 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4832 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4833 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4834 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4835 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4836 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4837 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4838 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4839 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 4840 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4841 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4842 | V8_DEPRECATED(Unlocker()); |
| 4843 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4844 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4845 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4846 | void Initialize(Isolate* isolate); |
| 4847 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4848 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4849 | }; |
| 4850 | |
| 4851 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4852 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4854 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4855 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4856 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4857 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 4858 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4859 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4860 | V8_DEPRECATED(Locker()); |
| 4861 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4862 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4863 | |
| 4864 | /** |
| 4865 | * Start preemption. |
| 4866 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4867 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4868 | * that will switch between multiple threads that are in contention |
| 4869 | * for the V8 lock. |
| 4870 | */ |
| 4871 | static void StartPreemption(int every_n_ms); |
| 4872 | |
| 4873 | /** |
| 4874 | * Stop preemption. |
| 4875 | */ |
| 4876 | static void StopPreemption(); |
| 4877 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4878 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4879 | * Returns whether or not the locker for a given isolate, is locked by the |
| 4880 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4881 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4882 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4883 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4884 | /** |
| 4885 | * Returns whether v8::Locker is being used by this V8 instance. |
| 4886 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4887 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4888 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4889 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4890 | void Initialize(Isolate* isolate); |
| 4891 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4892 | bool has_lock_; |
| 4893 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4894 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4895 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4896 | static bool active_; |
| 4897 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4898 | // Disallow copying and assigning. |
| 4899 | Locker(const Locker&); |
| 4900 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4901 | }; |
| 4902 | |
| 4903 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4904 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4905 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 4906 | */ |
| 4907 | struct HeapStatsUpdate; |
| 4908 | |
| 4909 | |
| 4910 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4911 | * An interface for exporting data from V8, using "push" model. |
| 4912 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 4913 | class V8EXPORT OutputStream { // NOLINT |
| 4914 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4915 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4916 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4917 | }; |
| 4918 | enum WriteResult { |
| 4919 | kContinue = 0, |
| 4920 | kAbort = 1 |
| 4921 | }; |
| 4922 | virtual ~OutputStream() {} |
| 4923 | /** Notify about the end of stream. */ |
| 4924 | virtual void EndOfStream() = 0; |
| 4925 | /** Get preferred output chunk size. Called only once. */ |
| 4926 | virtual int GetChunkSize() { return 1024; } |
| 4927 | /** Get preferred output encoding. Called only once. */ |
| 4928 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 4929 | /** |
| 4930 | * Writes the next chunk of snapshot data into the stream. Writing |
| 4931 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4932 | * will not be called in case writing was aborted. |
| 4933 | */ |
| 4934 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4935 | /** |
| 4936 | * Writes the next chunk of heap stats data into the stream. Writing |
| 4937 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4938 | * will not be called in case writing was aborted. |
| 4939 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4940 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 4941 | return kAbort; |
| 4942 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4943 | }; |
| 4944 | |
| 4945 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4946 | /** |
| 4947 | * An interface for reporting progress and controlling long-running |
| 4948 | * activities. |
| 4949 | */ |
| 4950 | class V8EXPORT ActivityControl { // NOLINT |
| 4951 | public: |
| 4952 | enum ControlOption { |
| 4953 | kContinue = 0, |
| 4954 | kAbort = 1 |
| 4955 | }; |
| 4956 | virtual ~ActivityControl() {} |
| 4957 | /** |
| 4958 | * Notify about current progress. The activity can be stopped by |
| 4959 | * returning kAbort as the callback result. |
| 4960 | */ |
| 4961 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 4962 | }; |
| 4963 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4964 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4965 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4966 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4967 | |
| 4968 | namespace internal { |
| 4969 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4970 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 4971 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4972 | |
| 4973 | // Tag information for HeapObject. |
| 4974 | const int kHeapObjectTag = 1; |
| 4975 | const int kHeapObjectTagSize = 2; |
| 4976 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 4977 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4978 | // Tag information for Smi. |
| 4979 | const int kSmiTag = 0; |
| 4980 | const int kSmiTagSize = 1; |
| 4981 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 4982 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4983 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4984 | |
| 4985 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4986 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4987 | static const int kSmiShiftSize = 0; |
| 4988 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4989 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4990 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 4991 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 4992 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 4993 | } |
| 4994 | }; |
| 4995 | |
| 4996 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4997 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4998 | static const int kSmiShiftSize = 31; |
| 4999 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5000 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5001 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5002 | // Shift down and throw away top 32 bits. |
| 5003 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5004 | } |
| 5005 | }; |
| 5006 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5007 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5008 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5009 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5010 | |
| 5011 | /** |
| 5012 | * This class exports constants and functionality from within v8 that |
| 5013 | * is necessary to implement inline functions in the v8 api. Don't |
| 5014 | * depend on functions and constants defined here. |
| 5015 | */ |
| 5016 | class Internals { |
| 5017 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5018 | // These values match non-compiler-dependent values defined within |
| 5019 | // the implementation of v8. |
| 5020 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5021 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5022 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5023 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5024 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5025 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5026 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5027 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5028 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5029 | static const int kContextEmbedderDataIndex = 65; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5030 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5031 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5032 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5033 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5034 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5035 | static const int kIsolateStateOffset = 0; |
| 5036 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5037 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5038 | static const int kUndefinedValueRootIndex = 5; |
| 5039 | static const int kNullValueRootIndex = 7; |
| 5040 | static const int kTrueValueRootIndex = 8; |
| 5041 | static const int kFalseValueRootIndex = 9; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5042 | static const int kEmptyStringRootIndex = 118; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5043 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5044 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5045 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5046 | static const int kNodeStateMask = 0xf; |
| 5047 | static const int kNodeStateIsWeakValue = 2; |
| 5048 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5049 | static const int kNodeIsIndependentShift = 4; |
| 5050 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5051 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5052 | static const int kJSObjectType = 0xae; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5053 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5054 | static const int kOddballType = 0x83; |
| 5055 | static const int kForeignType = 0x86; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5056 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5057 | static const int kUndefinedOddballKind = 5; |
| 5058 | static const int kNullOddballKind = 3; |
| 5059 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5060 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5061 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5062 | kHeapObjectTag); |
| 5063 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5064 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5065 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5066 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5067 | } |
| 5068 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5069 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5070 | typedef internal::Object O; |
| 5071 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5072 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5073 | } |
| 5074 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5075 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5076 | typedef internal::Object O; |
| 5077 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5078 | } |
| 5079 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5080 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5081 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5082 | return representation == kExternalTwoByteRepresentationTag; |
| 5083 | } |
| 5084 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5085 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5086 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5087 | return *reinterpret_cast<int*>(addr) == 1; |
| 5088 | } |
| 5089 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5090 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5091 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5092 | return *addr & (1 << shift); |
| 5093 | } |
| 5094 | |
| 5095 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5096 | bool value, int shift)) { |
| 5097 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5098 | uint8_t mask = 1 << shift; |
| 5099 | *addr = (*addr & ~mask) | (value << shift); |
| 5100 | } |
| 5101 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5102 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5103 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5104 | return *addr & kNodeStateMask; |
| 5105 | } |
| 5106 | |
| 5107 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5108 | uint8_t value)) { |
| 5109 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5110 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5111 | } |
| 5112 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5113 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5114 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5115 | kIsolateEmbedderDataOffset; |
| 5116 | *reinterpret_cast<void**>(addr) = data; |
| 5117 | } |
| 5118 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5119 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5120 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5121 | kIsolateEmbedderDataOffset; |
| 5122 | return *reinterpret_cast<void**>(addr); |
| 5123 | } |
| 5124 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5125 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5126 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5127 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5128 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5129 | } |
| 5130 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5131 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5132 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5133 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5134 | return *reinterpret_cast<T*>(addr); |
| 5135 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5136 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5137 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5138 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5139 | typedef internal::Object O; |
| 5140 | typedef internal::Internals I; |
| 5141 | O* ctx = *reinterpret_cast<O**>(context); |
| 5142 | int embedder_data_offset = I::kContextHeaderSize + |
| 5143 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5144 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5145 | int value_offset = |
| 5146 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5147 | return I::ReadField<T>(embedder_data, value_offset); |
| 5148 | } |
| 5149 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5150 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5151 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5152 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5153 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5154 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5155 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5156 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5157 | }; |
| 5158 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5159 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5160 | |
| 5161 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5162 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5163 | Local<T>::Local() : Handle<T>() { } |
| 5164 | |
| 5165 | |
| 5166 | template <class T> |
| 5167 | Local<T> Local<T>::New(Handle<T> that) { |
| 5168 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5169 | T* that_ptr = *that; |
| 5170 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5171 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5172 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5173 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5174 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5175 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5176 | } |
| 5177 | |
| 5178 | |
| 5179 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5180 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5181 | return New(isolate, that.val_); |
| 5182 | } |
| 5183 | |
| 5184 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5185 | template <class T> |
| 5186 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5187 | return New(isolate, that.val_); |
| 5188 | } |
| 5189 | |
| 5190 | template <class T> |
| 5191 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5192 | if (that == NULL) return Handle<T>(); |
| 5193 | T* that_ptr = that; |
| 5194 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5195 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5196 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5197 | } |
| 5198 | #endif |
| 5199 | |
| 5200 | |
| 5201 | template <class T> |
| 5202 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5203 | if (that == NULL) return Local<T>(); |
| 5204 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5205 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5206 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5207 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5212 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5213 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | |
| 5217 | template <class T> |
| 5218 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5219 | return New(Isolate::GetCurrent(), that.val_); |
| 5220 | } |
| 5221 | |
| 5222 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5223 | template <class T> |
| 5224 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5225 | return New(Isolate::GetCurrent(), that.val_); |
| 5226 | } |
| 5227 | #endif |
| 5228 | |
| 5229 | template <class T> |
| 5230 | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5231 | if (that == NULL) return Persistent<T>(); |
| 5232 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5233 | return Persistent<T>(reinterpret_cast<T*>( |
| 5234 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5235 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | |
| 5239 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5240 | bool Persistent<T>::IsIndependent() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5241 | return IsIndependent(Isolate::GetCurrent()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | |
| 5245 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5246 | bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5247 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5248 | if (this->IsEmpty()) return false; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5249 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5250 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5251 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | |
| 5255 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5256 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5257 | return IsNearDeath(Isolate::GetCurrent()); |
| 5258 | } |
| 5259 | |
| 5260 | |
| 5261 | template <class T> |
| 5262 | bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 5263 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5264 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5265 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5266 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5267 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | |
| 5271 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5272 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5273 | return IsWeak(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | |
| 5277 | template <class T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5278 | bool Persistent<T>::IsWeak(Isolate* isolate) const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5279 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5280 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5281 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5282 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5283 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | |
| 5287 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5288 | void Persistent<T>::Dispose() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5289 | Dispose(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | |
| 5293 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5294 | void Persistent<T>::Dispose(Isolate* isolate) { |
| 5295 | if (this->IsEmpty()) return; |
| 5296 | V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5297 | reinterpret_cast<internal::Object**>(this->val_)); |
| 5298 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5299 | val_ = 0; |
| 5300 | #endif |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | |
| 5304 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5305 | template <typename S, typename P> |
| 5306 | void Persistent<T>::MakeWeak( |
| 5307 | Isolate* isolate, |
| 5308 | P* parameters, |
| 5309 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5310 | TYPE_CHECK(S, T); |
| 5311 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5312 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5313 | reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5314 | parameters, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5315 | reinterpret_cast<Revivable>(callback), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5316 | NULL); |
| 5317 | } |
| 5318 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5319 | |
| 5320 | template <class T> |
| 5321 | template <typename P> |
| 5322 | void Persistent<T>::MakeWeak( |
| 5323 | Isolate* isolate, |
| 5324 | P* parameters, |
| 5325 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5326 | MakeWeak<T, P>(isolate, parameters, callback); |
| 5327 | } |
| 5328 | |
| 5329 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5330 | template <class T> |
| 5331 | void Persistent<T>::MakeWeak(Isolate* isolate, |
| 5332 | void* parameters, |
| 5333 | NearDeathCallback callback) { |
| 5334 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5335 | reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5336 | parameters, |
| 5337 | NULL, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5338 | callback); |
| 5339 | } |
| 5340 | |
| 5341 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5342 | void Persistent<T>::ClearWeak() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5343 | ClearWeak(Isolate::GetCurrent()); |
| 5344 | } |
| 5345 | |
| 5346 | template <class T> |
| 5347 | void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 5348 | V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5349 | reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5350 | } |
| 5351 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5352 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5353 | void Persistent<T>::MarkIndependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5354 | MarkIndependent(Isolate::GetCurrent()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | template <class T> |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5358 | void Persistent<T>::MarkIndependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5359 | typedef internal::Internals I; |
| 5360 | if (this->IsEmpty()) return; |
| 5361 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5362 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5363 | true, |
| 5364 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | template <class T> |
| 5368 | void Persistent<T>::MarkPartiallyDependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5369 | MarkPartiallyDependent(Isolate::GetCurrent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | template <class T> |
| 5373 | void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5374 | typedef internal::Internals I; |
| 5375 | if (this->IsEmpty()) return; |
| 5376 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5377 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5378 | true, |
| 5379 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5383 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5384 | SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 5385 | } |
| 5386 | |
| 5387 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5388 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5389 | Dispose(isolate); |
| 5390 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5391 | *this = *New(isolate, other); |
| 5392 | #else |
| 5393 | if (other.IsEmpty()) { |
| 5394 | this->val_ = NULL; |
| 5395 | return; |
| 5396 | } |
| 5397 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5398 | this->val_ = reinterpret_cast<T*>( |
| 5399 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5400 | #endif |
| 5401 | } |
| 5402 | |
| 5403 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5404 | void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5405 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5406 | if (this->IsEmpty()) return; |
| 5407 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5408 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5409 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5410 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5411 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5412 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5413 | template <class T> |
| 5414 | uint16_t Persistent<T>::WrapperClassId() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5415 | return WrapperClassId(Isolate::GetCurrent()); |
| 5416 | } |
| 5417 | |
| 5418 | template <class T> |
| 5419 | uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5420 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5421 | if (this->IsEmpty()) return 0; |
| 5422 | if (!I::IsInitialized(isolate)) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5423 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5424 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5425 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5426 | } |
| 5427 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5428 | Arguments::Arguments(internal::Object** implicit_args, |
| 5429 | internal::Object** values, int length, |
| 5430 | bool is_construct_call) |
| 5431 | : implicit_args_(implicit_args), |
| 5432 | values_(values), |
| 5433 | length_(length), |
| 5434 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5435 | |
| 5436 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5437 | Local<Value> Arguments::operator[](int i) const { |
| 5438 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5439 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5440 | } |
| 5441 | |
| 5442 | |
| 5443 | Local<Function> Arguments::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5444 | return Local<Function>(reinterpret_cast<Function*>( |
| 5445 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | |
| 5449 | Local<Object> Arguments::This() const { |
| 5450 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5451 | } |
| 5452 | |
| 5453 | |
| 5454 | Local<Object> Arguments::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5455 | return Local<Object>(reinterpret_cast<Object*>( |
| 5456 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | |
| 5460 | Local<Value> Arguments::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5461 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5465 | Isolate* Arguments::GetIsolate() const { |
| 5466 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5467 | } |
| 5468 | |
| 5469 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5470 | bool Arguments::IsConstructCall() const { |
| 5471 | return is_construct_call_; |
| 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | int Arguments::Length() const { |
| 5476 | return length_; |
| 5477 | } |
| 5478 | |
| 5479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5480 | template <class T> |
| 5481 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5482 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5483 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5484 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5485 | } |
| 5486 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5487 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5488 | return resource_name_; |
| 5489 | } |
| 5490 | |
| 5491 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5492 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5493 | return resource_line_offset_; |
| 5494 | } |
| 5495 | |
| 5496 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5497 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5498 | return resource_column_offset_; |
| 5499 | } |
| 5500 | |
| 5501 | |
| 5502 | Handle<Boolean> Boolean::New(bool value) { |
| 5503 | return value ? True() : False(); |
| 5504 | } |
| 5505 | |
| 5506 | |
| 5507 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5508 | Set(v8::String::New(name), value); |
| 5509 | } |
| 5510 | |
| 5511 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5512 | Local<Value> Object::GetInternalField(int index) { |
| 5513 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5514 | typedef internal::Object O; |
| 5515 | typedef internal::Internals I; |
| 5516 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5517 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5518 | // 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] | 5519 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5520 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5521 | O* value = I::ReadField<O*>(obj, offset); |
| 5522 | O** result = HandleScope::CreateHandle(value); |
| 5523 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5524 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5525 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5526 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5530 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5531 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5532 | typedef internal::Object O; |
| 5533 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5534 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5535 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5536 | // 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] | 5537 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5538 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5539 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5540 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5541 | #endif |
| 5542 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | |
| 5546 | String* String::Cast(v8::Value* value) { |
| 5547 | #ifdef V8_ENABLE_CHECKS |
| 5548 | CheckCast(value); |
| 5549 | #endif |
| 5550 | return static_cast<String*>(value); |
| 5551 | } |
| 5552 | |
| 5553 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5554 | Local<String> String::Empty(Isolate* isolate) { |
| 5555 | typedef internal::Object* S; |
| 5556 | typedef internal::Internals I; |
| 5557 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5558 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5559 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5560 | } |
| 5561 | |
| 5562 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5563 | Local<String> String::New(const char* data, int length) { |
| 5564 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5565 | } |
| 5566 | |
| 5567 | |
| 5568 | Local<String> String::New(const uint16_t* data, int length) { |
| 5569 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5570 | } |
| 5571 | |
| 5572 | |
| 5573 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5574 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5575 | } |
| 5576 | |
| 5577 | |
| 5578 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5579 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5580 | } |
| 5581 | |
| 5582 | |
| 5583 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5584 | return NewFromTwoByte( |
| 5585 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5586 | } |
| 5587 | |
| 5588 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5589 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5590 | typedef internal::Object O; |
| 5591 | typedef internal::Internals I; |
| 5592 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5593 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5594 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5595 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5596 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5597 | } else { |
| 5598 | result = NULL; |
| 5599 | } |
| 5600 | #ifdef V8_ENABLE_CHECKS |
| 5601 | VerifyExternalStringResource(result); |
| 5602 | #endif |
| 5603 | return result; |
| 5604 | } |
| 5605 | |
| 5606 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5607 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5608 | String::Encoding* encoding_out) const { |
| 5609 | typedef internal::Object O; |
| 5610 | typedef internal::Internals I; |
| 5611 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5612 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5613 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5614 | ExternalStringResourceBase* resource = NULL; |
| 5615 | if (type == I::kExternalAsciiRepresentationTag || |
| 5616 | type == I::kExternalTwoByteRepresentationTag) { |
| 5617 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5618 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5619 | } |
| 5620 | #ifdef V8_ENABLE_CHECKS |
| 5621 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5622 | #endif |
| 5623 | return resource; |
| 5624 | } |
| 5625 | |
| 5626 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5627 | bool Value::IsUndefined() const { |
| 5628 | #ifdef V8_ENABLE_CHECKS |
| 5629 | return FullIsUndefined(); |
| 5630 | #else |
| 5631 | return QuickIsUndefined(); |
| 5632 | #endif |
| 5633 | } |
| 5634 | |
| 5635 | bool Value::QuickIsUndefined() const { |
| 5636 | typedef internal::Object O; |
| 5637 | typedef internal::Internals I; |
| 5638 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5639 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5640 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5641 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 5642 | } |
| 5643 | |
| 5644 | |
| 5645 | bool Value::IsNull() const { |
| 5646 | #ifdef V8_ENABLE_CHECKS |
| 5647 | return FullIsNull(); |
| 5648 | #else |
| 5649 | return QuickIsNull(); |
| 5650 | #endif |
| 5651 | } |
| 5652 | |
| 5653 | bool Value::QuickIsNull() const { |
| 5654 | typedef internal::Object O; |
| 5655 | typedef internal::Internals I; |
| 5656 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5657 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5658 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5659 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 5660 | } |
| 5661 | |
| 5662 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5663 | bool Value::IsString() const { |
| 5664 | #ifdef V8_ENABLE_CHECKS |
| 5665 | return FullIsString(); |
| 5666 | #else |
| 5667 | return QuickIsString(); |
| 5668 | #endif |
| 5669 | } |
| 5670 | |
| 5671 | bool Value::QuickIsString() const { |
| 5672 | typedef internal::Object O; |
| 5673 | typedef internal::Internals I; |
| 5674 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5675 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5676 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5680 | Symbol* Symbol::Cast(v8::Value* value) { |
| 5681 | #ifdef V8_ENABLE_CHECKS |
| 5682 | CheckCast(value); |
| 5683 | #endif |
| 5684 | return static_cast<Symbol*>(value); |
| 5685 | } |
| 5686 | |
| 5687 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5688 | Number* Number::Cast(v8::Value* value) { |
| 5689 | #ifdef V8_ENABLE_CHECKS |
| 5690 | CheckCast(value); |
| 5691 | #endif |
| 5692 | return static_cast<Number*>(value); |
| 5693 | } |
| 5694 | |
| 5695 | |
| 5696 | Integer* Integer::Cast(v8::Value* value) { |
| 5697 | #ifdef V8_ENABLE_CHECKS |
| 5698 | CheckCast(value); |
| 5699 | #endif |
| 5700 | return static_cast<Integer*>(value); |
| 5701 | } |
| 5702 | |
| 5703 | |
| 5704 | Date* Date::Cast(v8::Value* value) { |
| 5705 | #ifdef V8_ENABLE_CHECKS |
| 5706 | CheckCast(value); |
| 5707 | #endif |
| 5708 | return static_cast<Date*>(value); |
| 5709 | } |
| 5710 | |
| 5711 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5712 | StringObject* StringObject::Cast(v8::Value* value) { |
| 5713 | #ifdef V8_ENABLE_CHECKS |
| 5714 | CheckCast(value); |
| 5715 | #endif |
| 5716 | return static_cast<StringObject*>(value); |
| 5717 | } |
| 5718 | |
| 5719 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5720 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 5721 | #ifdef V8_ENABLE_CHECKS |
| 5722 | CheckCast(value); |
| 5723 | #endif |
| 5724 | return static_cast<SymbolObject*>(value); |
| 5725 | } |
| 5726 | |
| 5727 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5728 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 5729 | #ifdef V8_ENABLE_CHECKS |
| 5730 | CheckCast(value); |
| 5731 | #endif |
| 5732 | return static_cast<NumberObject*>(value); |
| 5733 | } |
| 5734 | |
| 5735 | |
| 5736 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 5737 | #ifdef V8_ENABLE_CHECKS |
| 5738 | CheckCast(value); |
| 5739 | #endif |
| 5740 | return static_cast<BooleanObject*>(value); |
| 5741 | } |
| 5742 | |
| 5743 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5744 | RegExp* RegExp::Cast(v8::Value* value) { |
| 5745 | #ifdef V8_ENABLE_CHECKS |
| 5746 | CheckCast(value); |
| 5747 | #endif |
| 5748 | return static_cast<RegExp*>(value); |
| 5749 | } |
| 5750 | |
| 5751 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5752 | Object* Object::Cast(v8::Value* value) { |
| 5753 | #ifdef V8_ENABLE_CHECKS |
| 5754 | CheckCast(value); |
| 5755 | #endif |
| 5756 | return static_cast<Object*>(value); |
| 5757 | } |
| 5758 | |
| 5759 | |
| 5760 | Array* Array::Cast(v8::Value* value) { |
| 5761 | #ifdef V8_ENABLE_CHECKS |
| 5762 | CheckCast(value); |
| 5763 | #endif |
| 5764 | return static_cast<Array*>(value); |
| 5765 | } |
| 5766 | |
| 5767 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5768 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 5769 | #ifdef V8_ENABLE_CHECKS |
| 5770 | CheckCast(value); |
| 5771 | #endif |
| 5772 | return static_cast<ArrayBuffer*>(value); |
| 5773 | } |
| 5774 | |
| 5775 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5776 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 5777 | #ifdef V8_ENABLE_CHECKS |
| 5778 | CheckCast(value); |
| 5779 | #endif |
| 5780 | return static_cast<TypedArray*>(value); |
| 5781 | } |
| 5782 | |
| 5783 | |
| 5784 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 5785 | #ifdef V8_ENABLE_CHECKS |
| 5786 | CheckCast(value); |
| 5787 | #endif |
| 5788 | return static_cast<Uint8Array*>(value); |
| 5789 | } |
| 5790 | |
| 5791 | |
| 5792 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 5793 | #ifdef V8_ENABLE_CHECKS |
| 5794 | CheckCast(value); |
| 5795 | #endif |
| 5796 | return static_cast<Int8Array*>(value); |
| 5797 | } |
| 5798 | |
| 5799 | |
| 5800 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 5801 | #ifdef V8_ENABLE_CHECKS |
| 5802 | CheckCast(value); |
| 5803 | #endif |
| 5804 | return static_cast<Uint16Array*>(value); |
| 5805 | } |
| 5806 | |
| 5807 | |
| 5808 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 5809 | #ifdef V8_ENABLE_CHECKS |
| 5810 | CheckCast(value); |
| 5811 | #endif |
| 5812 | return static_cast<Int16Array*>(value); |
| 5813 | } |
| 5814 | |
| 5815 | |
| 5816 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 5817 | #ifdef V8_ENABLE_CHECKS |
| 5818 | CheckCast(value); |
| 5819 | #endif |
| 5820 | return static_cast<Uint32Array*>(value); |
| 5821 | } |
| 5822 | |
| 5823 | |
| 5824 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 5825 | #ifdef V8_ENABLE_CHECKS |
| 5826 | CheckCast(value); |
| 5827 | #endif |
| 5828 | return static_cast<Int32Array*>(value); |
| 5829 | } |
| 5830 | |
| 5831 | |
| 5832 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 5833 | #ifdef V8_ENABLE_CHECKS |
| 5834 | CheckCast(value); |
| 5835 | #endif |
| 5836 | return static_cast<Float32Array*>(value); |
| 5837 | } |
| 5838 | |
| 5839 | |
| 5840 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 5841 | #ifdef V8_ENABLE_CHECKS |
| 5842 | CheckCast(value); |
| 5843 | #endif |
| 5844 | return static_cast<Float64Array*>(value); |
| 5845 | } |
| 5846 | |
| 5847 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5848 | Function* Function::Cast(v8::Value* value) { |
| 5849 | #ifdef V8_ENABLE_CHECKS |
| 5850 | CheckCast(value); |
| 5851 | #endif |
| 5852 | return static_cast<Function*>(value); |
| 5853 | } |
| 5854 | |
| 5855 | |
| 5856 | External* External::Cast(v8::Value* value) { |
| 5857 | #ifdef V8_ENABLE_CHECKS |
| 5858 | CheckCast(value); |
| 5859 | #endif |
| 5860 | return static_cast<External*>(value); |
| 5861 | } |
| 5862 | |
| 5863 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5864 | Isolate* AccessorInfo::GetIsolate() const { |
| 5865 | return *reinterpret_cast<Isolate**>(&args_[-3]); |
| 5866 | } |
| 5867 | |
| 5868 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5869 | Local<Value> AccessorInfo::Data() const { |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5870 | return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | |
| 5874 | Local<Object> AccessorInfo::This() const { |
| 5875 | return Local<Object>(reinterpret_cast<Object*>(&args_[0])); |
| 5876 | } |
| 5877 | |
| 5878 | |
| 5879 | Local<Object> AccessorInfo::Holder() const { |
| 5880 | return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); |
| 5881 | } |
| 5882 | |
| 5883 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5884 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 5885 | typedef internal::Object* S; |
| 5886 | typedef internal::Internals I; |
| 5887 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 5888 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 5889 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5890 | } |
| 5891 | |
| 5892 | |
| 5893 | Handle<Primitive> Null(Isolate* isolate) { |
| 5894 | typedef internal::Object* S; |
| 5895 | typedef internal::Internals I; |
| 5896 | if (!I::IsInitialized(isolate)) return Null(); |
| 5897 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 5898 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5899 | } |
| 5900 | |
| 5901 | |
| 5902 | Handle<Boolean> True(Isolate* isolate) { |
| 5903 | typedef internal::Object* S; |
| 5904 | typedef internal::Internals I; |
| 5905 | if (!I::IsInitialized(isolate)) return True(); |
| 5906 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 5907 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5908 | } |
| 5909 | |
| 5910 | |
| 5911 | Handle<Boolean> False(Isolate* isolate) { |
| 5912 | typedef internal::Object* S; |
| 5913 | typedef internal::Internals I; |
| 5914 | if (!I::IsInitialized(isolate)) return False(); |
| 5915 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 5916 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5917 | } |
| 5918 | |
| 5919 | |
| 5920 | void Isolate::SetData(void* data) { |
| 5921 | typedef internal::Internals I; |
| 5922 | I::SetEmbedderData(this, data); |
| 5923 | } |
| 5924 | |
| 5925 | |
| 5926 | void* Isolate::GetData() { |
| 5927 | typedef internal::Internals I; |
| 5928 | return I::GetEmbedderData(this); |
| 5929 | } |
| 5930 | |
| 5931 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5932 | Local<Value> Context::GetEmbedderData(int index) { |
| 5933 | #ifndef V8_ENABLE_CHECKS |
| 5934 | typedef internal::Object O; |
| 5935 | typedef internal::Internals I; |
| 5936 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 5937 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 5938 | #else |
| 5939 | return SlowGetEmbedderData(index); |
| 5940 | #endif |
| 5941 | } |
| 5942 | |
| 5943 | |
| 5944 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 5945 | #ifndef V8_ENABLE_CHECKS |
| 5946 | typedef internal::Internals I; |
| 5947 | return I::ReadEmbedderData<void*>(this, index); |
| 5948 | #else |
| 5949 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 5950 | #endif |
| 5951 | } |
| 5952 | |
| 5953 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5954 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5955 | * \example shell.cc |
| 5956 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5957 | * command-line and executes them. |
| 5958 | */ |
| 5959 | |
| 5960 | |
| 5961 | /** |
| 5962 | * \example process.cc |
| 5963 | */ |
| 5964 | |
| 5965 | |
| 5966 | } // namespace v8 |
| 5967 | |
| 5968 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5969 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5970 | #undef TYPE_CHECK |
| 5971 | |
| 5972 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5973 | #endif // V8_H_ |