jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 32 | * This set of documents provides reference material generated from the |
| 33 | * V8 header file, include/v8.h. |
| 34 | * |
| 35 | * For other documentation see http://code.google.com/apis/v8/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 66 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 67 | (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 68 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 70 | #else |
| 71 | #define V8EXPORT |
| 72 | #endif |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 73 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 75 | #endif |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // _WIN32 |
| 78 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 79 | #if defined(__GNUC__) && !defined(DEBUG) |
| 80 | #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 81 | #elif defined(_MSC_VER) && !defined(DEBUG) |
| 82 | #define V8_INLINE(declarator) __forceinline declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 83 | #else |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 84 | #define V8_INLINE(declarator) inline declarator |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS |
| 88 | #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated)) |
| 89 | #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS |
| 90 | #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 91 | #else |
| 92 | #define V8_DEPRECATED(declarator) declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 95 | #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 96 | #define V8_UNLIKELY(condition) __builtin_expect((condition), 0) |
| 97 | #define V8_LIKELY(condition) __builtin_expect((condition), 1) |
| 98 | #else |
| 99 | #define V8_UNLIKELY(condition) (condition) |
| 100 | #define V8_LIKELY(condition) (condition) |
| 101 | #endif |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 104 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | */ |
| 106 | namespace v8 { |
| 107 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 108 | class AccessorInfo; |
| 109 | class AccessorSignature; |
| 110 | class Array; |
| 111 | class Boolean; |
| 112 | class BooleanObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | class Context; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 114 | class CpuProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 115 | class Data; |
| 116 | class Date; |
| 117 | class DeclaredAccessorDescriptor; |
| 118 | class External; |
| 119 | class Function; |
| 120 | class FunctionTemplate; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 121 | class HeapProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 122 | class ImplementationUtilities; |
| 123 | class Int32; |
| 124 | class Integer; |
| 125 | class Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 127 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 129 | class ObjectOperationDescriptor; |
| 130 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 132 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 134 | class StackFrame; |
| 135 | class StackTrace; |
| 136 | class String; |
| 137 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 138 | class Symbol; |
| 139 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 140 | class Uint32; |
| 141 | class Utils; |
| 142 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | template <class T> class Handle; |
| 144 | template <class T> class Local; |
| 145 | template <class T> class Persistent; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 146 | class FunctionTemplate; |
| 147 | class ObjectTemplate; |
| 148 | class Data; |
| 149 | class AccessorInfo; |
| 150 | template<typename T> class PropertyCallbackInfo; |
| 151 | class StackTrace; |
| 152 | class StackFrame; |
| 153 | class Isolate; |
| 154 | class DeclaredAccessorDescriptor; |
| 155 | class ObjectOperationDescriptor; |
| 156 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 158 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 159 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 160 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 161 | class HeapObject; |
| 162 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 163 | class Object; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 164 | template<typename T> class CustomArguments; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 165 | class PropertyCallbackArguments; |
| 166 | class FunctionCallbackArguments; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 167 | } |
| 168 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 170 | /** |
| 171 | * General purpose unique identifier. |
| 172 | */ |
| 173 | class UniqueId { |
| 174 | public: |
| 175 | explicit UniqueId(intptr_t data) |
| 176 | : data_(data) {} |
| 177 | |
| 178 | bool operator==(const UniqueId& other) const { |
| 179 | return data_ == other.data_; |
| 180 | } |
| 181 | |
| 182 | bool operator!=(const UniqueId& other) const { |
| 183 | return data_ != other.data_; |
| 184 | } |
| 185 | |
| 186 | bool operator<(const UniqueId& other) const { |
| 187 | return data_ < other.data_; |
| 188 | } |
| 189 | |
| 190 | private: |
| 191 | intptr_t data_; |
| 192 | }; |
| 193 | |
| 194 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 195 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | |
| 197 | |
| 198 | /** |
| 199 | * A weak reference callback function. |
| 200 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 201 | * This callback should either explicitly invoke Dispose on |object| if |
| 202 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 203 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | * \param object the weak global object to be reclaimed by the garbage collector |
| 205 | * \param parameter the value passed in when making the weak global object |
| 206 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 207 | template<typename T, typename P> |
| 208 | class WeakReferenceCallbacks { |
| 209 | public: |
| 210 | typedef void (*Revivable)(Isolate* isolate, |
| 211 | Persistent<T>* object, |
| 212 | P* parameter); |
| 213 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 215 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 217 | #define TYPE_CHECK(T, S) \ |
| 218 | while (false) { \ |
| 219 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 220 | } |
| 221 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | /** |
| 224 | * An object reference managed by the v8 garbage collector. |
| 225 | * |
| 226 | * All objects returned from v8 have to be tracked by the garbage |
| 227 | * collector so that it knows that the objects are still alive. Also, |
| 228 | * because the garbage collector may move objects, it is unsafe to |
| 229 | * point directly to an object. Instead, all objects are stored in |
| 230 | * handles which are known by the garbage collector and updated |
| 231 | * whenever an object moves. Handles should always be passed by value |
| 232 | * (except in cases like out-parameters) and they should never be |
| 233 | * allocated on the heap. |
| 234 | * |
| 235 | * There are two types of handles: local and persistent handles. |
| 236 | * Local handles are light-weight and transient and typically used in |
| 237 | * local operations. They are managed by HandleScopes. Persistent |
| 238 | * handles can be used when storing objects across several independent |
| 239 | * operations and have to be explicitly deallocated when they're no |
| 240 | * longer used. |
| 241 | * |
| 242 | * It is safe to extract the object stored in the handle by |
| 243 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 244 | * 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] | 245 | * behind the scenes and the same rules apply to these values as to |
| 246 | * their handles. |
| 247 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 248 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | /** |
| 251 | * Creates an empty handle. |
| 252 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 253 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 255 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | /** |
| 257 | * Creates a new handle for the specified value. |
| 258 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 259 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 260 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | |
| 262 | /** |
| 263 | * Creates a handle for the contents of the specified handle. This |
| 264 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 265 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 267 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | * between compatible handles, for instance assigning a |
| 269 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 270 | * because String is a subclass of Value. |
| 271 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 272 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 273 | : val_(reinterpret_cast<T*>(*that)) { |
| 274 | /** |
| 275 | * This check fails when trying to convert between incompatible |
| 276 | * handles. For example, converting from a Handle<String> to a |
| 277 | * Handle<Number>. |
| 278 | */ |
| 279 | TYPE_CHECK(T, S); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Returns true if the handle is empty. |
| 284 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 285 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | /** |
| 288 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 289 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 290 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 291 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 292 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 293 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 294 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * Checks whether two handles are the same. |
| 298 | * Returns true if both are empty, or if the objects |
| 299 | * to which they refer are identical. |
| 300 | * The handles' references are not checked. |
| 301 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 302 | 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] | 303 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 304 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | if (a == 0) return b == 0; |
| 306 | if (b == 0) return false; |
| 307 | return *a == *b; |
| 308 | } |
| 309 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 310 | #ifndef V8_USE_UNSAFE_HANDLES |
| 311 | template <class S> V8_INLINE( |
| 312 | bool operator==(const Persistent<S>& that) const) { |
| 313 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 314 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 315 | if (a == 0) return b == 0; |
| 316 | if (b == 0) return false; |
| 317 | return *a == *b; |
| 318 | } |
| 319 | #endif |
| 320 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | /** |
| 322 | * Checks whether two handles are different. |
| 323 | * Returns true if only one of the handles is empty, or if |
| 324 | * the objects to which they refer are different. |
| 325 | * The handles' references are not checked. |
| 326 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 327 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | return !operator==(that); |
| 329 | } |
| 330 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 331 | 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] | 332 | #ifdef V8_ENABLE_CHECKS |
| 333 | // If we're going to perform the type check then we have to check |
| 334 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 335 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 336 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | return Handle<T>(T::Cast(*that)); |
| 338 | } |
| 339 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 340 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 341 | return Handle<S>::Cast(*this); |
| 342 | } |
| 343 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 344 | #ifndef V8_USE_UNSAFE_HANDLES |
| 345 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 346 | return New(isolate, that.val_); |
| 347 | } |
| 348 | // TODO(dcarney): remove before cutover |
| 349 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 350 | return New(isolate, that.val_); |
| 351 | } |
| 352 | |
| 353 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 354 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 356 | #endif |
| 357 | /** |
| 358 | * Creates a new handle for the specified value. |
| 359 | */ |
| 360 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 361 | #endif |
| 362 | |
| 363 | private: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 364 | friend class Utils; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 365 | template<class F> friend class Persistent; |
| 366 | template<class F> friend class Local; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 367 | friend class Arguments; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 368 | template<class F> friend class FunctionCallbackInfo; |
| 369 | template<class F> friend class PropertyCallbackInfo; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 370 | template<class F> friend class internal::CustomArguments; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 371 | friend class AccessorInfo; |
| 372 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 373 | friend Handle<Primitive> Null(Isolate* isolate); |
| 374 | friend Handle<Boolean> True(Isolate* isolate); |
| 375 | friend Handle<Boolean> False(Isolate* isolate); |
| 376 | friend class Context; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 377 | friend class HandleScope; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 378 | |
| 379 | #ifndef V8_USE_UNSAFE_HANDLES |
| 380 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 381 | #endif |
| 382 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | T* val_; |
| 384 | }; |
| 385 | |
| 386 | |
| 387 | /** |
| 388 | * A light-weight stack-allocated object handle. All operations |
| 389 | * that return objects from within v8 return them in local handles. They |
| 390 | * are created within HandleScopes, and all local handles allocated within a |
| 391 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 392 | * is not necessary to explicitly deallocate local handles. |
| 393 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 394 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 395 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 397 | V8_INLINE(Local()); |
| 398 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 399 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 400 | /** |
| 401 | * This check fails when trying to convert between incompatible |
| 402 | * handles. For example, converting from a Handle<String> to a |
| 403 | * Handle<Number>. |
| 404 | */ |
| 405 | TYPE_CHECK(T, S); |
| 406 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 407 | |
| 408 | |
| 409 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 410 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 411 | #endif |
| 412 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 413 | 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] | 414 | #ifdef V8_ENABLE_CHECKS |
| 415 | // If we're going to perform the type check then we have to check |
| 416 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 417 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 418 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | return Local<T>(T::Cast(*that)); |
| 420 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 421 | #ifndef V8_USE_UNSAFE_HANDLES |
| 422 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 423 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 424 | TYPE_CHECK(T, S); |
| 425 | } |
| 426 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 428 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 429 | return Local<S>::Cast(*this); |
| 430 | } |
| 431 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 432 | /** |
| 433 | * Create a local handle for the content of another handle. |
| 434 | * The referee is kept alive by the local handle even when |
| 435 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 436 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 437 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 438 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 439 | #ifndef V8_USE_UNSAFE_HANDLES |
| 440 | // TODO(dcarney): remove before cutover |
| 441 | 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] | 442 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 443 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 444 | |
| 445 | private: |
| 446 | #endif |
| 447 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 448 | #endif |
| 449 | |
| 450 | private: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 451 | friend class Utils; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 452 | template<class F> friend class Persistent; |
| 453 | template<class F> friend class Handle; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 454 | friend class Arguments; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 455 | template<class F> friend class FunctionCallbackInfo; |
| 456 | template<class F> friend class PropertyCallbackInfo; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 457 | friend class String; |
| 458 | friend class Object; |
| 459 | friend class AccessorInfo; |
| 460 | friend class Context; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 461 | template<class F> friend class internal::CustomArguments; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 462 | friend class HandleScope; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 463 | |
| 464 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 465 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 466 | |
| 467 | /** |
| 468 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 469 | * 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] | 470 | * allocated, a Persistent handle remains valid until it is explicitly |
| 471 | * disposed. |
| 472 | * |
| 473 | * A persistent handle contains a reference to a storage cell within |
| 474 | * the v8 engine which holds an object value and which is updated by |
| 475 | * the garbage collector whenever the object is moved. A new storage |
| 476 | * cell can be created using Persistent::New and existing handles can |
| 477 | * be disposed using Persistent::Dispose. Since persistent handles |
| 478 | * are passed by value you may have many persistent handle objects |
| 479 | * that point to the same storage cell. For instance, if you pass a |
| 480 | * persistent handle as an argument to a function you will not get two |
| 481 | * different storage cells but rather two references to the same |
| 482 | * storage cell. |
| 483 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 484 | template <class T> class Persistent // NOLINT |
| 485 | #ifdef V8_USE_UNSAFE_HANDLES |
| 486 | : public Handle<T> { |
| 487 | #else |
| 488 | { // NOLINT |
| 489 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 491 | #ifndef V8_USE_UNSAFE_HANDLES |
| 492 | V8_INLINE(Persistent()) : val_(0) { } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 493 | // TODO(dcarney): add this back before cutover. |
| 494 | // V8_INLINE(~Persistent()) { |
| 495 | // Dispose(); |
| 496 | // } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 497 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 498 | // TODO(dcarney): remove somehow before cutover |
| 499 | // The handle should either be 0, or a pointer to a live cell. |
| 500 | V8_INLINE(void Clear()) { val_ = 0; } |
| 501 | |
| 502 | /** |
| 503 | * A constructor that creates a new global cell pointing to that. In contrast |
| 504 | * to the copy constructor, this creates a new persistent handle which needs |
| 505 | * to be separately disposed. |
| 506 | */ |
| 507 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 508 | : val_(New(isolate, *that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 509 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 510 | template <class S> V8_INLINE(Persistent(Isolate* isolate, |
| 511 | Persistent<S>& that)) // NOLINT |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 512 | : val_(New(isolate, *that)) { } |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 513 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 514 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | /** |
| 516 | * Creates an empty persistent handle that doesn't point to any |
| 517 | * storage cell. |
| 518 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 519 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | |
| 521 | /** |
| 522 | * Creates a persistent handle for the same storage cell as the |
| 523 | * specified handle. This constructor allows you to pass persistent |
| 524 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 525 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 527 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | * between compatible persistent handles, for instance assigning a |
| 529 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 530 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 532 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 534 | /** |
| 535 | * This check fails when trying to convert between incompatible |
| 536 | * handles. For example, converting from a Handle<String> to a |
| 537 | * Handle<Number>. |
| 538 | */ |
| 539 | TYPE_CHECK(T, S); |
| 540 | } |
| 541 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 542 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 544 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 545 | * A constructor that creates a new global cell pointing to that. In contrast |
| 546 | * to the copy constructor, this creates a new persistent handle which needs |
| 547 | * to be separately disposed. |
| 548 | */ |
| 549 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 550 | : Handle<T>(New(isolate, that)) { } |
| 551 | |
| 552 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 553 | * "Casts" a plain handle which is known to be a persistent handle |
| 554 | * to a persistent handle. |
| 555 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 556 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | : Handle<T>(*that) { } |
| 558 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 559 | #endif |
| 560 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 561 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 562 | 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] | 563 | #ifdef V8_ENABLE_CHECKS |
| 564 | // If we're going to perform the type check then we have to check |
| 565 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 567 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | return Persistent<T>(T::Cast(*that)); |
| 569 | } |
| 570 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 571 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 572 | return Persistent<S>::Cast(*this); |
| 573 | } |
| 574 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 575 | #else |
| 576 | template <class S> |
| 577 | V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT |
| 578 | #ifdef V8_ENABLE_CHECKS |
| 579 | // If we're going to perform the type check then we have to check |
| 580 | // that the handle isn't empty before doing the checked cast. |
| 581 | if (!that.IsEmpty()) T::Cast(*that); |
| 582 | #endif |
| 583 | return reinterpret_cast<Persistent<T>&>(that); |
| 584 | } |
| 585 | |
| 586 | template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| 587 | return Persistent<S>::Cast(*this); |
| 588 | } |
| 589 | #endif |
| 590 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 591 | #ifdef V8_USE_UNSAFE_HANDLES |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 592 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 593 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 594 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 595 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 596 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 597 | #ifndef V8_USE_UNSAFE_HANDLES |
| 598 | template <class S> V8_INLINE( |
| 599 | bool operator==(const Persistent<S>& that) const) { |
| 600 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 601 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 602 | if (a == 0) return b == 0; |
| 603 | if (b == 0) return false; |
| 604 | return *a == *b; |
| 605 | } |
| 606 | |
| 607 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 608 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 609 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 610 | if (a == 0) return b == 0; |
| 611 | if (b == 0) return false; |
| 612 | return *a == *b; |
| 613 | } |
| 614 | #endif |
| 615 | |
| 616 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 617 | |
| 618 | /** |
| 619 | * Releases the storage cell referenced by this persistent handle. |
| 620 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 621 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | * cell remain and IsEmpty will still return false. |
| 623 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 624 | // TODO(dcarney): deprecate |
| 625 | V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 626 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 627 | /** |
| 628 | * Make the reference to this object weak. When only weak handles |
| 629 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 630 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 631 | * it the object reference and the given parameters. |
| 632 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 633 | template<typename S, typename P> |
| 634 | V8_INLINE(void MakeWeak( |
| 635 | P* parameters, |
| 636 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 637 | |
| 638 | template<typename P> |
| 639 | V8_INLINE(void MakeWeak( |
| 640 | P* parameters, |
| 641 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| 642 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 643 | template<typename S, typename P> |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 644 | V8_DEPRECATED(void MakeWeak( |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 645 | Isolate* isolate, |
| 646 | P* parameters, |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 647 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 648 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 649 | template<typename P> |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 650 | V8_DEPRECATED(void MakeWeak( |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 651 | Isolate* isolate, |
| 652 | P* parameters, |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 653 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 654 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 655 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 657 | // TODO(dcarney): deprecate |
| 658 | V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | |
| 660 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 661 | * Marks the reference to this object independent. Garbage collector is free |
| 662 | * to ignore any object groups containing this object. Weak callback for an |
| 663 | * independent handle should not assume that it will be preceded by a global |
| 664 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 665 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 666 | V8_INLINE(void MarkIndependent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 667 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 668 | // TODO(dcarney): deprecate |
| 669 | V8_INLINE(void MarkIndependent(Isolate* isolate)) { MarkIndependent(); } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 670 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 671 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 672 | * Marks the reference to this object partially dependent. Partially dependent |
| 673 | * handles only depend on other partially dependent handles and these |
| 674 | * dependencies are provided through object groups. It provides a way to build |
| 675 | * smaller object groups for young objects that represent only a subset of all |
| 676 | * external dependencies. This mark is automatically cleared after each |
| 677 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 678 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 679 | V8_INLINE(void MarkPartiallyDependent()); |
| 680 | |
| 681 | // TODO(dcarney): deprecate |
| 682 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)) { |
| 683 | MarkPartiallyDependent(); |
| 684 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 685 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 686 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 687 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 688 | // TODO(dcarney): deprecate |
| 689 | V8_INLINE(bool IsIndependent(Isolate* isolate) const) { |
| 690 | return IsIndependent(); |
| 691 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 692 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 693 | /** Checks if the handle holds the only reference to an object. */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 694 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 695 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 696 | // TODO(dcarney): deprecate |
| 697 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const) { return IsNearDeath(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 699 | /** Returns true if the handle's reference is weak. */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 700 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 702 | // TODO(dcarney): deprecate |
| 703 | V8_INLINE(bool IsWeak(Isolate* isolate) const) { return IsWeak(); } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 704 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 705 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 706 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 707 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 708 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 709 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 710 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 711 | // TODO(dcarney): deprecate |
| 712 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)) { |
| 713 | SetWrapperClassId(class_id); |
| 714 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 715 | |
| 716 | /** |
| 717 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 718 | * was previously assigned. |
| 719 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 720 | V8_INLINE(uint16_t WrapperClassId() const); |
| 721 | |
| 722 | // TODO(dcarney): deprecate |
| 723 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { |
| 724 | return WrapperClassId(); |
| 725 | } |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 726 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 727 | /** |
| 728 | * Disposes the current contents of the handle and replaces it. |
| 729 | */ |
| 730 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 731 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 732 | #ifndef V8_USE_UNSAFE_HANDLES |
| 733 | V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); |
| 734 | #endif |
| 735 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 736 | /** |
| 737 | * Returns the underlying raw pointer and clears the handle. The caller is |
| 738 | * responsible of eventually destroying the underlying object (by creating a |
| 739 | * Persistent handle which points to it and Disposing it). In the future, |
| 740 | * destructing a Persistent will also Dispose it. With this function, the |
| 741 | * embedder can let the Persistent go out of scope without it getting |
| 742 | * disposed. |
| 743 | */ |
| 744 | V8_INLINE(T* ClearAndLeak()); |
| 745 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 746 | #ifndef V8_USE_UNSAFE_HANDLES |
| 747 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 749 | // TODO(dcarney): make unlinkable before cutover |
| 750 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 751 | // TODO(dcarney): make unlinkable before cutover |
| 752 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 753 | this->val_ = that.val_; |
| 754 | return *this; |
| 755 | } |
| 756 | |
| 757 | public: |
| 758 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 759 | |
| 760 | private: |
| 761 | #endif |
| 762 | // TODO(dcarney): remove before cutover |
| 763 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 764 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 765 | // TODO(dcarney): remove before cutover |
| 766 | V8_INLINE(T* operator*() const) { return val_; } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 767 | |
| 768 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 769 | // TODO(dcarney): remove before cutover |
| 770 | V8_INLINE(T* operator->() const) { return val_; } |
| 771 | public: |
| 772 | #endif |
| 773 | |
| 774 | private: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 775 | friend class Utils; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 776 | template<class F> friend class Handle; |
| 777 | template<class F> friend class Local; |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 778 | template<class F> friend class Persistent; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 779 | template<class F> friend class ReturnValue; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 780 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 781 | V8_INLINE(static T* New(Isolate* isolate, T* that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 782 | |
| 783 | #ifndef V8_USE_UNSAFE_HANDLES |
| 784 | T* val_; |
| 785 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 786 | }; |
| 787 | |
| 788 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 789 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 790 | * A stack-allocated class that governs a number of local handles. |
| 791 | * After a handle scope has been created, all local handles will be |
| 792 | * allocated within that handle scope until either the handle scope is |
| 793 | * deleted or another handle scope is created. If there is already a |
| 794 | * 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] | 795 | * 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] | 796 | * new handles will again be allocated in the original handle scope. |
| 797 | * |
| 798 | * After the handle scope of a local handle has been deleted the |
| 799 | * garbage collector will no longer track the object stored in the |
| 800 | * handle and may deallocate it. The behavior of accessing a handle |
| 801 | * for which the handle scope has been deleted is undefined. |
| 802 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 803 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 805 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 806 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 808 | HandleScope(Isolate* isolate); |
| 809 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 810 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 811 | |
| 812 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 813 | * Closes the handle scope and returns the value as a handle in the |
| 814 | * previous scope, which is the new current scope after the call. |
| 815 | */ |
| 816 | template <class T> Local<T> Close(Handle<T> value); |
| 817 | |
| 818 | /** |
| 819 | * Counts the number of allocated handles. |
| 820 | */ |
| 821 | static int NumberOfHandles(); |
| 822 | |
| 823 | /** |
| 824 | * Creates a new handle with the given value. |
| 825 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 826 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 827 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 828 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 829 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 830 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
| 832 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 833 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 834 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | HandleScope(const HandleScope&); |
| 836 | void operator=(const HandleScope&); |
| 837 | void* operator new(size_t size); |
| 838 | void operator delete(void*, size_t); |
| 839 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 840 | // This Data class is accessible internally as HandleScopeData through a |
| 841 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 842 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 844 | internal::Object** next; |
| 845 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 846 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 847 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 848 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 849 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | } |
| 851 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 852 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 853 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 854 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 856 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 857 | internal::Object** prev_next_; |
| 858 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 859 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 860 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 861 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 862 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 863 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 865 | friend class ImplementationUtilities; |
| 866 | }; |
| 867 | |
| 868 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 869 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | |
| 871 | |
| 872 | /** |
| 873 | * The superclass of values and API object templates. |
| 874 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 875 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 876 | private: |
| 877 | Data(); |
| 878 | }; |
| 879 | |
| 880 | |
| 881 | /** |
| 882 | * Pre-compilation data that can be associated with a script. This |
| 883 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 884 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 885 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 887 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | public: |
| 889 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 890 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 891 | /** |
| 892 | * Pre-compiles the specified script (context-independent). |
| 893 | * |
| 894 | * \param input Pointer to UTF-8 script source code. |
| 895 | * \param length Length of UTF-8 script source code. |
| 896 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 897 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 898 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 899 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 900 | * Pre-compiles the specified script (context-independent). |
| 901 | * |
| 902 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 903 | * without using Lockers. |
| 904 | * |
| 905 | * \param source Script source code. |
| 906 | */ |
| 907 | static ScriptData* PreCompile(Handle<String> source); |
| 908 | |
| 909 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 910 | * Load previous pre-compilation data. |
| 911 | * |
| 912 | * \param data Pointer to data returned by a call to Data() of a previous |
| 913 | * ScriptData. Ownership is not transferred. |
| 914 | * \param length Length of data. |
| 915 | */ |
| 916 | static ScriptData* New(const char* data, int length); |
| 917 | |
| 918 | /** |
| 919 | * Returns the length of Data(). |
| 920 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 922 | |
| 923 | /** |
| 924 | * Returns a serialized representation of this ScriptData that can later be |
| 925 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 926 | */ |
| 927 | virtual const char* Data() = 0; |
| 928 | |
| 929 | /** |
| 930 | * Returns true if the source code could not be parsed. |
| 931 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 932 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 933 | }; |
| 934 | |
| 935 | |
| 936 | /** |
| 937 | * The origin, within a file, of a script. |
| 938 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 939 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 941 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 942 | Handle<Value> resource_name, |
| 943 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 944 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 945 | : resource_name_(resource_name), |
| 946 | resource_line_offset_(resource_line_offset), |
| 947 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 948 | V8_INLINE(Handle<Value> ResourceName() const); |
| 949 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 950 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 951 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 952 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 953 | Handle<Integer> resource_line_offset_; |
| 954 | Handle<Integer> resource_column_offset_; |
| 955 | }; |
| 956 | |
| 957 | |
| 958 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 959 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 960 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 961 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 962 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 963 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 964 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 965 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 966 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 967 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 968 | * when New() returns |
| 969 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 970 | * using pre_data speeds compilation if it's done multiple times. |
| 971 | * Owned by caller, no references are kept when New() returns. |
| 972 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 973 | * 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] | 974 | * available to compile event handlers. |
| 975 | * \return Compiled script object (context independent; when run it |
| 976 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 977 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 978 | static Local<Script> New(Handle<String> source, |
| 979 | ScriptOrigin* origin = NULL, |
| 980 | ScriptData* pre_data = NULL, |
| 981 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 982 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 983 | /** |
| 984 | * Compiles the specified script using the specified file name |
| 985 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 986 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 987 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 988 | * \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] | 989 | * as the script's origin. |
| 990 | * \return Compiled script object (context independent; when run it |
| 991 | * will use the currently entered context). |
| 992 | */ |
| 993 | static Local<Script> New(Handle<String> source, |
| 994 | Handle<Value> file_name); |
| 995 | |
| 996 | /** |
| 997 | * Compiles the specified script (bound to current context). |
| 998 | * |
| 999 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1000 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1001 | * when Compile() returns |
| 1002 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 1003 | * using pre_data speeds compilation if it's done multiple times. |
| 1004 | * Owned by caller, no references are kept when Compile() returns. |
| 1005 | * \param script_data Arbitrary data associated with script. Using |
| 1006 | * this has same effect as calling SetData(), but makes data available |
| 1007 | * earlier (i.e. to compile event handlers). |
| 1008 | * \return Compiled script object, bound to the context that was active |
| 1009 | * when this function was called. When run it will always use this |
| 1010 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1011 | */ |
| 1012 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1013 | ScriptOrigin* origin = NULL, |
| 1014 | ScriptData* pre_data = NULL, |
| 1015 | Handle<String> script_data = Handle<String>()); |
| 1016 | |
| 1017 | /** |
| 1018 | * Compiles the specified script using the specified file name |
| 1019 | * object (typically a string) as the script's origin. |
| 1020 | * |
| 1021 | * \param source Script source code. |
| 1022 | * \param file_name File name to use as script's origin |
| 1023 | * \param script_data Arbitrary data associated with script. Using |
| 1024 | * this has same effect as calling SetData(), but makes data available |
| 1025 | * earlier (i.e. to compile event handlers). |
| 1026 | * \return Compiled script object, bound to the context that was active |
| 1027 | * when this function was called. When run it will always use this |
| 1028 | * context. |
| 1029 | */ |
| 1030 | static Local<Script> Compile(Handle<String> source, |
| 1031 | Handle<Value> file_name, |
| 1032 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1033 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1034 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1035 | * Runs the script returning the resulting value. If the script is |
| 1036 | * context independent (created using ::New) it will be run in the |
| 1037 | * currently entered context. If it is context specific (created |
| 1038 | * using ::Compile) it will be run in the context in which it was |
| 1039 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1040 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1041 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1042 | |
| 1043 | /** |
| 1044 | * Returns the script id value. |
| 1045 | */ |
| 1046 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1047 | |
| 1048 | /** |
| 1049 | * Associate an additional data object with the script. This is mainly used |
| 1050 | * with the debugger as this data object is only available through the |
| 1051 | * debugger API. |
| 1052 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1053 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1054 | |
| 1055 | /** |
| 1056 | * Returns the name value of one Script. |
| 1057 | */ |
| 1058 | Handle<Value> GetScriptName(); |
| 1059 | |
| 1060 | /** |
| 1061 | * Returns zero based line number of the code_pos location in the script. |
| 1062 | * -1 will be returned if no information available. |
| 1063 | */ |
| 1064 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1065 | }; |
| 1066 | |
| 1067 | |
| 1068 | /** |
| 1069 | * An error message. |
| 1070 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1071 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1072 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1073 | Local<String> Get() const; |
| 1074 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1076 | /** |
| 1077 | * Returns the resource name for the script from where the function causing |
| 1078 | * the error originates. |
| 1079 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1080 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1081 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1082 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1083 | * Returns the resource data for the script from where the function causing |
| 1084 | * the error originates. |
| 1085 | */ |
| 1086 | Handle<Value> GetScriptData() const; |
| 1087 | |
| 1088 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1089 | * Exception stack trace. By default stack traces are not captured for |
| 1090 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1091 | * to change this option. |
| 1092 | */ |
| 1093 | Handle<StackTrace> GetStackTrace() const; |
| 1094 | |
| 1095 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1096 | * Returns the number, 1-based, of the line where the error occurred. |
| 1097 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1098 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1099 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1100 | /** |
| 1101 | * Returns the index within the script of the first character where |
| 1102 | * the error occurred. |
| 1103 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1104 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1105 | |
| 1106 | /** |
| 1107 | * Returns the index within the script of the last character where |
| 1108 | * the error occurred. |
| 1109 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1110 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1111 | |
| 1112 | /** |
| 1113 | * Returns the index within the line of the first character where |
| 1114 | * the error occurred. |
| 1115 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1116 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1117 | |
| 1118 | /** |
| 1119 | * Returns the index within the line of the last character where |
| 1120 | * the error occurred. |
| 1121 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1122 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1123 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1124 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1125 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1126 | |
| 1127 | static const int kNoLineNumberInfo = 0; |
| 1128 | static const int kNoColumnInfo = 0; |
| 1129 | }; |
| 1130 | |
| 1131 | |
| 1132 | /** |
| 1133 | * Representation of a JavaScript stack trace. The information collected is a |
| 1134 | * snapshot of the execution stack and the information remains valid after |
| 1135 | * execution continues. |
| 1136 | */ |
| 1137 | class V8EXPORT StackTrace { |
| 1138 | public: |
| 1139 | /** |
| 1140 | * Flags that determine what information is placed captured for each |
| 1141 | * StackFrame when grabbing the current stack trace. |
| 1142 | */ |
| 1143 | enum StackTraceOptions { |
| 1144 | kLineNumber = 1, |
| 1145 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1146 | kScriptName = 1 << 2, |
| 1147 | kFunctionName = 1 << 3, |
| 1148 | kIsEval = 1 << 4, |
| 1149 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1150 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1151 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1152 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1153 | }; |
| 1154 | |
| 1155 | /** |
| 1156 | * Returns a StackFrame at a particular index. |
| 1157 | */ |
| 1158 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1159 | |
| 1160 | /** |
| 1161 | * Returns the number of StackFrames. |
| 1162 | */ |
| 1163 | int GetFrameCount() const; |
| 1164 | |
| 1165 | /** |
| 1166 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1167 | */ |
| 1168 | Local<Array> AsArray(); |
| 1169 | |
| 1170 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1171 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1172 | * |
| 1173 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1174 | * \param options Enumerates the set of things we will capture for each |
| 1175 | * StackFrame. |
| 1176 | */ |
| 1177 | static Local<StackTrace> CurrentStackTrace( |
| 1178 | int frame_limit, |
| 1179 | StackTraceOptions options = kOverview); |
| 1180 | }; |
| 1181 | |
| 1182 | |
| 1183 | /** |
| 1184 | * A single JavaScript stack frame. |
| 1185 | */ |
| 1186 | class V8EXPORT StackFrame { |
| 1187 | public: |
| 1188 | /** |
| 1189 | * Returns the number, 1-based, of the line for the associate function call. |
| 1190 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1191 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1192 | * when capturing the StackTrace. |
| 1193 | */ |
| 1194 | int GetLineNumber() const; |
| 1195 | |
| 1196 | /** |
| 1197 | * Returns the 1-based column offset on the line for the associated function |
| 1198 | * call. |
| 1199 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1200 | * the column number, or if kColumnOffset was not passed as an option when |
| 1201 | * capturing the StackTrace. |
| 1202 | */ |
| 1203 | int GetColumn() const; |
| 1204 | |
| 1205 | /** |
| 1206 | * Returns the name of the resource that contains the script for the |
| 1207 | * function for this StackFrame. |
| 1208 | */ |
| 1209 | Local<String> GetScriptName() const; |
| 1210 | |
| 1211 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1212 | * Returns the name of the resource that contains the script for the |
| 1213 | * function for this StackFrame or sourceURL value if the script name |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1214 | * is undefined and its source ends with //# sourceURL=... string or |
| 1215 | * deprecated //@ sourceURL=... string. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1216 | */ |
| 1217 | Local<String> GetScriptNameOrSourceURL() const; |
| 1218 | |
| 1219 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1220 | * Returns the name of the function associated with this stack frame. |
| 1221 | */ |
| 1222 | Local<String> GetFunctionName() const; |
| 1223 | |
| 1224 | /** |
| 1225 | * Returns whether or not the associated function is compiled via a call to |
| 1226 | * eval(). |
| 1227 | */ |
| 1228 | bool IsEval() const; |
| 1229 | |
| 1230 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1231 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1232 | * constructor via "new". |
| 1233 | */ |
| 1234 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | }; |
| 1236 | |
| 1237 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1238 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | |
| 1240 | |
| 1241 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1242 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1243 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1244 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | /** |
| 1247 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1248 | * 4.3.10. |
| 1249 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1250 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | |
| 1252 | /** |
| 1253 | * Returns true if this value is the null value. See ECMA-262 |
| 1254 | * 4.3.11. |
| 1255 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1256 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1257 | |
| 1258 | /** |
| 1259 | * Returns true if this value is true. |
| 1260 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1261 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1262 | |
| 1263 | /** |
| 1264 | * Returns true if this value is false. |
| 1265 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1266 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | |
| 1268 | /** |
| 1269 | * Returns true if this value is an instance of the String type. |
| 1270 | * See ECMA-262 8.4. |
| 1271 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1272 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1273 | |
| 1274 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1275 | * Returns true if this value is a symbol. |
| 1276 | * This is an experimental feature. |
| 1277 | */ |
| 1278 | bool IsSymbol() const; |
| 1279 | |
| 1280 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | * Returns true if this value is a function. |
| 1282 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1283 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | |
| 1285 | /** |
| 1286 | * Returns true if this value is an array. |
| 1287 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1288 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1290 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1291 | * Returns true if this value is an object. |
| 1292 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1293 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1294 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1295 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | * Returns true if this value is boolean. |
| 1297 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1298 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1299 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1300 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | * Returns true if this value is a number. |
| 1302 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1303 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1305 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | * Returns true if this value is external. |
| 1307 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1308 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1310 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1311 | * Returns true if this value is a 32-bit signed integer. |
| 1312 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1313 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1315 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1316 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1317 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1318 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1319 | |
| 1320 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1321 | * Returns true if this value is a Date. |
| 1322 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1323 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1324 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1325 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1326 | * Returns true if this value is a Boolean object. |
| 1327 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1328 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1329 | |
| 1330 | /** |
| 1331 | * Returns true if this value is a Number object. |
| 1332 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1333 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1334 | |
| 1335 | /** |
| 1336 | * Returns true if this value is a String object. |
| 1337 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1338 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1339 | |
| 1340 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1341 | * Returns true if this value is a Symbol object. |
| 1342 | * This is an experimental feature. |
| 1343 | */ |
| 1344 | bool IsSymbolObject() const; |
| 1345 | |
| 1346 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1347 | * Returns true if this value is a NativeError. |
| 1348 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1349 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1350 | |
| 1351 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1352 | * Returns true if this value is a RegExp. |
| 1353 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1354 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1355 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1356 | |
| 1357 | /** |
| 1358 | * Returns true if this value is an ArrayBuffer. |
| 1359 | * This is an experimental feature. |
| 1360 | */ |
| 1361 | bool IsArrayBuffer() const; |
| 1362 | |
| 1363 | /** |
| 1364 | * Returns true if this value is one of TypedArrays. |
| 1365 | * This is an experimental feature. |
| 1366 | */ |
| 1367 | bool IsTypedArray() const; |
| 1368 | |
| 1369 | /** |
| 1370 | * Returns true if this value is an Uint8Array. |
| 1371 | * This is an experimental feature. |
| 1372 | */ |
| 1373 | bool IsUint8Array() const; |
| 1374 | |
| 1375 | /** |
| 1376 | * Returns true if this value is an Uint8ClampedArray. |
| 1377 | * This is an experimental feature. |
| 1378 | */ |
| 1379 | bool IsUint8ClampedArray() const; |
| 1380 | |
| 1381 | /** |
| 1382 | * Returns true if this value is an Int8Array. |
| 1383 | * This is an experimental feature. |
| 1384 | */ |
| 1385 | bool IsInt8Array() const; |
| 1386 | |
| 1387 | /** |
| 1388 | * Returns true if this value is an Uint16Array. |
| 1389 | * This is an experimental feature. |
| 1390 | */ |
| 1391 | bool IsUint16Array() const; |
| 1392 | |
| 1393 | /** |
| 1394 | * Returns true if this value is an Int16Array. |
| 1395 | * This is an experimental feature. |
| 1396 | */ |
| 1397 | bool IsInt16Array() const; |
| 1398 | |
| 1399 | /** |
| 1400 | * Returns true if this value is an Uint32Array. |
| 1401 | * This is an experimental feature. |
| 1402 | */ |
| 1403 | bool IsUint32Array() const; |
| 1404 | |
| 1405 | /** |
| 1406 | * Returns true if this value is an Int32Array. |
| 1407 | * This is an experimental feature. |
| 1408 | */ |
| 1409 | bool IsInt32Array() const; |
| 1410 | |
| 1411 | /** |
| 1412 | * Returns true if this value is a Float32Array. |
| 1413 | * This is an experimental feature. |
| 1414 | */ |
| 1415 | bool IsFloat32Array() const; |
| 1416 | |
| 1417 | /** |
| 1418 | * Returns true if this value is a Float64Array. |
| 1419 | * This is an experimental feature. |
| 1420 | */ |
| 1421 | bool IsFloat64Array() const; |
| 1422 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1423 | Local<Boolean> ToBoolean() const; |
| 1424 | Local<Number> ToNumber() const; |
| 1425 | Local<String> ToString() const; |
| 1426 | Local<String> ToDetailString() const; |
| 1427 | Local<Object> ToObject() const; |
| 1428 | Local<Integer> ToInteger() const; |
| 1429 | Local<Uint32> ToUint32() const; |
| 1430 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | |
| 1432 | /** |
| 1433 | * Attempts to convert a string to an array index. |
| 1434 | * Returns an empty handle if the conversion fails. |
| 1435 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1436 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1438 | bool BooleanValue() const; |
| 1439 | double NumberValue() const; |
| 1440 | int64_t IntegerValue() const; |
| 1441 | uint32_t Uint32Value() const; |
| 1442 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | |
| 1444 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1445 | bool Equals(Handle<Value> that) const; |
| 1446 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1447 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1448 | template <class T> V8_INLINE(static Value* Cast(T* value)); |
| 1449 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1450 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1451 | V8_INLINE(bool QuickIsUndefined() const); |
| 1452 | V8_INLINE(bool QuickIsNull() const); |
| 1453 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1454 | bool FullIsUndefined() const; |
| 1455 | bool FullIsNull() const; |
| 1456 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1457 | }; |
| 1458 | |
| 1459 | |
| 1460 | /** |
| 1461 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1462 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1463 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1464 | |
| 1465 | |
| 1466 | /** |
| 1467 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1468 | * or false value. |
| 1469 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1470 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1471 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1472 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1473 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1474 | }; |
| 1475 | |
| 1476 | |
| 1477 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1478 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1480 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1482 | enum Encoding { |
| 1483 | UNKNOWN_ENCODING = 0x1, |
| 1484 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1485 | ASCII_ENCODING = 0x4, |
| 1486 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1487 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1488 | /** |
| 1489 | * Returns the number of characters in this string. |
| 1490 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1491 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1492 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1493 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1494 | * Returns the number of bytes in the UTF-8 encoded |
| 1495 | * representation of this string. |
| 1496 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1497 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1498 | |
| 1499 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1500 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1501 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1502 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1503 | |
| 1504 | /** |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 1505 | * Returns whether this string is known to contain only one byte data. |
| 1506 | * Does not read the string. |
| 1507 | * False negatives are possible. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1508 | */ |
| 1509 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1510 | |
| 1511 | /** |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 1512 | * Returns whether this string contain only one byte data. |
| 1513 | * Will read the entire string in some cases. |
| 1514 | */ |
| 1515 | bool ContainsOnlyOneByte() const; |
| 1516 | |
| 1517 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1518 | * Write the contents of the string to an external buffer. |
| 1519 | * If no arguments are given, expects the buffer to be large |
| 1520 | * enough to hold the entire string and NULL terminator. Copies |
| 1521 | * the contents of the string and the NULL terminator into the |
| 1522 | * buffer. |
| 1523 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1524 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1525 | * before the end of the buffer. |
| 1526 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1527 | * Copies up to length characters into the output buffer. |
| 1528 | * Only null-terminates if there is enough space in the buffer. |
| 1529 | * |
| 1530 | * \param buffer The buffer into which the string will be copied. |
| 1531 | * \param start The starting position within the string at which |
| 1532 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1533 | * \param length The number of characters to copy from the string. For |
| 1534 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1535 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1536 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1537 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1538 | * \return The number of characters copied to the buffer excluding the null |
| 1539 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1540 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1541 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1542 | enum WriteOptions { |
| 1543 | NO_OPTIONS = 0, |
| 1544 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1545 | NO_NULL_TERMINATION = 2, |
| 1546 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1547 | }; |
| 1548 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1549 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1550 | int Write(uint16_t* buffer, |
| 1551 | int start = 0, |
| 1552 | int length = -1, |
| 1553 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1554 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1555 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1556 | int start = 0, |
| 1557 | int length = -1, |
| 1558 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1559 | // One byte characters. |
| 1560 | int WriteOneByte(uint8_t* buffer, |
| 1561 | int start = 0, |
| 1562 | int length = -1, |
| 1563 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1564 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1565 | int WriteUtf8(char* buffer, |
| 1566 | int length = -1, |
| 1567 | int* nchars_ref = NULL, |
| 1568 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1569 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1570 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1571 | * A zero length string. |
| 1572 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1573 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1574 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1575 | |
| 1576 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1577 | * Returns true if the string is external |
| 1578 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1579 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1580 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1581 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1582 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1583 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1584 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1585 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1586 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1587 | public: |
| 1588 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1589 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1590 | protected: |
| 1591 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1592 | |
| 1593 | /** |
| 1594 | * Internally V8 will call this Dispose method when the external string |
| 1595 | * resource is no longer needed. The default implementation will use the |
| 1596 | * delete operator. This method can be overridden in subclasses to |
| 1597 | * control how allocated external string resources are disposed. |
| 1598 | */ |
| 1599 | virtual void Dispose() { delete this; } |
| 1600 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1601 | private: |
| 1602 | // Disallow copying and assigning. |
| 1603 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1604 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1605 | |
| 1606 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1607 | }; |
| 1608 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1609 | /** |
| 1610 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1611 | * buffer that resides outside V8's heap. Implement an |
| 1612 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1613 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1614 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1615 | class V8EXPORT ExternalStringResource |
| 1616 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1617 | public: |
| 1618 | /** |
| 1619 | * Override the destructor to manage the life cycle of the underlying |
| 1620 | * buffer. |
| 1621 | */ |
| 1622 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1623 | |
| 1624 | /** |
| 1625 | * The string data from the underlying buffer. |
| 1626 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1627 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1628 | |
| 1629 | /** |
| 1630 | * The length of the string. That is, the number of two-byte characters. |
| 1631 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1632 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1633 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1634 | protected: |
| 1635 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | }; |
| 1637 | |
| 1638 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1639 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1640 | * string buffer that resides outside V8's heap. Implement an |
| 1641 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1642 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1643 | * 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] | 1644 | * UTF-8, which would require special treatment internally in the |
| 1645 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1646 | * 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] | 1647 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1648 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1649 | class V8EXPORT ExternalAsciiStringResource |
| 1650 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1651 | public: |
| 1652 | /** |
| 1653 | * Override the destructor to manage the life cycle of the underlying |
| 1654 | * buffer. |
| 1655 | */ |
| 1656 | virtual ~ExternalAsciiStringResource() {} |
| 1657 | /** The string data from the underlying buffer.*/ |
| 1658 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1659 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | virtual size_t length() const = 0; |
| 1661 | protected: |
| 1662 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1663 | }; |
| 1664 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1665 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1666 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1667 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1668 | * If the string is an external string, return the ExternalStringResourceBase |
| 1669 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1670 | * string is returned in encoding_out. |
| 1671 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1672 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1673 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1674 | |
| 1675 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1676 | * Get the ExternalStringResource for an external string. Returns |
| 1677 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1678 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1679 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | |
| 1681 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1682 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1683 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1684 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1685 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1687 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1689 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1690 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1691 | * 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] | 1692 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1693 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1694 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1695 | 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] | 1696 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1697 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1698 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1699 | 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] | 1700 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1701 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1702 | /** |
| 1703 | * Creates an internalized string (historically called a "symbol", |
| 1704 | * 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] | 1705 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1706 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1707 | |
| 1708 | enum NewStringType { |
| 1709 | kNormalString, kInternalizedString, kUndetectableString |
| 1710 | }; |
| 1711 | |
| 1712 | /** Allocates a new string from UTF-8 data.*/ |
| 1713 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1714 | const char* data, |
| 1715 | NewStringType type = kNormalString, |
| 1716 | int length = -1); |
| 1717 | |
| 1718 | /** Allocates a new string from Latin-1 data.*/ |
| 1719 | static Local<String> NewFromOneByte( |
| 1720 | Isolate* isolate, |
| 1721 | const uint8_t* data, |
| 1722 | NewStringType type = kNormalString, |
| 1723 | int length = -1); |
| 1724 | |
| 1725 | /** Allocates a new string from UTF-16 data.*/ |
| 1726 | static Local<String> NewFromTwoByte( |
| 1727 | Isolate* isolate, |
| 1728 | const uint16_t* data, |
| 1729 | NewStringType type = kNormalString, |
| 1730 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1732 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1733 | * Creates a new string by concatenating the left and the right strings |
| 1734 | * passed in as parameters. |
| 1735 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1736 | 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] | 1737 | |
| 1738 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1739 | * 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] | 1740 | * 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] | 1741 | * resource will be disposed by calling its Dispose method. The caller of |
| 1742 | * this function should not otherwise delete or modify the resource. Neither |
| 1743 | * should the underlying buffer be deallocated or modified except through the |
| 1744 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1745 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1746 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1747 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1748 | /** |
| 1749 | * Associate an external string resource with this string by transforming it |
| 1750 | * in place so that existing references to this string in the JavaScript heap |
| 1751 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1752 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1753 | * 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] | 1754 | * The string is not modified if the operation fails. See NewExternal for |
| 1755 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1756 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1757 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1759 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1760 | * 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] | 1761 | * 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] | 1762 | * resource will be disposed by calling its Dispose method. The caller of |
| 1763 | * this function should not otherwise delete or modify the resource. Neither |
| 1764 | * should the underlying buffer be deallocated or modified except through the |
| 1765 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1766 | */ |
| 1767 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1768 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1769 | /** |
| 1770 | * Associate an external string resource with this string by transforming it |
| 1771 | * in place so that existing references to this string in the JavaScript heap |
| 1772 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1773 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1774 | * 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] | 1775 | * The string is not modified if the operation fails. See NewExternal for |
| 1776 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1777 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1778 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1779 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1780 | /** |
| 1781 | * Returns true if this string can be made external. |
| 1782 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1783 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1784 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1785 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1786 | /** 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] | 1787 | V8_INLINE( |
| 1788 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1789 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1790 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1791 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1792 | V8_INLINE(static Local<String> NewUndetectable( |
| 1793 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1794 | |
| 1795 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1796 | * 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] | 1797 | * 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] | 1798 | * (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] | 1799 | * then the length() method returns 0 and the * operator returns |
| 1800 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1801 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1802 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1803 | public: |
| 1804 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1805 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1806 | char* operator*() { return str_; } |
| 1807 | const char* operator*() const { return str_; } |
| 1808 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1809 | private: |
| 1810 | char* str_; |
| 1811 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1812 | |
| 1813 | // Disallow copying and assigning. |
| 1814 | Utf8Value(const Utf8Value&); |
| 1815 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1816 | }; |
| 1817 | |
| 1818 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1819 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1821 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1822 | * method of the object) then the length() method returns 0 and the * operator |
| 1823 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1824 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1825 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1826 | public: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1827 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1828 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1829 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1830 | char* operator*() { return str_; } |
| 1831 | const char* operator*() const { return str_; } |
| 1832 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1833 | private: |
| 1834 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1835 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1836 | |
| 1837 | // Disallow copying and assigning. |
| 1838 | AsciiValue(const AsciiValue&); |
| 1839 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | }; |
| 1841 | |
| 1842 | /** |
| 1843 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1844 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1845 | * method of the object) then the length() method returns 0 and the * operator |
| 1846 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1847 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1848 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | public: |
| 1850 | explicit Value(Handle<v8::Value> obj); |
| 1851 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1852 | uint16_t* operator*() { return str_; } |
| 1853 | const uint16_t* operator*() const { return str_; } |
| 1854 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1855 | private: |
| 1856 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1857 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1858 | |
| 1859 | // Disallow copying and assigning. |
| 1860 | Value(const Value&); |
| 1861 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1863 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1864 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1865 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1866 | Encoding encoding) const; |
| 1867 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1868 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1869 | }; |
| 1870 | |
| 1871 | |
| 1872 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1873 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1874 | * |
| 1875 | * This is an experimental feature. Use at your own risk. |
| 1876 | */ |
| 1877 | class V8EXPORT Symbol : public Primitive { |
| 1878 | public: |
| 1879 | // Returns the print name string of the symbol, or undefined if none. |
| 1880 | Local<Value> Name() const; |
| 1881 | |
| 1882 | // Create a symbol without a print name. |
| 1883 | static Local<Symbol> New(Isolate* isolate); |
| 1884 | |
| 1885 | // Create a symbol with a print name. |
| 1886 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1887 | |
| 1888 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1889 | private: |
| 1890 | Symbol(); |
| 1891 | static void CheckCast(v8::Value* obj); |
| 1892 | }; |
| 1893 | |
| 1894 | |
| 1895 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1896 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1898 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1900 | double Value() const; |
| 1901 | static Local<Number> New(double value); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1902 | static Local<Number> New(Isolate* isolate, double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1903 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1905 | Number(); |
| 1906 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1907 | }; |
| 1908 | |
| 1909 | |
| 1910 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1911 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1912 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1913 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1914 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1915 | static Local<Integer> New(int32_t value); |
| 1916 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1917 | static Local<Integer> New(int32_t value, Isolate*); |
| 1918 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1919 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1920 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1922 | Integer(); |
| 1923 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | }; |
| 1925 | |
| 1926 | |
| 1927 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1928 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1930 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1931 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1932 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1933 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1934 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1935 | }; |
| 1936 | |
| 1937 | |
| 1938 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1939 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1940 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1941 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1942 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1943 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1944 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1945 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1946 | }; |
| 1947 | |
| 1948 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1949 | enum PropertyAttribute { |
| 1950 | None = 0, |
| 1951 | ReadOnly = 1 << 0, |
| 1952 | DontEnum = 1 << 1, |
| 1953 | DontDelete = 1 << 2 |
| 1954 | }; |
| 1955 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1956 | enum ExternalArrayType { |
| 1957 | kExternalByteArray = 1, |
| 1958 | kExternalUnsignedByteArray, |
| 1959 | kExternalShortArray, |
| 1960 | kExternalUnsignedShortArray, |
| 1961 | kExternalIntArray, |
| 1962 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1963 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1964 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1965 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1966 | }; |
| 1967 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1968 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1969 | * Accessor[Getter|Setter] are used as callback functions when |
| 1970 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1971 | * method SetAccessor. |
| 1972 | */ |
| 1973 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1974 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1975 | typedef void (*AccessorGetterCallback)( |
| 1976 | Local<String> property, |
| 1977 | const PropertyCallbackInfo<Value>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1978 | |
| 1979 | |
| 1980 | typedef void (*AccessorSetter)(Local<String> property, |
| 1981 | Local<Value> value, |
| 1982 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1983 | typedef void (*AccessorSetterCallback)( |
| 1984 | Local<String> property, |
| 1985 | Local<Value> value, |
| 1986 | const PropertyCallbackInfo<void>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1987 | |
| 1988 | |
| 1989 | /** |
| 1990 | * Access control specifications. |
| 1991 | * |
| 1992 | * Some accessors should be accessible across contexts. These |
| 1993 | * accessors have an explicit access control parameter which specifies |
| 1994 | * the kind of cross-context access that should be allowed. |
| 1995 | * |
| 1996 | * Additionally, for security, accessors can prohibit overwriting by |
| 1997 | * accessors defined in JavaScript. For objects that have such |
| 1998 | * accessors either locally or in their prototype chain it is not |
| 1999 | * possible to overwrite the accessor by using __defineGetter__ or |
| 2000 | * __defineSetter__ from JavaScript code. |
| 2001 | */ |
| 2002 | enum AccessControl { |
| 2003 | DEFAULT = 0, |
| 2004 | ALL_CAN_READ = 1, |
| 2005 | ALL_CAN_WRITE = 1 << 1, |
| 2006 | PROHIBITS_OVERWRITING = 1 << 2 |
| 2007 | }; |
| 2008 | |
| 2009 | |
| 2010 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2011 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2012 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2013 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2014 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2015 | bool Set(Handle<Value> key, |
| 2016 | Handle<Value> value, |
| 2017 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2018 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2019 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2020 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2021 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2022 | // overriding accessors or read-only properties. |
| 2023 | // |
| 2024 | // Note that if the object has an interceptor the property will be set |
| 2025 | // locally, but since the interceptor takes precedence the local property |
| 2026 | // will only be returned if the interceptor doesn't return a value. |
| 2027 | // |
| 2028 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2029 | bool ForceSet(Handle<Value> key, |
| 2030 | Handle<Value> value, |
| 2031 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2032 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2033 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2035 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2036 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2037 | /** |
| 2038 | * Gets the property attributes of a property which can be None or |
| 2039 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 2040 | * None when the property doesn't exist. |
| 2041 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2042 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2043 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2044 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2045 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2046 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2047 | |
| 2048 | // Delete a property on this object bypassing interceptors and |
| 2049 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2050 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2051 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2052 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2053 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2054 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2056 | // TODO(dcarney): deprecate |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2057 | bool SetAccessor(Handle<String> name, |
| 2058 | AccessorGetter getter, |
| 2059 | AccessorSetter setter = 0, |
| 2060 | Handle<Value> data = Handle<Value>(), |
| 2061 | AccessControl settings = DEFAULT, |
| 2062 | PropertyAttribute attribute = None); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2063 | bool SetAccessor(Handle<String> name, |
| 2064 | AccessorGetterCallback getter, |
| 2065 | AccessorSetterCallback setter = 0, |
| 2066 | Handle<Value> data = Handle<Value>(), |
| 2067 | AccessControl settings = DEFAULT, |
| 2068 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2069 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2070 | // This function is not yet stable and should not be used at this time. |
| 2071 | bool SetAccessor(Handle<String> name, |
| 2072 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2073 | AccessControl settings = DEFAULT, |
| 2074 | PropertyAttribute attribute = None); |
| 2075 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2077 | * Returns an array containing the names of the enumerable properties |
| 2078 | * of this object, including properties from prototype objects. The |
| 2079 | * array returned by this method contains the same values as would |
| 2080 | * be enumerated by a for-in statement over this object. |
| 2081 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2082 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2083 | |
| 2084 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2085 | * This function has the same functionality as GetPropertyNames but |
| 2086 | * the returned array doesn't contain the names of properties from |
| 2087 | * prototype objects. |
| 2088 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2089 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2090 | |
| 2091 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | * Get the prototype object. This does not skip objects marked to |
| 2093 | * be skipped by __proto__ and it does not consult the security |
| 2094 | * handler. |
| 2095 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2096 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2097 | |
| 2098 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2099 | * Set the prototype object. This does not skip objects marked to |
| 2100 | * be skipped by __proto__ and it does not consult the security |
| 2101 | * handler. |
| 2102 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2103 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2104 | |
| 2105 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2106 | * Finds an instance of the given function template in the prototype |
| 2107 | * chain. |
| 2108 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2109 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2110 | |
| 2111 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2112 | * Call builtin Object.prototype.toString on this object. |
| 2113 | * This is different from Value::ToString() that may call |
| 2114 | * user-defined toString function. This one does not. |
| 2115 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2116 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2117 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2118 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2119 | * Returns the function invoked as a constructor for this object. |
| 2120 | * May be the null value. |
| 2121 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2122 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2123 | |
| 2124 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2125 | * Returns the name of the function invoked as a constructor for this object. |
| 2126 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2127 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2128 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2129 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2130 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2131 | |
| 2132 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2133 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2134 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2135 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2136 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2137 | |
| 2138 | /** |
| 2139 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2140 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2141 | * leads to undefined behavior. |
| 2142 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2143 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2144 | |
| 2145 | /** |
| 2146 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2147 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2148 | * leads to undefined behavior. |
| 2149 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2150 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2151 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2152 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2153 | bool HasOwnProperty(Handle<String> key); |
| 2154 | bool HasRealNamedProperty(Handle<String> key); |
| 2155 | bool HasRealIndexedProperty(uint32_t index); |
| 2156 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2157 | |
| 2158 | /** |
| 2159 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2160 | * This means interceptors in the prototype chain are not called. |
| 2161 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2162 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2163 | |
| 2164 | /** |
| 2165 | * If result.IsEmpty() no real property was located on the object or |
| 2166 | * in the prototype chain. |
| 2167 | * This means interceptors in the prototype chain are not called. |
| 2168 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2169 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2170 | |
| 2171 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2172 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2173 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2174 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2175 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2176 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2177 | /** |
| 2178 | * Turns on access check on the object if the object is an instance of |
| 2179 | * a template that has access check callbacks. If an object has no |
| 2180 | * access check info, the object cannot be accessed by anyone. |
| 2181 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2182 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2183 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2184 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2185 | * Returns the identity hash for this object. The current implementation |
| 2186 | * 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] | 2187 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2188 | * 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] | 2189 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2190 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2191 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2192 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2193 | /** |
| 2194 | * Access hidden properties on JavaScript objects. These properties are |
| 2195 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2196 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2197 | * identity hash) are prefixed with "v8::". |
| 2198 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2199 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2200 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2201 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2202 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2203 | /** |
| 2204 | * Returns true if this is an instance of an api function (one |
| 2205 | * created from a function created from a function template) and has |
| 2206 | * been modified since it was created. Note that this method is |
| 2207 | * conservative and may return true for objects that haven't actually |
| 2208 | * been modified. |
| 2209 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2210 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2211 | |
| 2212 | /** |
| 2213 | * Clone this object with a fast but shallow copy. Values will point |
| 2214 | * to the same values as the original object. |
| 2215 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2216 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2217 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2218 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2219 | * Returns the context in which the object was created. |
| 2220 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2221 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2222 | |
| 2223 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2224 | * Set the backing store of the indexed properties to be managed by the |
| 2225 | * embedding layer. Access to the indexed properties will follow the rules |
| 2226 | * spelled out in CanvasPixelArray. |
| 2227 | * Note: The embedding program still owns the data and needs to ensure that |
| 2228 | * the backing store is preserved while V8 has a reference. |
| 2229 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2230 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2231 | bool HasIndexedPropertiesInPixelData(); |
| 2232 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2233 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2234 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2235 | /** |
| 2236 | * Set the backing store of the indexed properties to be managed by the |
| 2237 | * embedding layer. Access to the indexed properties will follow the rules |
| 2238 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2239 | * Note: The embedding program still owns the data and needs to ensure that |
| 2240 | * the backing store is preserved while V8 has a reference. |
| 2241 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2242 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2243 | ExternalArrayType array_type, |
| 2244 | int number_of_elements); |
| 2245 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2246 | void* GetIndexedPropertiesExternalArrayData(); |
| 2247 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2248 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2249 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2250 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2251 | * Checks whether a callback is set by the |
| 2252 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2253 | * When an Object is callable this method returns true. |
| 2254 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2255 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2256 | |
| 2257 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2258 | * 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] | 2259 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2260 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2261 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2262 | int argc, |
| 2263 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2264 | |
| 2265 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2266 | * 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] | 2267 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2268 | * Note: This method behaves like the Function::NewInstance method. |
| 2269 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2270 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2271 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2272 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2273 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2274 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2276 | Object(); |
| 2277 | static void CheckCast(Value* obj); |
| 2278 | Local<Value> SlowGetInternalField(int index); |
| 2279 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2280 | }; |
| 2281 | |
| 2282 | |
| 2283 | /** |
| 2284 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2285 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2286 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2287 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2288 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2290 | /** |
| 2291 | * Clones an element at index |index|. Returns an empty |
| 2292 | * handle if cloning fails (for any reason). |
| 2293 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2294 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2295 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2296 | /** |
| 2297 | * Creates a JavaScript array with the given length. If the length |
| 2298 | * is negative the returned array will have length 0. |
| 2299 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2300 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2301 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2302 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2303 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2304 | Array(); |
| 2305 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2306 | }; |
| 2307 | |
| 2308 | |
| 2309 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2310 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2312 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2313 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2314 | Local<Object> NewInstance() const; |
| 2315 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2316 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2317 | void SetName(Handle<String> name); |
| 2318 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2319 | |
| 2320 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2321 | * Name inferred from variable or property assignment of this function. |
| 2322 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2323 | * in an OO style, where many functions are anonymous but are assigned |
| 2324 | * to object properties. |
| 2325 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2326 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2327 | |
| 2328 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2329 | * Returns zero based line number of function body and |
| 2330 | * kLineOffsetNotFound if no information available. |
| 2331 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2332 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2333 | /** |
| 2334 | * Returns zero based column number of function body and |
| 2335 | * kLineOffsetNotFound if no information available. |
| 2336 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2337 | int GetScriptColumnNumber() const; |
| 2338 | Handle<Value> GetScriptId() const; |
| 2339 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2340 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2341 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2344 | Function(); |
| 2345 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2346 | }; |
| 2347 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2348 | #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 2349 | #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
| 2350 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2351 | |
| 2352 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2353 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2354 | * This API is experimental and may change significantly. |
| 2355 | */ |
| 2356 | class V8EXPORT ArrayBuffer : public Object { |
| 2357 | public: |
| 2358 | /** |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 2359 | * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. |
| 2360 | * The allocator is a global V8 setting. It should be set with |
| 2361 | * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. |
| 2362 | * |
| 2363 | * This API is experimental and may change significantly. |
| 2364 | */ |
| 2365 | class V8EXPORT Allocator { // NOLINT |
| 2366 | public: |
| 2367 | virtual ~Allocator() {} |
| 2368 | |
| 2369 | /** |
| 2370 | * Allocate |length| bytes. Return NULL if allocation is not successful. |
| 2371 | */ |
| 2372 | virtual void* Allocate(size_t length) = 0; |
| 2373 | /** |
| 2374 | * Free the memory pointed to |data|. That memory is guaranteed to be |
| 2375 | * previously allocated by |Allocate|. |
| 2376 | */ |
| 2377 | virtual void Free(void* data) = 0; |
| 2378 | }; |
| 2379 | |
| 2380 | /** |
| 2381 | * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 2382 | * returns an instance of this class, populated, with a pointer to data |
| 2383 | * and byte length. |
| 2384 | * |
| 2385 | * The Data pointer of ArrayBuffer::Contents is always allocated with |
| 2386 | * Allocator::Allocate that is set with V8::SetArrayBufferAllocator. |
| 2387 | * |
| 2388 | * This API is experimental and may change significantly. |
| 2389 | */ |
| 2390 | class V8EXPORT Contents { // NOLINT |
| 2391 | public: |
| 2392 | Contents() : data_(NULL), byte_length_(0) {} |
| 2393 | |
| 2394 | void* Data() const { return data_; } |
| 2395 | size_t ByteLength() const { return byte_length_; } |
| 2396 | |
| 2397 | private: |
| 2398 | void* data_; |
| 2399 | size_t byte_length_; |
| 2400 | |
| 2401 | friend class ArrayBuffer; |
| 2402 | }; |
| 2403 | |
| 2404 | |
| 2405 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2406 | * Data length in bytes. |
| 2407 | */ |
| 2408 | size_t ByteLength() const; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2409 | |
| 2410 | /** |
| 2411 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2412 | * Allocated memory will be owned by a created ArrayBuffer and |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2413 | * will be deallocated when it is garbage-collected, |
| 2414 | * unless the object is externalized. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2415 | */ |
| 2416 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2417 | |
| 2418 | /** |
| 2419 | * Create a new ArrayBuffer over an existing memory block. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2420 | * The created array buffer is immediately in externalized state. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2421 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2422 | * is garbage-collected. |
| 2423 | */ |
| 2424 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2425 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2426 | /** |
| 2427 | * Returns true if ArrayBuffer is extrenalized, that is, does not |
| 2428 | * own its memory block. |
| 2429 | */ |
| 2430 | bool IsExternal() const; |
| 2431 | |
| 2432 | /** |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 2433 | * Neuters this ArrayBuffer and all its views (typed arrays). |
| 2434 | * Neutering sets the byte length of the buffer and all typed arrays to zero, |
| 2435 | * preventing JavaScript from ever accessing underlying backing store. |
| 2436 | * ArrayBuffer should have been externalized. |
| 2437 | */ |
| 2438 | void Neuter(); |
| 2439 | |
| 2440 | /** |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 2441 | * Make this ArrayBuffer external. The pointer to underlying memory block |
| 2442 | * and byte length are returned as |Contents| structure. After ArrayBuffer |
| 2443 | * had been etxrenalized, it does no longer owns the memory block. The caller |
| 2444 | * should take steps to free memory when it is no longer needed. |
| 2445 | * |
| 2446 | * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
| 2447 | * that has been set with V8::SetArrayBufferAllocator. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2448 | */ |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 2449 | Contents Externalize(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2450 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2451 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2452 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2453 | static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
| 2454 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2455 | private: |
| 2456 | ArrayBuffer(); |
| 2457 | static void CheckCast(Value* obj); |
| 2458 | }; |
| 2459 | |
| 2460 | |
| 2461 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2462 | * A base class for an instance of TypedArray series of constructors |
| 2463 | * (ES6 draft 15.13.6). |
| 2464 | * This API is experimental and may change significantly. |
| 2465 | */ |
| 2466 | class V8EXPORT TypedArray : public Object { |
| 2467 | public: |
| 2468 | /** |
| 2469 | * Returns underlying ArrayBuffer. |
| 2470 | */ |
| 2471 | Local<ArrayBuffer> Buffer(); |
| 2472 | /** |
| 2473 | * Byte offset in |Buffer| |
| 2474 | */ |
| 2475 | size_t ByteOffset(); |
| 2476 | /** |
| 2477 | * Numbe of elements in this typed array. |
| 2478 | */ |
| 2479 | size_t Length(); |
| 2480 | /** |
| 2481 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2482 | */ |
| 2483 | size_t ByteLength(); |
| 2484 | /** |
| 2485 | * Base address of typed array. |
| 2486 | */ |
| 2487 | void* BaseAddress(); |
| 2488 | |
| 2489 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2490 | |
| 2491 | private: |
| 2492 | TypedArray(); |
| 2493 | static void CheckCast(Value* obj); |
| 2494 | }; |
| 2495 | |
| 2496 | |
| 2497 | /** |
| 2498 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2499 | * This API is experimental and may change significantly. |
| 2500 | */ |
| 2501 | class V8EXPORT Uint8Array : public TypedArray { |
| 2502 | public: |
| 2503 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2504 | size_t byte_offset, size_t length); |
| 2505 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2506 | |
| 2507 | private: |
| 2508 | Uint8Array(); |
| 2509 | static void CheckCast(Value* obj); |
| 2510 | }; |
| 2511 | |
| 2512 | |
| 2513 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2514 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2515 | * This API is experimental and may change significantly. |
| 2516 | */ |
| 2517 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2518 | public: |
| 2519 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2520 | size_t byte_offset, size_t length); |
| 2521 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2522 | |
| 2523 | private: |
| 2524 | Uint8ClampedArray(); |
| 2525 | static void CheckCast(Value* obj); |
| 2526 | }; |
| 2527 | |
| 2528 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2529 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2530 | * This API is experimental and may change significantly. |
| 2531 | */ |
| 2532 | class V8EXPORT Int8Array : public TypedArray { |
| 2533 | public: |
| 2534 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2535 | size_t byte_offset, size_t length); |
| 2536 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2537 | |
| 2538 | private: |
| 2539 | Int8Array(); |
| 2540 | static void CheckCast(Value* obj); |
| 2541 | }; |
| 2542 | |
| 2543 | |
| 2544 | /** |
| 2545 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2546 | * This API is experimental and may change significantly. |
| 2547 | */ |
| 2548 | class V8EXPORT Uint16Array : public TypedArray { |
| 2549 | public: |
| 2550 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2551 | size_t byte_offset, size_t length); |
| 2552 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2553 | |
| 2554 | private: |
| 2555 | Uint16Array(); |
| 2556 | static void CheckCast(Value* obj); |
| 2557 | }; |
| 2558 | |
| 2559 | |
| 2560 | /** |
| 2561 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2562 | * This API is experimental and may change significantly. |
| 2563 | */ |
| 2564 | class V8EXPORT Int16Array : public TypedArray { |
| 2565 | public: |
| 2566 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2567 | size_t byte_offset, size_t length); |
| 2568 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2569 | |
| 2570 | private: |
| 2571 | Int16Array(); |
| 2572 | static void CheckCast(Value* obj); |
| 2573 | }; |
| 2574 | |
| 2575 | |
| 2576 | /** |
| 2577 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2578 | * This API is experimental and may change significantly. |
| 2579 | */ |
| 2580 | class V8EXPORT Uint32Array : public TypedArray { |
| 2581 | public: |
| 2582 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2583 | size_t byte_offset, size_t length); |
| 2584 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2585 | |
| 2586 | private: |
| 2587 | Uint32Array(); |
| 2588 | static void CheckCast(Value* obj); |
| 2589 | }; |
| 2590 | |
| 2591 | |
| 2592 | /** |
| 2593 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2594 | * This API is experimental and may change significantly. |
| 2595 | */ |
| 2596 | class V8EXPORT Int32Array : public TypedArray { |
| 2597 | public: |
| 2598 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2599 | size_t byte_offset, size_t length); |
| 2600 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2601 | |
| 2602 | private: |
| 2603 | Int32Array(); |
| 2604 | static void CheckCast(Value* obj); |
| 2605 | }; |
| 2606 | |
| 2607 | |
| 2608 | /** |
| 2609 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2610 | * This API is experimental and may change significantly. |
| 2611 | */ |
| 2612 | class V8EXPORT Float32Array : public TypedArray { |
| 2613 | public: |
| 2614 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2615 | size_t byte_offset, size_t length); |
| 2616 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2617 | |
| 2618 | private: |
| 2619 | Float32Array(); |
| 2620 | static void CheckCast(Value* obj); |
| 2621 | }; |
| 2622 | |
| 2623 | |
| 2624 | /** |
| 2625 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2626 | * This API is experimental and may change significantly. |
| 2627 | */ |
| 2628 | class V8EXPORT Float64Array : public TypedArray { |
| 2629 | public: |
| 2630 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2631 | size_t byte_offset, size_t length); |
| 2632 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2633 | |
| 2634 | private: |
| 2635 | Float64Array(); |
| 2636 | static void CheckCast(Value* obj); |
| 2637 | }; |
| 2638 | |
| 2639 | |
| 2640 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2641 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2642 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2643 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2644 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2645 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2646 | |
| 2647 | /** |
| 2648 | * A specialization of Value::NumberValue that is more efficient |
| 2649 | * because we know the structure of this object. |
| 2650 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2651 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2652 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2653 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2654 | |
| 2655 | /** |
| 2656 | * Notification that the embedder has changed the time zone, |
| 2657 | * daylight savings time, or other date / time configuration |
| 2658 | * parameters. V8 keeps a cache of various values used for |
| 2659 | * date / time computation. This notification will reset |
| 2660 | * those cached values for the current context so that date / |
| 2661 | * time configuration changes would be reflected in the Date |
| 2662 | * object. |
| 2663 | * |
| 2664 | * This API should not be called more than needed as it will |
| 2665 | * negatively impact the performance of date operations. |
| 2666 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2667 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2668 | |
| 2669 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2670 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2671 | }; |
| 2672 | |
| 2673 | |
| 2674 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2675 | * A Number object (ECMA-262, 4.3.21). |
| 2676 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2677 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2678 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2679 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2680 | |
| 2681 | /** |
| 2682 | * Returns the Number held by the object. |
| 2683 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2684 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2685 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2686 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2687 | |
| 2688 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2689 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2690 | }; |
| 2691 | |
| 2692 | |
| 2693 | /** |
| 2694 | * A Boolean object (ECMA-262, 4.3.15). |
| 2695 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2696 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2697 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2698 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2699 | |
| 2700 | /** |
| 2701 | * Returns the Boolean held by the object. |
| 2702 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2703 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2704 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2705 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2706 | |
| 2707 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2708 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2709 | }; |
| 2710 | |
| 2711 | |
| 2712 | /** |
| 2713 | * A String object (ECMA-262, 4.3.18). |
| 2714 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2715 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2716 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2717 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2718 | |
| 2719 | /** |
| 2720 | * Returns the String held by the object. |
| 2721 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2722 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2723 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2724 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2725 | |
| 2726 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2727 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2728 | }; |
| 2729 | |
| 2730 | |
| 2731 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2732 | * A Symbol object (ECMA-262 edition 6). |
| 2733 | * |
| 2734 | * This is an experimental feature. Use at your own risk. |
| 2735 | */ |
| 2736 | class V8EXPORT SymbolObject : public Object { |
| 2737 | public: |
| 2738 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2739 | |
| 2740 | /** |
| 2741 | * Returns the Symbol held by the object. |
| 2742 | */ |
| 2743 | Local<Symbol> SymbolValue() const; |
| 2744 | |
| 2745 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2746 | |
| 2747 | private: |
| 2748 | static void CheckCast(v8::Value* obj); |
| 2749 | }; |
| 2750 | |
| 2751 | |
| 2752 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2753 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2754 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2755 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2756 | public: |
| 2757 | /** |
| 2758 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2759 | * of flags. |
| 2760 | */ |
| 2761 | enum Flags { |
| 2762 | kNone = 0, |
| 2763 | kGlobal = 1, |
| 2764 | kIgnoreCase = 2, |
| 2765 | kMultiline = 4 |
| 2766 | }; |
| 2767 | |
| 2768 | /** |
| 2769 | * Creates a regular expression from the given pattern string and |
| 2770 | * the flags bit field. May throw a JavaScript exception as |
| 2771 | * described in ECMA-262, 15.10.4.1. |
| 2772 | * |
| 2773 | * For example, |
| 2774 | * RegExp::New(v8::String::New("foo"), |
| 2775 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2776 | * is equivalent to evaluating "/foo/gm". |
| 2777 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2778 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2779 | |
| 2780 | /** |
| 2781 | * Returns the value of the source property: a string representing |
| 2782 | * the regular expression. |
| 2783 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2784 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2785 | |
| 2786 | /** |
| 2787 | * Returns the flags bit field. |
| 2788 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2789 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2790 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2791 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2792 | |
| 2793 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2794 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2795 | }; |
| 2796 | |
| 2797 | |
| 2798 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2799 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2800 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2801 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2802 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2803 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2804 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2805 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2806 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2807 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2808 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2809 | }; |
| 2810 | |
| 2811 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2812 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2813 | |
| 2814 | |
| 2815 | /** |
| 2816 | * The superclass of object and function templates. |
| 2817 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2818 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2819 | public: |
| 2820 | /** Adds a property to each instance created by this template.*/ |
| 2821 | void Set(Handle<String> name, Handle<Data> value, |
| 2822 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2823 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2824 | private: |
| 2825 | Template(); |
| 2826 | |
| 2827 | friend class ObjectTemplate; |
| 2828 | friend class FunctionTemplate; |
| 2829 | }; |
| 2830 | |
| 2831 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2832 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2833 | class ReturnValue { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2834 | public: |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2835 | template <class S> V8_INLINE(ReturnValue(const ReturnValue<S>& that)) |
| 2836 | : value_(that.value_) { |
| 2837 | TYPE_CHECK(T, S); |
| 2838 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2839 | // Handle setters |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2840 | template <typename S> V8_INLINE(void Set(const Persistent<S>& handle)); |
| 2841 | template <typename S> V8_INLINE(void Set(const Handle<S> handle)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2842 | // Fast primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2843 | V8_INLINE(void Set(bool value)); |
| 2844 | V8_INLINE(void Set(double i)); |
| 2845 | V8_INLINE(void Set(int32_t i)); |
| 2846 | V8_INLINE(void Set(uint32_t i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2847 | // Fast JS primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2848 | V8_INLINE(void SetNull()); |
| 2849 | V8_INLINE(void SetUndefined()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 2850 | V8_INLINE(void SetEmptyString()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2851 | // Convenience getter for Isolate |
| 2852 | V8_INLINE(Isolate* GetIsolate()); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2853 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2854 | private: |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2855 | template<class F> friend class ReturnValue; |
| 2856 | template<class F> friend class FunctionCallbackInfo; |
| 2857 | template<class F> friend class PropertyCallbackInfo; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2858 | V8_INLINE(internal::Object* GetDefaultValue()); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2859 | V8_INLINE(explicit ReturnValue(internal::Object** slot)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2860 | internal::Object** value_; |
| 2861 | }; |
| 2862 | |
| 2863 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2864 | /** |
| 2865 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2866 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2867 | * including the receiver, the number and values of arguments, and |
| 2868 | * the holder of the function. |
| 2869 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2870 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2871 | class FunctionCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2872 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2873 | V8_INLINE(int Length() const); |
| 2874 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2875 | V8_INLINE(Local<Function> Callee() const); |
| 2876 | V8_INLINE(Local<Object> This() const); |
| 2877 | V8_INLINE(Local<Object> Holder() const); |
| 2878 | V8_INLINE(bool IsConstructCall() const); |
| 2879 | V8_INLINE(Local<Value> Data() const); |
| 2880 | V8_INLINE(Isolate* GetIsolate() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2881 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2882 | // This shouldn't be public, but the arm compiler needs it. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2883 | static const int kArgsLength = 6; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2884 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2885 | protected: |
| 2886 | friend class internal::FunctionCallbackArguments; |
| 2887 | friend class internal::CustomArguments<FunctionCallbackInfo>; |
| 2888 | static const int kReturnValueIndex = 0; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2889 | static const int kReturnValueDefaultValueIndex = -1; |
| 2890 | static const int kIsolateIndex = -2; |
| 2891 | static const int kDataIndex = -3; |
| 2892 | static const int kCalleeIndex = -4; |
| 2893 | static const int kHolderIndex = -5; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2894 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2895 | V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2896 | internal::Object** values, |
| 2897 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2898 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2899 | internal::Object** implicit_args_; |
| 2900 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2901 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2902 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2903 | }; |
| 2904 | |
| 2905 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2906 | class V8EXPORT Arguments : public FunctionCallbackInfo<Value> { |
| 2907 | private: |
| 2908 | friend class internal::FunctionCallbackArguments; |
| 2909 | V8_INLINE(Arguments(internal::Object** implicit_args, |
| 2910 | internal::Object** values, |
| 2911 | int length, |
| 2912 | bool is_construct_call)); |
| 2913 | }; |
| 2914 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2915 | /** |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2916 | * The information passed to a property callback about the context |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2917 | * of the property access. |
| 2918 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2919 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2920 | class PropertyCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2921 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2922 | V8_INLINE(Isolate* GetIsolate() const); |
| 2923 | V8_INLINE(Local<Value> Data() const); |
| 2924 | V8_INLINE(Local<Object> This() const); |
| 2925 | V8_INLINE(Local<Object> Holder() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2926 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2927 | // This shouldn't be public, but the arm compiler needs it. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2928 | static const int kArgsLength = 6; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2929 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2930 | protected: |
| 2931 | friend class MacroAssembler; |
| 2932 | friend class internal::PropertyCallbackArguments; |
| 2933 | friend class internal::CustomArguments<PropertyCallbackInfo>; |
| 2934 | static const int kThisIndex = 0; |
| 2935 | static const int kHolderIndex = -1; |
| 2936 | static const int kDataIndex = -2; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2937 | static const int kReturnValueIndex = -3; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2938 | static const int kReturnValueDefaultValueIndex = -4; |
| 2939 | static const int kIsolateIndex = -5; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2940 | |
| 2941 | V8_INLINE(PropertyCallbackInfo(internal::Object** args)) |
| 2942 | : args_(args) { } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2943 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2944 | }; |
| 2945 | |
| 2946 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2947 | class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> { |
| 2948 | private: |
| 2949 | friend class internal::PropertyCallbackArguments; |
| 2950 | V8_INLINE(AccessorInfo(internal::Object** args)) |
| 2951 | : PropertyCallbackInfo<Value>(args) { } |
| 2952 | }; |
| 2953 | |
| 2954 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2956 | typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2957 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2958 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2959 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2960 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2961 | */ |
| 2962 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2963 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2964 | typedef void (*NamedPropertyGetterCallback)( |
| 2965 | Local<String> property, |
| 2966 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2967 | |
| 2968 | |
| 2969 | /** |
| 2970 | * Returns the value if the setter intercepts the request. |
| 2971 | * Otherwise, returns an empty handle. |
| 2972 | */ |
| 2973 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2974 | Local<Value> value, |
| 2975 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2976 | typedef void (*NamedPropertySetterCallback)( |
| 2977 | Local<String> property, |
| 2978 | Local<Value> value, |
| 2979 | const PropertyCallbackInfo<Value>& info); |
| 2980 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2981 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2982 | /** |
| 2983 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2984 | * The result is an integer encoding property attributes (like v8::None, |
| 2985 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2986 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2987 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2988 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2989 | typedef void (*NamedPropertyQueryCallback)( |
| 2990 | Local<String> property, |
| 2991 | const PropertyCallbackInfo<Integer>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2992 | |
| 2993 | |
| 2994 | /** |
| 2995 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2996 | * The return value is true if the property could be deleted and false |
| 2997 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2998 | */ |
| 2999 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 3000 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3001 | typedef void (*NamedPropertyDeleterCallback)( |
| 3002 | Local<String> property, |
| 3003 | const PropertyCallbackInfo<Boolean>& info); |
| 3004 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3005 | |
| 3006 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3007 | * Returns an array containing the names of the properties the named |
| 3008 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3009 | */ |
| 3010 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3011 | typedef void (*NamedPropertyEnumeratorCallback)( |
| 3012 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3013 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3014 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3015 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3016 | * Returns the value of the property if the getter intercepts the |
| 3017 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3018 | */ |
| 3019 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 3020 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3021 | typedef void (*IndexedPropertyGetterCallback)( |
| 3022 | uint32_t index, |
| 3023 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3024 | |
| 3025 | |
| 3026 | /** |
| 3027 | * Returns the value if the setter intercepts the request. |
| 3028 | * Otherwise, returns an empty handle. |
| 3029 | */ |
| 3030 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 3031 | Local<Value> value, |
| 3032 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3033 | typedef void (*IndexedPropertySetterCallback)( |
| 3034 | uint32_t index, |
| 3035 | Local<Value> value, |
| 3036 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3037 | |
| 3038 | |
| 3039 | /** |
| 3040 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3041 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3042 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3043 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 3044 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3045 | typedef void (*IndexedPropertyQueryCallback)( |
| 3046 | uint32_t index, |
| 3047 | const PropertyCallbackInfo<Integer>& info); |
| 3048 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3049 | |
| 3050 | /** |
| 3051 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3052 | * The return value is true if the property could be deleted and false |
| 3053 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3054 | */ |
| 3055 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 3056 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3057 | typedef void (*IndexedPropertyDeleterCallback)( |
| 3058 | uint32_t index, |
| 3059 | const PropertyCallbackInfo<Boolean>& info); |
| 3060 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3062 | /** |
| 3063 | * Returns an array containing the indices of the properties the |
| 3064 | * indexed property getter intercepts. |
| 3065 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3066 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3067 | typedef void (*IndexedPropertyEnumeratorCallback)( |
| 3068 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3069 | |
| 3070 | |
| 3071 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3072 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | */ |
| 3074 | enum AccessType { |
| 3075 | ACCESS_GET, |
| 3076 | ACCESS_SET, |
| 3077 | ACCESS_HAS, |
| 3078 | ACCESS_DELETE, |
| 3079 | ACCESS_KEYS |
| 3080 | }; |
| 3081 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3082 | |
| 3083 | /** |
| 3084 | * 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] | 3085 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3086 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3087 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3088 | Local<Value> key, |
| 3089 | AccessType type, |
| 3090 | Local<Value> data); |
| 3091 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3092 | |
| 3093 | /** |
| 3094 | * 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] | 3095 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3096 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3097 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3098 | uint32_t index, |
| 3099 | AccessType type, |
| 3100 | Local<Value> data); |
| 3101 | |
| 3102 | |
| 3103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3104 | * A FunctionTemplate is used to create functions at runtime. There |
| 3105 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3106 | * context. The lifetime of the created function is equal to the |
| 3107 | * lifetime of the context. So in case the embedder needs to create |
| 3108 | * temporary functions that can be collected using Scripts is |
| 3109 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3110 | * |
| 3111 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3112 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3113 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3114 | * A FunctionTemplate has a corresponding instance template which is |
| 3115 | * used to create object instances when the function is used as a |
| 3116 | * constructor. Properties added to the instance template are added to |
| 3117 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3118 | * |
| 3119 | * A FunctionTemplate can have a prototype template. The prototype template |
| 3120 | * is used to create the prototype object of the function. |
| 3121 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3122 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3123 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3124 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3125 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 3126 | * t->Set("func_property", v8::Number::New(1)); |
| 3127 | * |
| 3128 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 3129 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 3130 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 3131 | * |
| 3132 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 3133 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 3134 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 3135 | * instance_t->Set("instance_property", Number::New(3)); |
| 3136 | * |
| 3137 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 3138 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3139 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3140 | * |
| 3141 | * 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] | 3142 | * and "instance" for the instance object created above. The function |
| 3143 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3144 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3145 | * \code |
| 3146 | * func_property in function == true; |
| 3147 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3148 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3149 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 3150 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3151 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3152 | * instance instanceof function == true; |
| 3153 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 3154 | * instance.instance_property == 3; |
| 3155 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3156 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3157 | * A FunctionTemplate can inherit from another one by calling the |
| 3158 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 3159 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3160 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3161 | * \code |
| 3162 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 3163 | * ^ ^ |
| 3164 | * | Inherit(Parent) | .__proto__ |
| 3165 | * | | |
| 3166 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 3167 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3168 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3169 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 3170 | * object of the Child() function has __proto__ pointing to the |
| 3171 | * Parent() function's prototype object. An instance of the Child |
| 3172 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3173 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3174 | * Let Parent be the FunctionTemplate initialized in the previous |
| 3175 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3176 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3177 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3178 | * Local<FunctionTemplate> parent = t; |
| 3179 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 3180 | * child->Inherit(parent); |
| 3181 | * |
| 3182 | * Local<Function> child_function = child->GetFunction(); |
| 3183 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3184 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3185 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3186 | * The Child function and Child instance will have the following |
| 3187 | * properties: |
| 3188 | * |
| 3189 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3190 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3191 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3192 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3193 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3194 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3195 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3196 | public: |
| 3197 | /** Creates a function template.*/ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3198 | // TODO(dcarney): deprecate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3199 | static Local<FunctionTemplate> New( |
| 3200 | InvocationCallback callback = 0, |
| 3201 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3202 | Handle<Signature> signature = Handle<Signature>(), |
| 3203 | int length = 0); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3204 | static Local<FunctionTemplate> New( |
| 3205 | FunctionCallback callback, // TODO(dcarney): add back default param. |
| 3206 | Handle<Value> data = Handle<Value>(), |
| 3207 | Handle<Signature> signature = Handle<Signature>(), |
| 3208 | int length = 0); |
| 3209 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3210 | /** Returns the unique function instance in the current execution context.*/ |
| 3211 | Local<Function> GetFunction(); |
| 3212 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3213 | /** |
| 3214 | * Set the call-handler callback for a FunctionTemplate. This |
| 3215 | * callback is called whenever the function created from this |
| 3216 | * FunctionTemplate is called. |
| 3217 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3218 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3219 | void SetCallHandler(InvocationCallback callback, |
| 3220 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3221 | void SetCallHandler(FunctionCallback callback, |
| 3222 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3223 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3224 | /** Set the predefined length property for the FunctionTemplate. */ |
| 3225 | void SetLength(int length); |
| 3226 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3227 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3228 | Local<ObjectTemplate> InstanceTemplate(); |
| 3229 | |
| 3230 | /** Causes the function template to inherit from a parent function template.*/ |
| 3231 | void Inherit(Handle<FunctionTemplate> parent); |
| 3232 | |
| 3233 | /** |
| 3234 | * A PrototypeTemplate is the template used to create the prototype object |
| 3235 | * of the function created by this template. |
| 3236 | */ |
| 3237 | Local<ObjectTemplate> PrototypeTemplate(); |
| 3238 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3239 | /** |
| 3240 | * Set the class name of the FunctionTemplate. This is used for |
| 3241 | * printing objects created with the function created from the |
| 3242 | * FunctionTemplate as its constructor. |
| 3243 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3244 | void SetClassName(Handle<String> name); |
| 3245 | |
| 3246 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3247 | * Determines whether the __proto__ accessor ignores instances of |
| 3248 | * the function template. If instances of the function template are |
| 3249 | * ignored, __proto__ skips all instances and instead returns the |
| 3250 | * next object in the prototype chain. |
| 3251 | * |
| 3252 | * Call with a value of true to make the __proto__ accessor ignore |
| 3253 | * instances of the function template. Call with a value of false |
| 3254 | * to make the __proto__ accessor not ignore instances of the |
| 3255 | * function template. By default, instances of a function template |
| 3256 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3257 | */ |
| 3258 | void SetHiddenPrototype(bool value); |
| 3259 | |
| 3260 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3261 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3262 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3263 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3264 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3265 | |
| 3266 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3267 | * Returns true if the given object is an instance of this function |
| 3268 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3269 | */ |
| 3270 | bool HasInstance(Handle<Value> object); |
| 3271 | |
| 3272 | private: |
| 3273 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3274 | friend class Context; |
| 3275 | friend class ObjectTemplate; |
| 3276 | }; |
| 3277 | |
| 3278 | |
| 3279 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3280 | * An ObjectTemplate is used to create objects at runtime. |
| 3281 | * |
| 3282 | * Properties added to an ObjectTemplate are added to each object |
| 3283 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3284 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3285 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3286 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3287 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3288 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3289 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3290 | /** Creates a new instance of this template.*/ |
| 3291 | Local<Object> NewInstance(); |
| 3292 | |
| 3293 | /** |
| 3294 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3295 | * |
| 3296 | * Whenever the property with the given name is accessed on objects |
| 3297 | * created from this ObjectTemplate the getter and setter callbacks |
| 3298 | * are called instead of getting and setting the property directly |
| 3299 | * on the JavaScript object. |
| 3300 | * |
| 3301 | * \param name The name of the property for which an accessor is added. |
| 3302 | * \param getter The callback to invoke when getting the property. |
| 3303 | * \param setter The callback to invoke when setting the property. |
| 3304 | * \param data A piece of data that will be passed to the getter and setter |
| 3305 | * callbacks whenever they are invoked. |
| 3306 | * \param settings Access control settings for the accessor. This is a bit |
| 3307 | * field consisting of one of more of |
| 3308 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3309 | * The default is to not allow cross-context access. |
| 3310 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3311 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3312 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3313 | * cross-context access. |
| 3314 | * \param attribute The attributes of the property for which an accessor |
| 3315 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3316 | * \param signature The signature describes valid receivers for the accessor |
| 3317 | * and is used to perform implicit instance checks against them. If the |
| 3318 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3319 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3320 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3321 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3322 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3323 | void SetAccessor(Handle<String> name, |
| 3324 | AccessorGetter getter, |
| 3325 | AccessorSetter setter = 0, |
| 3326 | Handle<Value> data = Handle<Value>(), |
| 3327 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3328 | PropertyAttribute attribute = None, |
| 3329 | Handle<AccessorSignature> signature = |
| 3330 | Handle<AccessorSignature>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3331 | void SetAccessor(Handle<String> name, |
| 3332 | AccessorGetterCallback getter, |
| 3333 | AccessorSetterCallback setter = 0, |
| 3334 | Handle<Value> data = Handle<Value>(), |
| 3335 | AccessControl settings = DEFAULT, |
| 3336 | PropertyAttribute attribute = None, |
| 3337 | Handle<AccessorSignature> signature = |
| 3338 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3339 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3340 | // This function is not yet stable and should not be used at this time. |
| 3341 | bool SetAccessor(Handle<String> name, |
| 3342 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3343 | AccessControl settings = DEFAULT, |
| 3344 | PropertyAttribute attribute = None, |
| 3345 | Handle<AccessorSignature> signature = |
| 3346 | Handle<AccessorSignature>()); |
| 3347 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3348 | /** |
| 3349 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3350 | * |
| 3351 | * Whenever a named property is accessed on objects created from |
| 3352 | * this object template, the provided callback is invoked instead of |
| 3353 | * accessing the property directly on the JavaScript object. |
| 3354 | * |
| 3355 | * \param getter The callback to invoke when getting a property. |
| 3356 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3357 | * \param query The callback to invoke to check if a property is present, |
| 3358 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3359 | * \param deleter The callback to invoke when deleting a property. |
| 3360 | * \param enumerator The callback to invoke to enumerate all the named |
| 3361 | * properties of an object. |
| 3362 | * \param data A piece of data that will be passed to the callbacks |
| 3363 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3364 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3365 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3366 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3367 | NamedPropertySetter setter = 0, |
| 3368 | NamedPropertyQuery query = 0, |
| 3369 | NamedPropertyDeleter deleter = 0, |
| 3370 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3371 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3372 | void SetNamedPropertyHandler( |
| 3373 | NamedPropertyGetterCallback getter, |
| 3374 | NamedPropertySetterCallback setter = 0, |
| 3375 | NamedPropertyQueryCallback query = 0, |
| 3376 | NamedPropertyDeleterCallback deleter = 0, |
| 3377 | NamedPropertyEnumeratorCallback enumerator = 0, |
| 3378 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3379 | |
| 3380 | /** |
| 3381 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3382 | * |
| 3383 | * Whenever an indexed property is accessed on objects created from |
| 3384 | * this object template, the provided callback is invoked instead of |
| 3385 | * accessing the property directly on the JavaScript object. |
| 3386 | * |
| 3387 | * \param getter The callback to invoke when getting a property. |
| 3388 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3389 | * \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] | 3390 | * \param deleter The callback to invoke when deleting a property. |
| 3391 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3392 | * properties of an object. |
| 3393 | * \param data A piece of data that will be passed to the callbacks |
| 3394 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3395 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3396 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3397 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3398 | IndexedPropertySetter setter = 0, |
| 3399 | IndexedPropertyQuery query = 0, |
| 3400 | IndexedPropertyDeleter deleter = 0, |
| 3401 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3402 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3403 | void SetIndexedPropertyHandler( |
| 3404 | IndexedPropertyGetterCallback getter, |
| 3405 | IndexedPropertySetterCallback setter = 0, |
| 3406 | IndexedPropertyQueryCallback query = 0, |
| 3407 | IndexedPropertyDeleterCallback deleter = 0, |
| 3408 | IndexedPropertyEnumeratorCallback enumerator = 0, |
| 3409 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3410 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3411 | /** |
| 3412 | * Sets the callback to be used when calling instances created from |
| 3413 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3414 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3415 | * function. |
| 3416 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3417 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3418 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3419 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3420 | void SetCallAsFunctionHandler(FunctionCallback callback, |
| 3421 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3422 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3423 | /** |
| 3424 | * Mark object instances of the template as undetectable. |
| 3425 | * |
| 3426 | * In many ways, undetectable objects behave as though they are not |
| 3427 | * there. They behave like 'undefined' in conditionals and when |
| 3428 | * printed. However, properties can be accessed and called as on |
| 3429 | * normal objects. |
| 3430 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3431 | void MarkAsUndetectable(); |
| 3432 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3433 | /** |
| 3434 | * Sets access check callbacks on the object template. |
| 3435 | * |
| 3436 | * When accessing properties on instances of this object template, |
| 3437 | * the access check callback will be called to determine whether or |
| 3438 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3439 | * The last parameter specifies whether access checks are turned |
| 3440 | * on by default on instances. If access checks are off by default, |
| 3441 | * they can be turned on on individual instances by calling |
| 3442 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3443 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3444 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3445 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3446 | Handle<Value> data = Handle<Value>(), |
| 3447 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3448 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3449 | /** |
| 3450 | * Gets the number of internal fields for objects generated from |
| 3451 | * this template. |
| 3452 | */ |
| 3453 | int InternalFieldCount(); |
| 3454 | |
| 3455 | /** |
| 3456 | * Sets the number of internal fields for objects generated from |
| 3457 | * this template. |
| 3458 | */ |
| 3459 | void SetInternalFieldCount(int value); |
| 3460 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3461 | private: |
| 3462 | ObjectTemplate(); |
| 3463 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3464 | friend class FunctionTemplate; |
| 3465 | }; |
| 3466 | |
| 3467 | |
| 3468 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3469 | * A Signature specifies which receivers and arguments are valid |
| 3470 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3471 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3472 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3473 | public: |
| 3474 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3475 | Handle<FunctionTemplate>(), |
| 3476 | int argc = 0, |
| 3477 | Handle<FunctionTemplate> argv[] = 0); |
| 3478 | private: |
| 3479 | Signature(); |
| 3480 | }; |
| 3481 | |
| 3482 | |
| 3483 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3484 | * An AccessorSignature specifies which receivers are valid parameters |
| 3485 | * to an accessor callback. |
| 3486 | */ |
| 3487 | class V8EXPORT AccessorSignature : public Data { |
| 3488 | public: |
| 3489 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3490 | Handle<FunctionTemplate>()); |
| 3491 | private: |
| 3492 | AccessorSignature(); |
| 3493 | }; |
| 3494 | |
| 3495 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3496 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3497 | private: |
| 3498 | DeclaredAccessorDescriptor(); |
| 3499 | }; |
| 3500 | |
| 3501 | |
| 3502 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3503 | public: |
| 3504 | // This function is not yet stable and should not be used at this time. |
| 3505 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3506 | Isolate* isolate, |
| 3507 | int internal_field); |
| 3508 | private: |
| 3509 | ObjectOperationDescriptor(); |
| 3510 | }; |
| 3511 | |
| 3512 | |
| 3513 | enum DeclaredAccessorDescriptorDataType { |
| 3514 | kDescriptorBoolType, |
| 3515 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3516 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3517 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3518 | kDescriptorFloatType, kDescriptorDoubleType |
| 3519 | }; |
| 3520 | |
| 3521 | |
| 3522 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3523 | public: |
| 3524 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3525 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3526 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3527 | int16_t byte_offset); |
| 3528 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3529 | void* compare_value); |
| 3530 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3531 | Isolate* isolate, |
| 3532 | DeclaredAccessorDescriptorDataType data_type, |
| 3533 | uint8_t bool_offset = 0); |
| 3534 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3535 | uint8_t bitmask, |
| 3536 | uint8_t compare_value); |
| 3537 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3538 | Isolate* isolate, |
| 3539 | uint16_t bitmask, |
| 3540 | uint16_t compare_value); |
| 3541 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3542 | Isolate* isolate, |
| 3543 | uint32_t bitmask, |
| 3544 | uint32_t compare_value); |
| 3545 | |
| 3546 | private: |
| 3547 | RawOperationDescriptor(); |
| 3548 | }; |
| 3549 | |
| 3550 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3551 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3552 | * A utility for determining the type of objects based on the template |
| 3553 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3554 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3555 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3556 | public: |
| 3557 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3558 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3559 | int match(Handle<Value> value); |
| 3560 | private: |
| 3561 | TypeSwitch(); |
| 3562 | }; |
| 3563 | |
| 3564 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3565 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3566 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3567 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3568 | : public String::ExternalAsciiStringResource { |
| 3569 | public: |
| 3570 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3571 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3572 | : data_(data), length_(length) {} |
| 3573 | const char* data() const { return data_; } |
| 3574 | size_t length() const { return length_; } |
| 3575 | |
| 3576 | private: |
| 3577 | const char* data_; |
| 3578 | size_t length_; |
| 3579 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3580 | |
| 3581 | /** |
| 3582 | * Ignore |
| 3583 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3584 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3585 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3586 | // Note that the strings passed into this constructor must live as long |
| 3587 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3588 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3589 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3590 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3591 | const char** deps = 0, |
| 3592 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3593 | virtual ~Extension() { } |
| 3594 | virtual v8::Handle<v8::FunctionTemplate> |
| 3595 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3596 | return v8::Handle<v8::FunctionTemplate>(); |
| 3597 | } |
| 3598 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3599 | const char* name() const { return name_; } |
| 3600 | size_t source_length() const { return source_length_; } |
| 3601 | const String::ExternalAsciiStringResource* source() const { |
| 3602 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3603 | int dependency_count() { return dep_count_; } |
| 3604 | const char** dependencies() { return deps_; } |
| 3605 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3606 | bool auto_enable() { return auto_enable_; } |
| 3607 | |
| 3608 | private: |
| 3609 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3610 | size_t source_length_; // expected to initialize before source_ |
| 3611 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3612 | int dep_count_; |
| 3613 | const char** deps_; |
| 3614 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3615 | |
| 3616 | // Disallow copying and assigning. |
| 3617 | Extension(const Extension&); |
| 3618 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3619 | }; |
| 3620 | |
| 3621 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3622 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3623 | |
| 3624 | |
| 3625 | /** |
| 3626 | * Ignore |
| 3627 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3628 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3629 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3630 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3631 | RegisterExtension(extension); |
| 3632 | } |
| 3633 | }; |
| 3634 | |
| 3635 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3636 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3637 | |
| 3638 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3639 | Handle<Primitive> V8EXPORT Undefined(); |
| 3640 | Handle<Primitive> V8EXPORT Null(); |
| 3641 | Handle<Boolean> V8EXPORT True(); |
| 3642 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3643 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3644 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3645 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3646 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3647 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3648 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3649 | |
| 3650 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3651 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3652 | * You must set the heap size before initializing the VM - the size cannot be |
| 3653 | * adjusted after the VM is initialized. |
| 3654 | * |
| 3655 | * If you are using threads then you should hold the V8::Locker lock while |
| 3656 | * setting the stack limit and you must set a non-default stack limit separately |
| 3657 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3658 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3659 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3660 | public: |
| 3661 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3662 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3663 | 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] | 3664 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3665 | 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] | 3666 | int max_executable_size() { return max_executable_size_; } |
| 3667 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3668 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3669 | // 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] | 3670 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3671 | private: |
| 3672 | int max_young_space_size_; |
| 3673 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3674 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3675 | uint32_t* stack_limit_; |
| 3676 | }; |
| 3677 | |
| 3678 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3679 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3680 | |
| 3681 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3682 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3683 | |
| 3684 | |
| 3685 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3686 | |
| 3687 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3688 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3689 | |
| 3690 | |
| 3691 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3692 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3693 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3694 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3695 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3696 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3697 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3698 | |
| 3699 | /** |
| 3700 | * Create new error objects by calling the corresponding error object |
| 3701 | * constructor with the message. |
| 3702 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3703 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3704 | public: |
| 3705 | static Local<Value> RangeError(Handle<String> message); |
| 3706 | static Local<Value> ReferenceError(Handle<String> message); |
| 3707 | static Local<Value> SyntaxError(Handle<String> message); |
| 3708 | static Local<Value> TypeError(Handle<String> message); |
| 3709 | static Local<Value> Error(Handle<String> message); |
| 3710 | }; |
| 3711 | |
| 3712 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3713 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3714 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3715 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3716 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3717 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3718 | int min, |
| 3719 | int max, |
| 3720 | size_t buckets); |
| 3721 | |
| 3722 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3723 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3724 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3725 | enum ObjectSpace { |
| 3726 | kObjectSpaceNewSpace = 1 << 0, |
| 3727 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3728 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3729 | kObjectSpaceCodeSpace = 1 << 3, |
| 3730 | kObjectSpaceMapSpace = 1 << 4, |
| 3731 | kObjectSpaceLoSpace = 1 << 5, |
| 3732 | |
| 3733 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3734 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3735 | kObjectSpaceLoSpace |
| 3736 | }; |
| 3737 | |
| 3738 | enum AllocationAction { |
| 3739 | kAllocationActionAllocate = 1 << 0, |
| 3740 | kAllocationActionFree = 1 << 1, |
| 3741 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3742 | }; |
| 3743 | |
| 3744 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3745 | AllocationAction action, |
| 3746 | int size); |
| 3747 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3748 | // --- Leave Script Callback --- |
| 3749 | typedef void (*CallCompletedCallback)(); |
| 3750 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3751 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3752 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3753 | AccessType type, |
| 3754 | Local<Value> data); |
| 3755 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3756 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3757 | |
| 3758 | /** |
| 3759 | * Callback to check if code generation from strings is allowed. See |
| 3760 | * Context::AllowCodeGenerationFromStrings. |
| 3761 | */ |
| 3762 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3763 | |
| 3764 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3765 | |
| 3766 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3767 | * Applications can register callback functions which will be called |
| 3768 | * before and after a garbage collection. Allocations are not |
| 3769 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3770 | * objects (set or delete properties for example) since it is possible |
| 3771 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3772 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3773 | enum GCType { |
| 3774 | kGCTypeScavenge = 1 << 0, |
| 3775 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3776 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3777 | }; |
| 3778 | |
| 3779 | enum GCCallbackFlags { |
| 3780 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3781 | kGCCallbackFlagCompacted = 1 << 0, |
| 3782 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3783 | }; |
| 3784 | |
| 3785 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3786 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3787 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3788 | typedef void (*GCCallback)(); |
| 3789 | |
| 3790 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3791 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3792 | * Collection of V8 heap information. |
| 3793 | * |
| 3794 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3795 | * get heap statistics from V8. |
| 3796 | */ |
| 3797 | class V8EXPORT HeapStatistics { |
| 3798 | public: |
| 3799 | HeapStatistics(); |
| 3800 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3801 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3802 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3803 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3804 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3805 | |
| 3806 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3807 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3808 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3809 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3810 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3811 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3812 | |
| 3813 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3814 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3815 | }; |
| 3816 | |
| 3817 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3818 | class RetainedObjectInfo; |
| 3819 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3820 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3821 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3822 | * isolates have completely separate states. Objects from one isolate |
| 3823 | * must not be used in other isolates. When V8 is initialized a |
| 3824 | * default isolate is implicitly created and entered. The embedder |
| 3825 | * can create additional isolates and use them in parallel in multiple |
| 3826 | * 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] | 3827 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3828 | */ |
| 3829 | class V8EXPORT Isolate { |
| 3830 | public: |
| 3831 | /** |
| 3832 | * Stack-allocated class which sets the isolate for all operations |
| 3833 | * executed within a local scope. |
| 3834 | */ |
| 3835 | class V8EXPORT Scope { |
| 3836 | public: |
| 3837 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3838 | isolate->Enter(); |
| 3839 | } |
| 3840 | |
| 3841 | ~Scope() { isolate_->Exit(); } |
| 3842 | |
| 3843 | private: |
| 3844 | Isolate* const isolate_; |
| 3845 | |
| 3846 | // Prevent copying of Scope objects. |
| 3847 | Scope(const Scope&); |
| 3848 | Scope& operator=(const Scope&); |
| 3849 | }; |
| 3850 | |
| 3851 | /** |
| 3852 | * Creates a new isolate. Does not change the currently entered |
| 3853 | * isolate. |
| 3854 | * |
| 3855 | * When an isolate is no longer used its resources should be freed |
| 3856 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3857 | */ |
| 3858 | static Isolate* New(); |
| 3859 | |
| 3860 | /** |
| 3861 | * Returns the entered isolate for the current thread or NULL in |
| 3862 | * case there is no current isolate. |
| 3863 | */ |
| 3864 | static Isolate* GetCurrent(); |
| 3865 | |
| 3866 | /** |
| 3867 | * Methods below this point require holding a lock (using Locker) in |
| 3868 | * a multi-threaded environment. |
| 3869 | */ |
| 3870 | |
| 3871 | /** |
| 3872 | * Sets this isolate as the entered one for the current thread. |
| 3873 | * Saves the previously entered one (if any), so that it can be |
| 3874 | * restored when exiting. Re-entering an isolate is allowed. |
| 3875 | */ |
| 3876 | void Enter(); |
| 3877 | |
| 3878 | /** |
| 3879 | * Exits this isolate by restoring the previously entered one in the |
| 3880 | * current thread. The isolate may still stay the same, if it was |
| 3881 | * entered more than once. |
| 3882 | * |
| 3883 | * Requires: this == Isolate::GetCurrent(). |
| 3884 | */ |
| 3885 | void Exit(); |
| 3886 | |
| 3887 | /** |
| 3888 | * Disposes the isolate. The isolate must not be entered by any |
| 3889 | * thread to be disposable. |
| 3890 | */ |
| 3891 | void Dispose(); |
| 3892 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3893 | /** |
| 3894 | * Associate embedder-specific data with the isolate |
| 3895 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3896 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3897 | |
| 3898 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3899 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3900 | * Returns NULL if SetData has never been called. |
| 3901 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3902 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3903 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3904 | /** |
| 3905 | * Get statistics about the heap memory usage. |
| 3906 | */ |
| 3907 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3908 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3909 | /** |
| 3910 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3911 | * indication of the amount of externally allocated memory that is kept alive |
| 3912 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3913 | * garbage collections. Registering externally allocated memory will trigger |
| 3914 | * global garbage collections more often than it would otherwise in an attempt |
| 3915 | * to garbage collect the JavaScript objects that keep the externally |
| 3916 | * allocated memory alive. |
| 3917 | * |
| 3918 | * \param change_in_bytes the change in externally allocated memory that is |
| 3919 | * kept alive by JavaScript objects. |
| 3920 | * \returns the adjusted value. |
| 3921 | */ |
| 3922 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3923 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3924 | /** |
| 3925 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3926 | * is initialized. |
| 3927 | */ |
| 3928 | HeapProfiler* GetHeapProfiler(); |
| 3929 | |
| 3930 | /** |
| 3931 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3932 | * is initialized. |
| 3933 | */ |
| 3934 | CpuProfiler* GetCpuProfiler(); |
| 3935 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3936 | /** Returns the context that is on the top of the stack. */ |
| 3937 | Local<Context> GetCurrentContext(); |
| 3938 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3939 | /** |
| 3940 | * Allows the host application to group objects together. If one |
| 3941 | * object in the group is alive, all objects in the group are alive. |
| 3942 | * After each garbage collection, object groups are removed. It is |
| 3943 | * intended to be used in the before-garbage-collection callback |
| 3944 | * function, for instance to simulate DOM tree connections among JS |
| 3945 | * wrapper objects. Object groups for all dependent handles need to |
| 3946 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3947 | * garbage collection types it is sufficient to provide object groups |
| 3948 | * for partially dependent handles only. |
| 3949 | */ |
| 3950 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3951 | UniqueId id); |
| 3952 | |
| 3953 | /** |
| 3954 | * Allows the host application to declare implicit references from an object |
| 3955 | * group to an object. If the objects of the object group are alive, the child |
| 3956 | * object is alive too. After each garbage collection, all implicit references |
| 3957 | * are removed. It is intended to be used in the before-garbage-collection |
| 3958 | * callback function. |
| 3959 | */ |
| 3960 | void SetReferenceFromGroup(UniqueId id, |
| 3961 | const Persistent<Value>& child); |
| 3962 | |
| 3963 | /** |
| 3964 | * Allows the host application to declare implicit references from an object |
| 3965 | * to another object. If the parent object is alive, the child object is alive |
| 3966 | * too. After each garbage collection, all implicit references are removed. It |
| 3967 | * is intended to be used in the before-garbage-collection callback function. |
| 3968 | */ |
| 3969 | void SetReference(const Persistent<Object>& parent, |
| 3970 | const Persistent<Value>& child); |
| 3971 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3972 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3973 | Isolate(); |
| 3974 | Isolate(const Isolate&); |
| 3975 | ~Isolate(); |
| 3976 | Isolate& operator=(const Isolate&); |
| 3977 | void* operator new(size_t size); |
| 3978 | void operator delete(void*, size_t); |
| 3979 | }; |
| 3980 | |
| 3981 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3982 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3983 | public: |
| 3984 | enum CompressionAlgorithm { |
| 3985 | kUncompressed, |
| 3986 | kBZip2 |
| 3987 | }; |
| 3988 | |
| 3989 | const char* data; |
| 3990 | int compressed_size; |
| 3991 | int raw_size; |
| 3992 | }; |
| 3993 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3994 | |
| 3995 | /** |
| 3996 | * A helper class for driving V8 startup data decompression. It is based on |
| 3997 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3998 | * for an embedder to use this class, instead, API functions can be used |
| 3999 | * directly. |
| 4000 | * |
| 4001 | * For an example of the class usage, see the "shell.cc" sample application. |
| 4002 | */ |
| 4003 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 4004 | public: |
| 4005 | StartupDataDecompressor(); |
| 4006 | virtual ~StartupDataDecompressor(); |
| 4007 | int Decompress(); |
| 4008 | |
| 4009 | protected: |
| 4010 | virtual int DecompressData(char* raw_data, |
| 4011 | int* raw_data_size, |
| 4012 | const char* compressed_data, |
| 4013 | int compressed_data_size) = 0; |
| 4014 | |
| 4015 | private: |
| 4016 | char** raw_data; |
| 4017 | }; |
| 4018 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4019 | |
| 4020 | /** |
| 4021 | * EntropySource is used as a callback function when v8 needs a source |
| 4022 | * of entropy. |
| 4023 | */ |
| 4024 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 4025 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4026 | |
| 4027 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4028 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 4029 | * resolving the location of a return address on the stack. Profilers that |
| 4030 | * change the return address on the stack can use this to resolve the stack |
| 4031 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4032 | * |
| 4033 | * \param return_addr_location points to a location on stack where a machine |
| 4034 | * return address resides. |
| 4035 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 4036 | * copy of the original return address. |
| 4037 | * |
| 4038 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4039 | */ |
| 4040 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 4041 | uintptr_t return_addr_location); |
| 4042 | |
| 4043 | |
| 4044 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4045 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 4046 | * any generated function when function-level profiling is enabled. |
| 4047 | * |
| 4048 | * \param function the address of the function that's being entered. |
| 4049 | * \param return_addr_location points to a location on stack where the machine |
| 4050 | * return address resides. This can be used to identify the caller of |
| 4051 | * \p function, and/or modified to divert execution when \p function exits. |
| 4052 | * |
| 4053 | * \note the entry hook must not cause garbage collection. |
| 4054 | */ |
| 4055 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 4056 | uintptr_t return_addr_location); |
| 4057 | |
| 4058 | |
| 4059 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4060 | * A JIT code event is issued each time code is added, moved or removed. |
| 4061 | * |
| 4062 | * \note removal events are not currently issued. |
| 4063 | */ |
| 4064 | struct JitCodeEvent { |
| 4065 | enum EventType { |
| 4066 | CODE_ADDED, |
| 4067 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4068 | CODE_REMOVED, |
| 4069 | CODE_ADD_LINE_POS_INFO, |
| 4070 | CODE_START_LINE_INFO_RECORDING, |
| 4071 | CODE_END_LINE_INFO_RECORDING |
| 4072 | }; |
| 4073 | // Definition of the code position type. The "POSITION" type means the place |
| 4074 | // in the source code which are of interest when making stack traces to |
| 4075 | // pin-point the source location of a stack frame as close as possible. |
| 4076 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 4077 | // statement, and is used to indicate possible break locations. |
| 4078 | enum PositionType { |
| 4079 | POSITION, |
| 4080 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4081 | }; |
| 4082 | |
| 4083 | // Type of event. |
| 4084 | EventType type; |
| 4085 | // Start of the instructions. |
| 4086 | void* code_start; |
| 4087 | // Size of the instructions. |
| 4088 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4089 | // Script info for CODE_ADDED event. |
| 4090 | Handle<Script> script; |
| 4091 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 4092 | // code line information which is returned from the |
| 4093 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 4094 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 4095 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4096 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4097 | struct name_t { |
| 4098 | // Name of the object associated with the code, note that the string is not |
| 4099 | // zero-terminated. |
| 4100 | const char* str; |
| 4101 | // Number of chars in str. |
| 4102 | size_t len; |
| 4103 | }; |
| 4104 | |
| 4105 | struct line_info_t { |
| 4106 | // PC offset |
| 4107 | size_t offset; |
| 4108 | // Code postion |
| 4109 | size_t pos; |
| 4110 | // The position type. |
| 4111 | PositionType position_type; |
| 4112 | }; |
| 4113 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4114 | union { |
| 4115 | // Only valid for CODE_ADDED. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4116 | struct name_t name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4117 | |
| 4118 | // Only valid for CODE_ADD_LINE_POS_INFO |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4119 | struct line_info_t line_info; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4120 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4121 | // New location of instructions. Only valid for CODE_MOVED. |
| 4122 | void* new_code_start; |
| 4123 | }; |
| 4124 | }; |
| 4125 | |
| 4126 | /** |
| 4127 | * Option flags passed to the SetJitCodeEventHandler function. |
| 4128 | */ |
| 4129 | enum JitCodeEventOptions { |
| 4130 | kJitCodeEventDefault = 0, |
| 4131 | // Generate callbacks for already existent code. |
| 4132 | kJitCodeEventEnumExisting = 1 |
| 4133 | }; |
| 4134 | |
| 4135 | |
| 4136 | /** |
| 4137 | * Callback function passed to SetJitCodeEventHandler. |
| 4138 | * |
| 4139 | * \param event code add, move or removal event. |
| 4140 | */ |
| 4141 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 4142 | |
| 4143 | |
| 4144 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4145 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4146 | */ |
| 4147 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 4148 | public: |
| 4149 | virtual ~ExternalResourceVisitor() {} |
| 4150 | virtual void VisitExternalString(Handle<String> string) {} |
| 4151 | }; |
| 4152 | |
| 4153 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4154 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4155 | * Interface for iterating through all the persistent handles in the heap. |
| 4156 | */ |
| 4157 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 4158 | public: |
| 4159 | virtual ~PersistentHandleVisitor() {} |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4160 | virtual void VisitPersistentHandle(Persistent<Value>* value, |
| 4161 | uint16_t class_id) {} |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4162 | }; |
| 4163 | |
| 4164 | |
| 4165 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4166 | * Asserts that no action is performed that could cause a handle's value |
| 4167 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 4168 | * be performed. |
| 4169 | */ |
| 4170 | class V8EXPORT AssertNoGCScope { |
| 4171 | #ifndef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4172 | // TODO(yangguo): remove isolate argument. |
| 4173 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4174 | #else |
| 4175 | AssertNoGCScope(Isolate* isolate); |
| 4176 | ~AssertNoGCScope(); |
| 4177 | private: |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4178 | void* disallow_heap_allocation_; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4179 | #endif |
| 4180 | }; |
| 4181 | |
| 4182 | |
| 4183 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4184 | * Container class for static utility functions. |
| 4185 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4186 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4187 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4188 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4189 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 4190 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4191 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4192 | * Set the callback to invoke to check if code generation from |
| 4193 | * strings should be allowed. |
| 4194 | */ |
| 4195 | static void SetAllowCodeGenerationFromStringsCallback( |
| 4196 | AllowCodeGenerationFromStringsCallback that); |
| 4197 | |
| 4198 | /** |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4199 | * Set allocator to use for ArrayBuffer memory. |
| 4200 | * The allocator should be set only once. The allocator should be set |
| 4201 | * before any code tha uses ArrayBuffers is executed. |
| 4202 | * This allocator is used in all isolates. |
| 4203 | */ |
| 4204 | static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator); |
| 4205 | |
| 4206 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4207 | * Ignore out-of-memory exceptions. |
| 4208 | * |
| 4209 | * V8 running out of memory is treated as a fatal error by default. |
| 4210 | * This means that the fatal error handler is called and that V8 is |
| 4211 | * terminated. |
| 4212 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4213 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4214 | * out-of-memory situation as a fatal error. This way, the contexts |
| 4215 | * that did not cause the out of memory problem might be able to |
| 4216 | * continue execution. |
| 4217 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4218 | static void IgnoreOutOfMemoryException(); |
| 4219 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4220 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4221 | * 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] | 4222 | * fatal errors such as out-of-memory situations. |
| 4223 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4224 | static bool IsDead(); |
| 4225 | |
| 4226 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4227 | * The following 4 functions are to be used when V8 is built with |
| 4228 | * the 'compress_startup_data' flag enabled. In this case, the |
| 4229 | * embedder must decompress startup data prior to initializing V8. |
| 4230 | * |
| 4231 | * This is how interaction with V8 should look like: |
| 4232 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 4233 | * v8::StartupData* compressed_data = |
| 4234 | * new v8::StartupData[compressed_data_count]; |
| 4235 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 4236 | * ... decompress data (compressed_data can be updated in-place) ... |
| 4237 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 4238 | * ... now V8 can be initialized |
| 4239 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4240 | * |
| 4241 | * A helper class StartupDataDecompressor is provided. It implements |
| 4242 | * the protocol of the interaction described above, and can be used in |
| 4243 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4244 | */ |
| 4245 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 4246 | static int GetCompressedStartupDataCount(); |
| 4247 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 4248 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 4249 | |
| 4250 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4251 | * Adds a message listener. |
| 4252 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4253 | * 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] | 4254 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4255 | * |
| 4256 | * If data is specified, it will be passed to the callback when it is called. |
| 4257 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4258 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4259 | static bool AddMessageListener(MessageCallback that, |
| 4260 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4261 | |
| 4262 | /** |
| 4263 | * Remove all message listeners from the specified callback function. |
| 4264 | */ |
| 4265 | static void RemoveMessageListeners(MessageCallback that); |
| 4266 | |
| 4267 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4268 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 4269 | * and report it to the message listeners. The option is off by default. |
| 4270 | */ |
| 4271 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 4272 | bool capture, |
| 4273 | int frame_limit = 10, |
| 4274 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 4275 | |
| 4276 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4277 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4278 | */ |
| 4279 | static void SetFlagsFromString(const char* str, int length); |
| 4280 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4281 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4282 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4283 | */ |
| 4284 | static void SetFlagsFromCommandLine(int* argc, |
| 4285 | char** argv, |
| 4286 | bool remove_flags); |
| 4287 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4288 | /** Get the version string. */ |
| 4289 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4290 | |
| 4291 | /** |
| 4292 | * Enables the host application to provide a mechanism for recording |
| 4293 | * statistics counters. |
| 4294 | */ |
| 4295 | static void SetCounterFunction(CounterLookupCallback); |
| 4296 | |
| 4297 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4298 | * Enables the host application to provide a mechanism for recording |
| 4299 | * histograms. The CreateHistogram function returns a |
| 4300 | * histogram which will later be passed to the AddHistogramSample |
| 4301 | * function. |
| 4302 | */ |
| 4303 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4304 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4305 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4306 | /** Callback function for reporting failed access checks.*/ |
| 4307 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4308 | |
| 4309 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4310 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4311 | * garbage collection. Allocations are not allowed in the |
| 4312 | * callback function, you therefore cannot manipulate objects (set |
| 4313 | * or delete properties for example) since it is possible such |
| 4314 | * operations will result in the allocation of objects. It is possible |
| 4315 | * to specify the GCType filter for your callback. But it is not possible to |
| 4316 | * register the same callback function two times with different |
| 4317 | * GCType filters. |
| 4318 | */ |
| 4319 | static void AddGCPrologueCallback( |
| 4320 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4321 | |
| 4322 | /** |
| 4323 | * This function removes callback which was installed by |
| 4324 | * AddGCPrologueCallback function. |
| 4325 | */ |
| 4326 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4327 | |
| 4328 | /** |
| 4329 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4330 | * Enables the host application to receive a notification before a |
| 4331 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4332 | * callback function, you therefore cannot manipulate objects (set |
| 4333 | * or delete properties for example) since it is possible such |
| 4334 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4335 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4336 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4337 | |
| 4338 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4339 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4340 | * garbage collection. Allocations are not allowed in the |
| 4341 | * callback function, you therefore cannot manipulate objects (set |
| 4342 | * or delete properties for example) since it is possible such |
| 4343 | * operations will result in the allocation of objects. It is possible |
| 4344 | * to specify the GCType filter for your callback. But it is not possible to |
| 4345 | * register the same callback function two times with different |
| 4346 | * GCType filters. |
| 4347 | */ |
| 4348 | static void AddGCEpilogueCallback( |
| 4349 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4350 | |
| 4351 | /** |
| 4352 | * This function removes callback which was installed by |
| 4353 | * AddGCEpilogueCallback function. |
| 4354 | */ |
| 4355 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4356 | |
| 4357 | /** |
| 4358 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4359 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4360 | * major garbage collection. Allocations are not allowed in the |
| 4361 | * callback function, you therefore cannot manipulate objects (set |
| 4362 | * or delete properties for example) since it is possible such |
| 4363 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4364 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4365 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4366 | |
| 4367 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4368 | * Enables the host application to provide a mechanism to be notified |
| 4369 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4370 | */ |
| 4371 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4372 | ObjectSpace space, |
| 4373 | AllocationAction action); |
| 4374 | |
| 4375 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4376 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4377 | */ |
| 4378 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4379 | |
| 4380 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4381 | * Adds a callback to notify the host application when a script finished |
| 4382 | * running. If a script re-enters the runtime during executing, the |
| 4383 | * CallCompletedCallback is only invoked when the outer-most script |
| 4384 | * execution ends. Executing scripts inside the callback do not trigger |
| 4385 | * further callbacks. |
| 4386 | */ |
| 4387 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4388 | |
| 4389 | /** |
| 4390 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4391 | */ |
| 4392 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4393 | |
| 4394 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4395 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4396 | * initialize from scratch. This function is called implicitly if |
| 4397 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4398 | */ |
| 4399 | static bool Initialize(); |
| 4400 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4401 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4402 | * Allows the host application to provide a callback which can be used |
| 4403 | * as a source of entropy for random number generators. |
| 4404 | */ |
| 4405 | static void SetEntropySource(EntropySource source); |
| 4406 | |
| 4407 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4408 | * Allows the host application to provide a callback that allows v8 to |
| 4409 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4410 | */ |
| 4411 | static void SetReturnAddressLocationResolver( |
| 4412 | ReturnAddressLocationResolver return_address_resolver); |
| 4413 | |
| 4414 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4415 | * Allows the host application to provide the address of a function that's |
| 4416 | * invoked on entry to every V8-generated function. |
| 4417 | * Note that \p entry_hook is invoked at the very start of each |
| 4418 | * generated function. |
| 4419 | * |
| 4420 | * \param entry_hook a function that will be invoked on entry to every |
| 4421 | * V8-generated function. |
| 4422 | * \returns true on success on supported platforms, false on failure. |
| 4423 | * \note Setting a new entry hook function when one is already active will |
| 4424 | * fail. |
| 4425 | */ |
| 4426 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4427 | |
| 4428 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4429 | * Allows the host application to provide the address of a function that is |
| 4430 | * notified each time code is added, moved or removed. |
| 4431 | * |
| 4432 | * \param options options for the JIT code event handler. |
| 4433 | * \param event_handler the JIT code event handler, which will be invoked |
| 4434 | * each time code is added, moved or removed. |
| 4435 | * \note \p event_handler won't get notified of existent code. |
| 4436 | * \note since code removal notifications are not currently issued, the |
| 4437 | * \p event_handler may get notifications of code that overlaps earlier |
| 4438 | * code notifications. This happens when code areas are reused, and the |
| 4439 | * earlier overlapping code areas should therefore be discarded. |
| 4440 | * \note the events passed to \p event_handler and the strings they point to |
| 4441 | * are not guaranteed to live past each call. The \p event_handler must |
| 4442 | * copy strings and other parameters it needs to keep around. |
| 4443 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4444 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4445 | * new members. The \p event_handler function must ignore event codes |
| 4446 | * it does not recognize to maintain future compatibility. |
| 4447 | */ |
| 4448 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4449 | JitCodeEventHandler event_handler); |
| 4450 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4451 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4452 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4453 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4454 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4455 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4456 | /** |
| 4457 | * Suspends recording of tick samples in the profiler. |
| 4458 | * When the V8 profiling mode is enabled (usually via command line |
| 4459 | * switches) this function suspends recording of tick samples. |
| 4460 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4461 | * |
| 4462 | * See also the --prof and --prof_auto command line switches to |
| 4463 | * enable V8 profiling. |
| 4464 | */ |
| 4465 | static void PauseProfiler(); |
| 4466 | |
| 4467 | /** |
| 4468 | * Resumes recording of tick samples in the profiler. |
| 4469 | * See also PauseProfiler(). |
| 4470 | */ |
| 4471 | static void ResumeProfiler(); |
| 4472 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4473 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4474 | * Return whether profiler is currently paused. |
| 4475 | */ |
| 4476 | static bool IsProfilerPaused(); |
| 4477 | |
| 4478 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4479 | * Retrieve the V8 thread id of the calling thread. |
| 4480 | * |
| 4481 | * The thread id for a thread should only be retrieved after the V8 |
| 4482 | * lock has been acquired with a Locker object with that thread. |
| 4483 | */ |
| 4484 | static int GetCurrentThreadId(); |
| 4485 | |
| 4486 | /** |
| 4487 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4488 | * be used to terminate long-running scripts. |
| 4489 | * |
| 4490 | * TerminateExecution should only be called when then V8 lock has |
| 4491 | * been acquired with a Locker object. Therefore, in order to be |
| 4492 | * able to terminate long-running threads, preemption must be |
| 4493 | * enabled to allow the user of TerminateExecution to acquire the |
| 4494 | * lock. |
| 4495 | * |
| 4496 | * The termination is achieved by throwing an exception that is |
| 4497 | * uncatchable by JavaScript exception handlers. Termination |
| 4498 | * 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] | 4499 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4500 | * exception handler that catches an exception should check if that |
| 4501 | * exception is a termination exception and immediately return if |
| 4502 | * that is the case. Returning immediately in that case will |
| 4503 | * continue the propagation of the termination exception if needed. |
| 4504 | * |
| 4505 | * The thread id passed to TerminateExecution must have been |
| 4506 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4507 | * |
| 4508 | * \param thread_id The thread id of the thread to terminate. |
| 4509 | */ |
| 4510 | static void TerminateExecution(int thread_id); |
| 4511 | |
| 4512 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4513 | * Forcefully terminate the current thread of JavaScript execution |
| 4514 | * in the given isolate. If no isolate is provided, the default |
| 4515 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4516 | * |
| 4517 | * This method can be used by any thread even if that thread has not |
| 4518 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4519 | * |
| 4520 | * \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] | 4521 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4522 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4523 | |
| 4524 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4525 | * Is V8 terminating JavaScript execution. |
| 4526 | * |
| 4527 | * Returns true if JavaScript execution is currently terminating |
| 4528 | * because of a call to TerminateExecution. In that case there are |
| 4529 | * still JavaScript frames on the stack and the termination |
| 4530 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4531 | * |
| 4532 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4533 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4534 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4535 | |
| 4536 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4537 | * Resume execution capability in the given isolate, whose execution |
| 4538 | * was previously forcefully terminated using TerminateExecution(). |
| 4539 | * |
| 4540 | * When execution is forcefully terminated using TerminateExecution(), |
| 4541 | * the isolate can not resume execution until all JavaScript frames |
| 4542 | * have propagated the uncatchable exception which is generated. This |
| 4543 | * method allows the program embedding the engine to handle the |
| 4544 | * termination event and resume execution capability, even if |
| 4545 | * JavaScript frames remain on the stack. |
| 4546 | * |
| 4547 | * This method can be used by any thread even if that thread has not |
| 4548 | * acquired the V8 lock with a Locker object. |
| 4549 | * |
| 4550 | * \param isolate The isolate in which to resume execution capability. |
| 4551 | */ |
| 4552 | static void CancelTerminateExecution(Isolate* isolate); |
| 4553 | |
| 4554 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4555 | * Releases any resources used by v8 and stops any utility threads |
| 4556 | * that may be running. Note that disposing v8 is permanent, it |
| 4557 | * cannot be reinitialized. |
| 4558 | * |
| 4559 | * It should generally not be necessary to dispose v8 before exiting |
| 4560 | * a process, this should happen automatically. It is only necessary |
| 4561 | * to use if the process needs the resources taken up by v8. |
| 4562 | */ |
| 4563 | static bool Dispose(); |
| 4564 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4565 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4566 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4567 | |
| 4568 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4569 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4570 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4571 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4572 | */ |
| 4573 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4574 | |
| 4575 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4576 | * Iterates through all the persistent handles in the current isolate's heap |
| 4577 | * that have class_ids. |
| 4578 | */ |
| 4579 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4580 | |
| 4581 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4582 | * Iterates through all the persistent handles in the current isolate's heap |
| 4583 | * that have class_ids and are candidates to be marked as partially dependent |
| 4584 | * handles. This will visit handles to young objects created since the last |
| 4585 | * garbage collection but is free to visit an arbitrary superset of these |
| 4586 | * objects. |
| 4587 | */ |
| 4588 | static void VisitHandlesForPartialDependence( |
| 4589 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4590 | |
| 4591 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4592 | * Optional notification that the embedder is idle. |
| 4593 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4594 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4595 | * Returns true if the embedder should stop calling IdleNotification |
| 4596 | * until real work has been done. This indicates that V8 has done |
| 4597 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4598 | * |
| 4599 | * The hint argument specifies the amount of work to be done in the function |
| 4600 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4601 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4602 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4603 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4604 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4605 | /** |
| 4606 | * Optional notification that the system is running low on memory. |
| 4607 | * V8 uses these notifications to attempt to free memory. |
| 4608 | */ |
| 4609 | static void LowMemoryNotification(); |
| 4610 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4611 | /** |
| 4612 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4613 | * these notifications to guide the GC heuristic. Returns the number |
| 4614 | * of context disposals - including this one - since the last time |
| 4615 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4616 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4617 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4618 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4619 | private: |
| 4620 | V8(); |
| 4621 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4622 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4623 | internal::Object** handle); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4624 | static void DisposeGlobal(internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4625 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4626 | static void MakeWeak(internal::Object** global_handle, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4627 | void* data, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4628 | RevivableCallback weak_reference_callback); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4629 | static void ClearWeak(internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4630 | |
| 4631 | template <class T> friend class Handle; |
| 4632 | template <class T> friend class Local; |
| 4633 | template <class T> friend class Persistent; |
| 4634 | friend class Context; |
| 4635 | }; |
| 4636 | |
| 4637 | |
| 4638 | /** |
| 4639 | * An external exception handler. |
| 4640 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4641 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4642 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4643 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4644 | * Creates a new try/catch block and registers it with v8. Note that |
| 4645 | * all TryCatch blocks should be stack allocated because the memory |
| 4646 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4647 | */ |
| 4648 | TryCatch(); |
| 4649 | |
| 4650 | /** |
| 4651 | * Unregisters and deletes this try/catch block. |
| 4652 | */ |
| 4653 | ~TryCatch(); |
| 4654 | |
| 4655 | /** |
| 4656 | * Returns true if an exception has been caught by this try/catch block. |
| 4657 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4658 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4659 | |
| 4660 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4661 | * 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] | 4662 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4663 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4664 | * cleanup needed and then return. If CanContinue returns false and |
| 4665 | * HasTerminated returns true, it is possible to call |
| 4666 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4667 | */ |
| 4668 | bool CanContinue() const; |
| 4669 | |
| 4670 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4671 | * Returns true if an exception has been caught due to script execution |
| 4672 | * being terminated. |
| 4673 | * |
| 4674 | * There is no JavaScript representation of an execution termination |
| 4675 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4676 | * methods are called to terminate a long-running script. |
| 4677 | * |
| 4678 | * If such an exception has been thrown, HasTerminated will return true, |
| 4679 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4680 | * to continue calling into the engine. |
| 4681 | */ |
| 4682 | bool HasTerminated() const; |
| 4683 | |
| 4684 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4685 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4686 | * it being caught again by this same TryCatch. As with ThrowException |
| 4687 | * it is illegal to execute any JavaScript operations after calling |
| 4688 | * ReThrow; the caller must return immediately to where the exception |
| 4689 | * is caught. |
| 4690 | */ |
| 4691 | Handle<Value> ReThrow(); |
| 4692 | |
| 4693 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4694 | * Returns the exception caught by this try/catch block. If no exception has |
| 4695 | * been caught an empty handle is returned. |
| 4696 | * |
| 4697 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4698 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4699 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4700 | |
| 4701 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4702 | * Returns the .stack property of the thrown object. If no .stack |
| 4703 | * property is present an empty handle is returned. |
| 4704 | */ |
| 4705 | Local<Value> StackTrace() const; |
| 4706 | |
| 4707 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4708 | * Returns the message associated with this exception. If there is |
| 4709 | * no message associated an empty handle is returned. |
| 4710 | * |
| 4711 | * The returned handle is valid until this TryCatch block has been |
| 4712 | * destroyed. |
| 4713 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4714 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4715 | |
| 4716 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4717 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4718 | * After this method has been called, HasCaught() will return false. |
| 4719 | * |
| 4720 | * It is not necessary to clear a try/catch block before using it again; if |
| 4721 | * another exception is thrown the previously caught exception will just be |
| 4722 | * overwritten. However, it is often a good idea since it makes it easier |
| 4723 | * to determine which operation threw a given exception. |
| 4724 | */ |
| 4725 | void Reset(); |
| 4726 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4727 | /** |
| 4728 | * Set verbosity of the external exception handler. |
| 4729 | * |
| 4730 | * By default, exceptions that are caught by an external exception |
| 4731 | * handler are not reported. Call SetVerbose with true on an |
| 4732 | * external exception handler to have exceptions caught by the |
| 4733 | * handler reported as if they were not caught. |
| 4734 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4735 | void SetVerbose(bool value); |
| 4736 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4737 | /** |
| 4738 | * Set whether or not this TryCatch should capture a Message object |
| 4739 | * which holds source information about where the exception |
| 4740 | * occurred. True by default. |
| 4741 | */ |
| 4742 | void SetCaptureMessage(bool value); |
| 4743 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4744 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4745 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4746 | TryCatch(const TryCatch&); |
| 4747 | void operator=(const TryCatch&); |
| 4748 | void* operator new(size_t size); |
| 4749 | void operator delete(void*, size_t); |
| 4750 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4751 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4752 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4753 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4754 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4755 | bool is_verbose_ : 1; |
| 4756 | bool can_continue_ : 1; |
| 4757 | bool capture_message_ : 1; |
| 4758 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4759 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4760 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4761 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4762 | }; |
| 4763 | |
| 4764 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4765 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4766 | |
| 4767 | |
| 4768 | /** |
| 4769 | * Ignore |
| 4770 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4771 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4772 | public: |
| 4773 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4774 | : name_count_(name_count), names_(names) { } |
| 4775 | private: |
| 4776 | friend class ImplementationUtilities; |
| 4777 | int name_count_; |
| 4778 | const char** names_; |
| 4779 | }; |
| 4780 | |
| 4781 | |
| 4782 | /** |
| 4783 | * A sandboxed execution context with its own set of built-in objects |
| 4784 | * and functions. |
| 4785 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4786 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4787 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4788 | /** |
| 4789 | * Returns the global proxy object or global object itself for |
| 4790 | * detached contexts. |
| 4791 | * |
| 4792 | * Global proxy object is a thin wrapper whose prototype points to |
| 4793 | * actual context's global object with the properties like Object, etc. |
| 4794 | * This is done that way for security reasons (for more details see |
| 4795 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4796 | * |
| 4797 | * Please note that changes to global proxy object prototype most probably |
| 4798 | * would break VM---v8 expects only global object as a prototype of |
| 4799 | * global proxy object. |
| 4800 | * |
| 4801 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4802 | * object until global is reattached with ReattachGlobal(). |
| 4803 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4804 | Local<Object> Global(); |
| 4805 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4806 | /** |
| 4807 | * Detaches the global object from its context before |
| 4808 | * the global object can be reused to create a new context. |
| 4809 | */ |
| 4810 | void DetachGlobal(); |
| 4811 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4812 | /** |
| 4813 | * Reattaches a global object to a context. This can be used to |
| 4814 | * restore the connection between a global object and a context |
| 4815 | * after DetachGlobal has been called. |
| 4816 | * |
| 4817 | * \param global_object The global object to reattach to the |
| 4818 | * context. For this to work, the global object must be the global |
| 4819 | * object that was associated with this context before a call to |
| 4820 | * DetachGlobal. |
| 4821 | */ |
| 4822 | void ReattachGlobal(Handle<Object> global_object); |
| 4823 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4824 | /** |
| 4825 | * Creates a new context and returns a handle to the newly allocated |
| 4826 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4827 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4828 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4829 | * |
| 4830 | * \param extensions An optional extension configuration containing |
| 4831 | * the extensions to be installed in the newly created context. |
| 4832 | * |
| 4833 | * \param global_template An optional object template from which the |
| 4834 | * global object for the newly created context will be created. |
| 4835 | * |
| 4836 | * \param global_object An optional global object to be reused for |
| 4837 | * the newly created context. This global object must have been |
| 4838 | * created by a previous call to Context::New with the same global |
| 4839 | * template. The state of the global object will be completely reset |
| 4840 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4841 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4842 | static Local<Context> New( |
| 4843 | Isolate* isolate, |
| 4844 | ExtensionConfiguration* extensions = NULL, |
| 4845 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4846 | Handle<Value> global_object = Handle<Value>()); |
| 4847 | |
| 4848 | /** Deprecated. Use Isolate version instead. */ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4849 | V8_DEPRECATED(static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4850 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4851 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4852 | Handle<Value> global_object = Handle<Value>())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4854 | /** Returns the last entered context. */ |
| 4855 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4856 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4857 | // TODO(svenpanne) Actually deprecate this. |
| 4858 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4859 | static Local<Context> GetCurrent(); |
| 4860 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4861 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4862 | * Returns the context of the calling JavaScript code. That is the |
| 4863 | * context of the top-most JavaScript frame. If there are no |
| 4864 | * JavaScript frames an empty handle is returned. |
| 4865 | */ |
| 4866 | static Local<Context> GetCalling(); |
| 4867 | |
| 4868 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4869 | * Sets the security token for the context. To access an object in |
| 4870 | * another context, the security tokens must match. |
| 4871 | */ |
| 4872 | void SetSecurityToken(Handle<Value> token); |
| 4873 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4874 | /** Restores the security token to the default value. */ |
| 4875 | void UseDefaultSecurityToken(); |
| 4876 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4877 | /** Returns the security token of this context.*/ |
| 4878 | Handle<Value> GetSecurityToken(); |
| 4879 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4880 | /** |
| 4881 | * Enter this context. After entering a context, all code compiled |
| 4882 | * and run is compiled and run in this context. If another context |
| 4883 | * is already entered, this old context is saved so it can be |
| 4884 | * restored when the new context is exited. |
| 4885 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4886 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4887 | |
| 4888 | /** |
| 4889 | * Exit this context. Exiting the current context restores the |
| 4890 | * context that was in place when entering the current context. |
| 4891 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4892 | void Exit(); |
| 4893 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4894 | /** 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] | 4895 | bool HasOutOfMemoryException(); |
| 4896 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4897 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4898 | static bool InContext(); |
| 4899 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4900 | /** Returns an isolate associated with a current context. */ |
| 4901 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4902 | |
| 4903 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4904 | * Gets the embedder data with the given index, which must have been set by a |
| 4905 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4906 | * currently has a special meaning for Chrome's debugger. |
| 4907 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4908 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4909 | |
| 4910 | /** |
| 4911 | * Sets the embedder data with the given index, growing the data as |
| 4912 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4913 | * debugger. |
| 4914 | */ |
| 4915 | void SetEmbedderData(int index, Handle<Value> value); |
| 4916 | |
| 4917 | /** |
| 4918 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4919 | * index, which must have bees set by a previous call to |
| 4920 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4921 | * currently has a special meaning for Chrome's debugger. |
| 4922 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4923 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4924 | |
| 4925 | /** |
| 4926 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4927 | * index, growing the data as needed. Note that index 0 currently has a |
| 4928 | * special meaning for Chrome's debugger. |
| 4929 | */ |
| 4930 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4931 | |
| 4932 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4933 | * Control whether code generation from strings is allowed. Calling |
| 4934 | * this method with false will disable 'eval' and the 'Function' |
| 4935 | * constructor for code running in this context. If 'eval' or the |
| 4936 | * 'Function' constructor are used an exception will be thrown. |
| 4937 | * |
| 4938 | * If code generation from strings is not allowed the |
| 4939 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4940 | * set before blocking the call to 'eval' or the 'Function' |
| 4941 | * constructor. If that callback returns true, the call will be |
| 4942 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4943 | * set an exception will be thrown. |
| 4944 | */ |
| 4945 | void AllowCodeGenerationFromStrings(bool allow); |
| 4946 | |
| 4947 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4948 | * Returns true if code generation from strings is allowed for the context. |
| 4949 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4950 | */ |
| 4951 | bool IsCodeGenerationFromStringsAllowed(); |
| 4952 | |
| 4953 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4954 | * Sets the error description for the exception that is thrown when |
| 4955 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4956 | * constructor are called. |
| 4957 | */ |
| 4958 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4959 | |
| 4960 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4961 | * Stack-allocated class which sets the execution context for all |
| 4962 | * operations executed within a local scope. |
| 4963 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4964 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4965 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4966 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4967 | context_->Enter(); |
| 4968 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 4969 | // TODO(dcarney): deprecate |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4970 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4971 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4972 | : context_(Handle<Context>::New(isolate, context)) { |
| 4973 | #else |
| 4974 | : context_(Local<Context>::New(isolate, context)) { |
| 4975 | #endif |
| 4976 | context_->Enter(); |
| 4977 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4978 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4979 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4980 | private: |
| 4981 | Handle<Context> context_; |
| 4982 | }; |
| 4983 | |
| 4984 | private: |
| 4985 | friend class Value; |
| 4986 | friend class Script; |
| 4987 | friend class Object; |
| 4988 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4989 | |
| 4990 | Local<Value> SlowGetEmbedderData(int index); |
| 4991 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4992 | }; |
| 4993 | |
| 4994 | |
| 4995 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4996 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4997 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4998 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4999 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 5000 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 5001 | * constraint is not violated. In addition to any other synchronization |
| 5002 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 5003 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5004 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5005 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 5006 | * construction and destruction, the current thread is allowed to use the locked |
| 5007 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 5008 | * 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] | 5009 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5010 | * Sample usage: |
| 5011 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5012 | * ... |
| 5013 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5014 | * v8::Locker locker(isolate); |
| 5015 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5017 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5018 | * ... |
| 5019 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5020 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5021 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5022 | * If you wish to stop using V8 in a thread A you can do this either by |
| 5023 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 5024 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5025 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5026 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5027 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5028 | * isolate->Exit(); |
| 5029 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5030 | * ... |
| 5031 | * // Code not using V8 goes here while V8 can run in another thread. |
| 5032 | * ... |
| 5033 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5034 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5035 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5036 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5037 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 5038 | * 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] | 5039 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5040 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 5041 | * given thread. This can be useful if you have code that can be called either |
| 5042 | * from code that holds the lock or from code that does not. The Unlocker is |
| 5043 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 5044 | * 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] | 5045 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5046 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 5047 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5048 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5049 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5050 | * // V8 not locked. |
| 5051 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5052 | * v8::Locker locker(isolate); |
| 5053 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5054 | * // V8 locked. |
| 5055 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5056 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5057 | * // V8 still locked (2 levels). |
| 5058 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5059 | * isolate->Exit(); |
| 5060 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | * // V8 not locked. |
| 5062 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5063 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5064 | * // V8 locked again (2 levels). |
| 5065 | * } |
| 5066 | * // V8 still locked (1 level). |
| 5067 | * } |
| 5068 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5069 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5070 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5071 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5072 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5073 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5074 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5075 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5076 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 5077 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5078 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5079 | V8_DEPRECATED(Unlocker()); |
| 5080 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5081 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5082 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5083 | void Initialize(Isolate* isolate); |
| 5084 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5085 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5086 | }; |
| 5087 | |
| 5088 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5089 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5090 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5091 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5092 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5093 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5094 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 5095 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5096 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5097 | V8_DEPRECATED(Locker()); |
| 5098 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5099 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5100 | |
| 5101 | /** |
| 5102 | * Start preemption. |
| 5103 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5104 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5105 | * that will switch between multiple threads that are in contention |
| 5106 | * for the V8 lock. |
| 5107 | */ |
| 5108 | static void StartPreemption(int every_n_ms); |
| 5109 | |
| 5110 | /** |
| 5111 | * Stop preemption. |
| 5112 | */ |
| 5113 | static void StopPreemption(); |
| 5114 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5115 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5116 | * Returns whether or not the locker for a given isolate, is locked by the |
| 5117 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5118 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5119 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5120 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5121 | /** |
| 5122 | * Returns whether v8::Locker is being used by this V8 instance. |
| 5123 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5124 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5125 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5126 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5127 | void Initialize(Isolate* isolate); |
| 5128 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5129 | bool has_lock_; |
| 5130 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5131 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5132 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5133 | static bool active_; |
| 5134 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5135 | // Disallow copying and assigning. |
| 5136 | Locker(const Locker&); |
| 5137 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5138 | }; |
| 5139 | |
| 5140 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5141 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5142 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 5143 | */ |
| 5144 | struct HeapStatsUpdate; |
| 5145 | |
| 5146 | |
| 5147 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5148 | * An interface for exporting data from V8, using "push" model. |
| 5149 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5150 | class V8EXPORT OutputStream { // NOLINT |
| 5151 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5152 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5153 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5154 | }; |
| 5155 | enum WriteResult { |
| 5156 | kContinue = 0, |
| 5157 | kAbort = 1 |
| 5158 | }; |
| 5159 | virtual ~OutputStream() {} |
| 5160 | /** Notify about the end of stream. */ |
| 5161 | virtual void EndOfStream() = 0; |
| 5162 | /** Get preferred output chunk size. Called only once. */ |
| 5163 | virtual int GetChunkSize() { return 1024; } |
| 5164 | /** Get preferred output encoding. Called only once. */ |
| 5165 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 5166 | /** |
| 5167 | * Writes the next chunk of snapshot data into the stream. Writing |
| 5168 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5169 | * will not be called in case writing was aborted. |
| 5170 | */ |
| 5171 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5172 | /** |
| 5173 | * Writes the next chunk of heap stats data into the stream. Writing |
| 5174 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5175 | * will not be called in case writing was aborted. |
| 5176 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5177 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 5178 | return kAbort; |
| 5179 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5180 | }; |
| 5181 | |
| 5182 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5183 | /** |
| 5184 | * An interface for reporting progress and controlling long-running |
| 5185 | * activities. |
| 5186 | */ |
| 5187 | class V8EXPORT ActivityControl { // NOLINT |
| 5188 | public: |
| 5189 | enum ControlOption { |
| 5190 | kContinue = 0, |
| 5191 | kAbort = 1 |
| 5192 | }; |
| 5193 | virtual ~ActivityControl() {} |
| 5194 | /** |
| 5195 | * Notify about current progress. The activity can be stopped by |
| 5196 | * returning kAbort as the callback result. |
| 5197 | */ |
| 5198 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 5199 | }; |
| 5200 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5201 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5202 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5203 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5204 | |
| 5205 | namespace internal { |
| 5206 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5207 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 5208 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5209 | |
| 5210 | // Tag information for HeapObject. |
| 5211 | const int kHeapObjectTag = 1; |
| 5212 | const int kHeapObjectTagSize = 2; |
| 5213 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 5214 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5215 | // Tag information for Smi. |
| 5216 | const int kSmiTag = 0; |
| 5217 | const int kSmiTagSize = 1; |
| 5218 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 5219 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5220 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5221 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5222 | template<int kSmiShiftSize> |
| 5223 | V8_INLINE(internal::Object* IntToSmi(int value)) { |
| 5224 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5225 | intptr_t tagged_value = |
| 5226 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
| 5227 | return reinterpret_cast<internal::Object*>(tagged_value); |
| 5228 | } |
| 5229 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5230 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5231 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5232 | static const int kSmiShiftSize = 0; |
| 5233 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5234 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5235 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5236 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 5237 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 5238 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5239 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5240 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5241 | } |
| 5242 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5243 | // To be representable as an tagged small integer, the two |
| 5244 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 5245 | // sign-extension. To check this we add 01 to the two |
| 5246 | // most-significant bits, and check if the most-significant bit is 0 |
| 5247 | // |
| 5248 | // CAUTION: The original code below: |
| 5249 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 5250 | // may lead to incorrect results according to the C language spec, and |
| 5251 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 5252 | // compiler may produce undefined results in case of signed integer |
| 5253 | // overflow. The computation must be done w/ unsigned ints. |
| 5254 | return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; |
| 5255 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5256 | }; |
| 5257 | |
| 5258 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5259 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5260 | static const int kSmiShiftSize = 31; |
| 5261 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5262 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5263 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5264 | // Shift down and throw away top 32 bits. |
| 5265 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5266 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5267 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5268 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5269 | } |
| 5270 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5271 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 5272 | return (value == static_cast<int32_t>(value)); |
| 5273 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5274 | }; |
| 5275 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5276 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5277 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5278 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5279 | |
| 5280 | /** |
| 5281 | * This class exports constants and functionality from within v8 that |
| 5282 | * is necessary to implement inline functions in the v8 api. Don't |
| 5283 | * depend on functions and constants defined here. |
| 5284 | */ |
| 5285 | class Internals { |
| 5286 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5287 | // These values match non-compiler-dependent values defined within |
| 5288 | // the implementation of v8. |
| 5289 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5290 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5291 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5292 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5293 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5294 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5295 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5296 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5297 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5298 | static const int kContextEmbedderDataIndex = 64; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5299 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5300 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5301 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5302 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5303 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5304 | static const int kIsolateStateOffset = 0; |
| 5305 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5306 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5307 | static const int kUndefinedValueRootIndex = 5; |
| 5308 | static const int kNullValueRootIndex = 7; |
| 5309 | static const int kTrueValueRootIndex = 8; |
| 5310 | static const int kFalseValueRootIndex = 9; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5311 | static const int kEmptyStringRootIndex = 131; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5312 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5313 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5314 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5315 | static const int kNodeStateMask = 0xf; |
| 5316 | static const int kNodeStateIsWeakValue = 2; |
| 5317 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5318 | static const int kNodeIsIndependentShift = 4; |
| 5319 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5320 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5321 | static const int kJSObjectType = 0xb0; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5322 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5323 | static const int kOddballType = 0x83; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5324 | static const int kForeignType = 0x88; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5325 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5326 | static const int kUndefinedOddballKind = 5; |
| 5327 | static const int kNullOddballKind = 3; |
| 5328 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5329 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5330 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5331 | kHeapObjectTag); |
| 5332 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5333 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5334 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5335 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5338 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5339 | return PlatformSmiTagging::IntToSmi(value); |
| 5340 | } |
| 5341 | |
| 5342 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5343 | return PlatformSmiTagging::IsValidSmi(value); |
| 5344 | } |
| 5345 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5346 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5347 | typedef internal::Object O; |
| 5348 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5349 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5350 | } |
| 5351 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5352 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5353 | typedef internal::Object O; |
| 5354 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5355 | } |
| 5356 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5357 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5358 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5359 | return representation == kExternalTwoByteRepresentationTag; |
| 5360 | } |
| 5361 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5362 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5363 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5364 | return *reinterpret_cast<int*>(addr) == 1; |
| 5365 | } |
| 5366 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5367 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5368 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5369 | return *addr & (1 << shift); |
| 5370 | } |
| 5371 | |
| 5372 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5373 | bool value, int shift)) { |
| 5374 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5375 | uint8_t mask = 1 << shift; |
| 5376 | *addr = (*addr & ~mask) | (value << shift); |
| 5377 | } |
| 5378 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5379 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5380 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5381 | return *addr & kNodeStateMask; |
| 5382 | } |
| 5383 | |
| 5384 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5385 | uint8_t value)) { |
| 5386 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5387 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5388 | } |
| 5389 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5390 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5391 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5392 | kIsolateEmbedderDataOffset; |
| 5393 | *reinterpret_cast<void**>(addr) = data; |
| 5394 | } |
| 5395 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5396 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5397 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5398 | kIsolateEmbedderDataOffset; |
| 5399 | return *reinterpret_cast<void**>(addr); |
| 5400 | } |
| 5401 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5402 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5403 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5404 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5405 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5406 | } |
| 5407 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5408 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5409 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5410 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5411 | return *reinterpret_cast<T*>(addr); |
| 5412 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5413 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5414 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5415 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5416 | typedef internal::Object O; |
| 5417 | typedef internal::Internals I; |
| 5418 | O* ctx = *reinterpret_cast<O**>(context); |
| 5419 | int embedder_data_offset = I::kContextHeaderSize + |
| 5420 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5421 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5422 | int value_offset = |
| 5423 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5424 | return I::ReadField<T>(embedder_data, value_offset); |
| 5425 | } |
| 5426 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5427 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5428 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5429 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5430 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5431 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5432 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5433 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5434 | }; |
| 5435 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5436 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5437 | |
| 5438 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5439 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5440 | Local<T>::Local() : Handle<T>() { } |
| 5441 | |
| 5442 | |
| 5443 | template <class T> |
| 5444 | Local<T> Local<T>::New(Handle<T> that) { |
| 5445 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5446 | T* that_ptr = *that; |
| 5447 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5448 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5449 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5450 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5451 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5452 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5453 | } |
| 5454 | |
| 5455 | |
| 5456 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5457 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5458 | return New(isolate, that.val_); |
| 5459 | } |
| 5460 | |
| 5461 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5462 | template <class T> |
| 5463 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5464 | return New(isolate, that.val_); |
| 5465 | } |
| 5466 | |
| 5467 | template <class T> |
| 5468 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5469 | if (that == NULL) return Handle<T>(); |
| 5470 | T* that_ptr = that; |
| 5471 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5472 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5473 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5474 | } |
| 5475 | #endif |
| 5476 | |
| 5477 | |
| 5478 | template <class T> |
| 5479 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5480 | if (that == NULL) return Local<T>(); |
| 5481 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5482 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5483 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5484 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5485 | } |
| 5486 | |
| 5487 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5488 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5489 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5490 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5491 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | template <class T> |
| 5496 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5497 | return New(Isolate::GetCurrent(), that.val_); |
| 5498 | } |
| 5499 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5500 | template <class T> |
| 5501 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5502 | return New(Isolate::GetCurrent(), that.val_); |
| 5503 | } |
| 5504 | #endif |
| 5505 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5506 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5507 | template <class T> |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5508 | T* Persistent<T>::New(Isolate* isolate, T* that) { |
| 5509 | if (that == NULL) return NULL; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5510 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5511 | return reinterpret_cast<T*>( |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5512 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5513 | p)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | |
| 5517 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5518 | bool Persistent<T>::IsIndependent() const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5519 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5520 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5521 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5522 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | |
| 5526 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5527 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5528 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5529 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5530 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5531 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | |
| 5535 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5536 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5537 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5538 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5539 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5540 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | |
| 5544 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5545 | void Persistent<T>::Dispose() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5546 | if (this->IsEmpty()) return; |
| 5547 | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); |
| 5548 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5549 | val_ = 0; |
| 5550 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | |
| 5554 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5555 | template <typename S, typename P> |
| 5556 | void Persistent<T>::MakeWeak( |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5557 | P* parameters, |
| 5558 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5559 | TYPE_CHECK(S, T); |
| 5560 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5561 | V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5562 | parameters, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5563 | reinterpret_cast<Revivable>(callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5566 | |
| 5567 | template <class T> |
| 5568 | template <typename P> |
| 5569 | void Persistent<T>::MakeWeak( |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5570 | P* parameters, |
| 5571 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5572 | MakeWeak<T, P>(parameters, callback); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5576 | template <class T> |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5577 | template <typename S, typename P> |
| 5578 | void Persistent<T>::MakeWeak( |
| 5579 | Isolate* isolate, |
| 5580 | P* parameters, |
| 5581 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5582 | MakeWeak<S, P>(parameters, callback); |
| 5583 | } |
| 5584 | |
| 5585 | |
| 5586 | template <class T> |
| 5587 | template<typename P> |
| 5588 | void Persistent<T>::MakeWeak( |
| 5589 | Isolate* isolate, |
| 5590 | P* parameters, |
| 5591 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5592 | MakeWeak<P>(parameters, callback); |
| 5593 | } |
| 5594 | |
| 5595 | |
| 5596 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5597 | void Persistent<T>::ClearWeak() { |
| 5598 | V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5601 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5602 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5603 | void Persistent<T>::MarkIndependent() { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5604 | typedef internal::Internals I; |
| 5605 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5606 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5607 | true, |
| 5608 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5611 | |
| 5612 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5613 | void Persistent<T>::MarkPartiallyDependent() { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5614 | typedef internal::Internals I; |
| 5615 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5616 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5617 | true, |
| 5618 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5619 | } |
| 5620 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5621 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5622 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5623 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5624 | Dispose(isolate); |
| 5625 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5626 | *this = *New(isolate, other); |
| 5627 | #else |
| 5628 | if (other.IsEmpty()) { |
| 5629 | this->val_ = NULL; |
| 5630 | return; |
| 5631 | } |
| 5632 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5633 | this->val_ = reinterpret_cast<T*>( |
| 5634 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5635 | #endif |
| 5636 | } |
| 5637 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5638 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5639 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5640 | template <class T> |
| 5641 | void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { |
| 5642 | Dispose(isolate); |
| 5643 | if (other.IsEmpty()) { |
| 5644 | this->val_ = NULL; |
| 5645 | return; |
| 5646 | } |
| 5647 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5648 | this->val_ = reinterpret_cast<T*>( |
| 5649 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5650 | } |
| 5651 | #endif |
| 5652 | |
| 5653 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5654 | template <class T> |
| 5655 | T* Persistent<T>::ClearAndLeak() { |
| 5656 | T* old; |
| 5657 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5658 | old = **this; |
| 5659 | *this = Persistent<T>(); |
| 5660 | #else |
| 5661 | old = val_; |
| 5662 | val_ = NULL; |
| 5663 | #endif |
| 5664 | return old; |
| 5665 | } |
| 5666 | |
| 5667 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5668 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5669 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5670 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5671 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5672 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5673 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5674 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5675 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5676 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5677 | |
| 5678 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5679 | uint16_t Persistent<T>::WrapperClassId() const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5680 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5681 | if (this->IsEmpty()) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5682 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5683 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5684 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5685 | } |
| 5686 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5687 | |
| 5688 | template<typename T> |
| 5689 | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| 5690 | |
| 5691 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5692 | template<typename S> |
| 5693 | void ReturnValue<T>::Set(const Persistent<S>& handle) { |
| 5694 | TYPE_CHECK(T, S); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5695 | if (V8_UNLIKELY(handle.IsEmpty())) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 5696 | *value_ = GetDefaultValue(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5697 | } else { |
| 5698 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5699 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5703 | template<typename S> |
| 5704 | void ReturnValue<T>::Set(const Handle<S> handle) { |
| 5705 | TYPE_CHECK(T, S); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5706 | if (V8_UNLIKELY(handle.IsEmpty())) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 5707 | *value_ = GetDefaultValue(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5708 | } else { |
| 5709 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5710 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5714 | void ReturnValue<T>::Set(double i) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5715 | TYPE_CHECK(T, Number); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5716 | Set(Number::New(GetIsolate(), i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5720 | void ReturnValue<T>::Set(int32_t i) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5721 | TYPE_CHECK(T, Integer); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5722 | typedef internal::Internals I; |
| 5723 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5724 | *value_ = I::IntToSmi(i); |
| 5725 | return; |
| 5726 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5727 | Set(Integer::New(i, GetIsolate())); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5731 | void ReturnValue<T>::Set(uint32_t i) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5732 | TYPE_CHECK(T, Integer); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5733 | typedef internal::Internals I; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5734 | // Can't simply use INT32_MAX here for whatever reason. |
| 5735 | bool fits_into_int32_t = (i & (1 << 31)) == 0; |
| 5736 | if (V8_LIKELY(fits_into_int32_t)) { |
| 5737 | Set(static_cast<int32_t>(i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5738 | return; |
| 5739 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5740 | Set(Integer::NewFromUnsigned(i, GetIsolate())); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5744 | void ReturnValue<T>::Set(bool value) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5745 | TYPE_CHECK(T, Boolean); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5746 | typedef internal::Internals I; |
| 5747 | int root_index; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5748 | if (value) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5749 | root_index = I::kTrueValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5750 | } else { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5751 | root_index = I::kFalseValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5752 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5753 | *value_ = *I::GetRoot(GetIsolate(), root_index); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5757 | void ReturnValue<T>::SetNull() { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5758 | TYPE_CHECK(T, Primitive); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5759 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5760 | *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5764 | void ReturnValue<T>::SetUndefined() { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5765 | TYPE_CHECK(T, Primitive); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5766 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5767 | *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | template<typename T> |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5771 | void ReturnValue<T>::SetEmptyString() { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame^] | 5772 | TYPE_CHECK(T, String); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5773 | typedef internal::Internals I; |
| 5774 | *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); |
| 5775 | } |
| 5776 | |
| 5777 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5778 | Isolate* ReturnValue<T>::GetIsolate() { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 5779 | // Isolate is always the pointer below the default value on the stack. |
| 5780 | return *reinterpret_cast<Isolate**>(&value_[-2]); |
| 5781 | } |
| 5782 | |
| 5783 | template<typename T> |
| 5784 | internal::Object* ReturnValue<T>::GetDefaultValue() { |
| 5785 | // Default value is always the pointer below value_ on the stack. |
| 5786 | return value_[-1]; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | |
| 5790 | template<typename T> |
| 5791 | FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, |
| 5792 | internal::Object** values, |
| 5793 | int length, |
| 5794 | bool is_construct_call) |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5795 | : implicit_args_(implicit_args), |
| 5796 | values_(values), |
| 5797 | length_(length), |
| 5798 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5799 | |
| 5800 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5801 | Arguments::Arguments(internal::Object** args, |
| 5802 | internal::Object** values, |
| 5803 | int length, |
| 5804 | bool is_construct_call) |
| 5805 | : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { } |
| 5806 | |
| 5807 | |
| 5808 | template<typename T> |
| 5809 | Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5810 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5811 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5812 | } |
| 5813 | |
| 5814 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5815 | template<typename T> |
| 5816 | Local<Function> FunctionCallbackInfo<T>::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5817 | return Local<Function>(reinterpret_cast<Function*>( |
| 5818 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5822 | template<typename T> |
| 5823 | Local<Object> FunctionCallbackInfo<T>::This() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5824 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5825 | } |
| 5826 | |
| 5827 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5828 | template<typename T> |
| 5829 | Local<Object> FunctionCallbackInfo<T>::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5830 | return Local<Object>(reinterpret_cast<Object*>( |
| 5831 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5835 | template<typename T> |
| 5836 | Local<Value> FunctionCallbackInfo<T>::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5837 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5841 | template<typename T> |
| 5842 | Isolate* FunctionCallbackInfo<T>::GetIsolate() const { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5843 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5844 | } |
| 5845 | |
| 5846 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5847 | template<typename T> |
| 5848 | ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const { |
| 5849 | return ReturnValue<T>(&implicit_args_[kReturnValueIndex]); |
| 5850 | } |
| 5851 | |
| 5852 | |
| 5853 | template<typename T> |
| 5854 | bool FunctionCallbackInfo<T>::IsConstructCall() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5855 | return is_construct_call_; |
| 5856 | } |
| 5857 | |
| 5858 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5859 | template<typename T> |
| 5860 | int FunctionCallbackInfo<T>::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5861 | return length_; |
| 5862 | } |
| 5863 | |
| 5864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5865 | template <class T> |
| 5866 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5867 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5868 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5869 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5870 | } |
| 5871 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5872 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5873 | return resource_name_; |
| 5874 | } |
| 5875 | |
| 5876 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5877 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5878 | return resource_line_offset_; |
| 5879 | } |
| 5880 | |
| 5881 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5882 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5883 | return resource_column_offset_; |
| 5884 | } |
| 5885 | |
| 5886 | |
| 5887 | Handle<Boolean> Boolean::New(bool value) { |
| 5888 | return value ? True() : False(); |
| 5889 | } |
| 5890 | |
| 5891 | |
| 5892 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5893 | Set(v8::String::New(name), value); |
| 5894 | } |
| 5895 | |
| 5896 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5897 | Local<Value> Object::GetInternalField(int index) { |
| 5898 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5899 | typedef internal::Object O; |
| 5900 | typedef internal::Internals I; |
| 5901 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5902 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5903 | // 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] | 5904 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5905 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5906 | O* value = I::ReadField<O*>(obj, offset); |
| 5907 | O** result = HandleScope::CreateHandle(value); |
| 5908 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5909 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5910 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5911 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5915 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5916 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5917 | typedef internal::Object O; |
| 5918 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5919 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5920 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5921 | // 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] | 5922 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5923 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5924 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5925 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5926 | #endif |
| 5927 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | |
| 5931 | String* String::Cast(v8::Value* value) { |
| 5932 | #ifdef V8_ENABLE_CHECKS |
| 5933 | CheckCast(value); |
| 5934 | #endif |
| 5935 | return static_cast<String*>(value); |
| 5936 | } |
| 5937 | |
| 5938 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5939 | Local<String> String::Empty(Isolate* isolate) { |
| 5940 | typedef internal::Object* S; |
| 5941 | typedef internal::Internals I; |
| 5942 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5943 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5944 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5945 | } |
| 5946 | |
| 5947 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5948 | Local<String> String::New(const char* data, int length) { |
| 5949 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5950 | } |
| 5951 | |
| 5952 | |
| 5953 | Local<String> String::New(const uint16_t* data, int length) { |
| 5954 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5955 | } |
| 5956 | |
| 5957 | |
| 5958 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5959 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5960 | } |
| 5961 | |
| 5962 | |
| 5963 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5964 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5965 | } |
| 5966 | |
| 5967 | |
| 5968 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5969 | return NewFromTwoByte( |
| 5970 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5971 | } |
| 5972 | |
| 5973 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5974 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5975 | typedef internal::Object O; |
| 5976 | typedef internal::Internals I; |
| 5977 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5978 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5979 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5980 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5981 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5982 | } else { |
| 5983 | result = NULL; |
| 5984 | } |
| 5985 | #ifdef V8_ENABLE_CHECKS |
| 5986 | VerifyExternalStringResource(result); |
| 5987 | #endif |
| 5988 | return result; |
| 5989 | } |
| 5990 | |
| 5991 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5992 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5993 | String::Encoding* encoding_out) const { |
| 5994 | typedef internal::Object O; |
| 5995 | typedef internal::Internals I; |
| 5996 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5997 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5998 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5999 | ExternalStringResourceBase* resource = NULL; |
| 6000 | if (type == I::kExternalAsciiRepresentationTag || |
| 6001 | type == I::kExternalTwoByteRepresentationTag) { |
| 6002 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 6003 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 6004 | } |
| 6005 | #ifdef V8_ENABLE_CHECKS |
| 6006 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 6007 | #endif |
| 6008 | return resource; |
| 6009 | } |
| 6010 | |
| 6011 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 6012 | bool Value::IsUndefined() const { |
| 6013 | #ifdef V8_ENABLE_CHECKS |
| 6014 | return FullIsUndefined(); |
| 6015 | #else |
| 6016 | return QuickIsUndefined(); |
| 6017 | #endif |
| 6018 | } |
| 6019 | |
| 6020 | bool Value::QuickIsUndefined() const { |
| 6021 | typedef internal::Object O; |
| 6022 | typedef internal::Internals I; |
| 6023 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6024 | if (!I::HasHeapObjectTag(obj)) return false; |
| 6025 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 6026 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 6027 | } |
| 6028 | |
| 6029 | |
| 6030 | bool Value::IsNull() const { |
| 6031 | #ifdef V8_ENABLE_CHECKS |
| 6032 | return FullIsNull(); |
| 6033 | #else |
| 6034 | return QuickIsNull(); |
| 6035 | #endif |
| 6036 | } |
| 6037 | |
| 6038 | bool Value::QuickIsNull() const { |
| 6039 | typedef internal::Object O; |
| 6040 | typedef internal::Internals I; |
| 6041 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6042 | if (!I::HasHeapObjectTag(obj)) return false; |
| 6043 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 6044 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 6045 | } |
| 6046 | |
| 6047 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6048 | bool Value::IsString() const { |
| 6049 | #ifdef V8_ENABLE_CHECKS |
| 6050 | return FullIsString(); |
| 6051 | #else |
| 6052 | return QuickIsString(); |
| 6053 | #endif |
| 6054 | } |
| 6055 | |
| 6056 | bool Value::QuickIsString() const { |
| 6057 | typedef internal::Object O; |
| 6058 | typedef internal::Internals I; |
| 6059 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6060 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6061 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 6065 | template <class T> Value* Value::Cast(T* value) { |
| 6066 | return static_cast<Value*>(value); |
| 6067 | } |
| 6068 | |
| 6069 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6070 | Symbol* Symbol::Cast(v8::Value* value) { |
| 6071 | #ifdef V8_ENABLE_CHECKS |
| 6072 | CheckCast(value); |
| 6073 | #endif |
| 6074 | return static_cast<Symbol*>(value); |
| 6075 | } |
| 6076 | |
| 6077 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6078 | Number* Number::Cast(v8::Value* value) { |
| 6079 | #ifdef V8_ENABLE_CHECKS |
| 6080 | CheckCast(value); |
| 6081 | #endif |
| 6082 | return static_cast<Number*>(value); |
| 6083 | } |
| 6084 | |
| 6085 | |
| 6086 | Integer* Integer::Cast(v8::Value* value) { |
| 6087 | #ifdef V8_ENABLE_CHECKS |
| 6088 | CheckCast(value); |
| 6089 | #endif |
| 6090 | return static_cast<Integer*>(value); |
| 6091 | } |
| 6092 | |
| 6093 | |
| 6094 | Date* Date::Cast(v8::Value* value) { |
| 6095 | #ifdef V8_ENABLE_CHECKS |
| 6096 | CheckCast(value); |
| 6097 | #endif |
| 6098 | return static_cast<Date*>(value); |
| 6099 | } |
| 6100 | |
| 6101 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6102 | StringObject* StringObject::Cast(v8::Value* value) { |
| 6103 | #ifdef V8_ENABLE_CHECKS |
| 6104 | CheckCast(value); |
| 6105 | #endif |
| 6106 | return static_cast<StringObject*>(value); |
| 6107 | } |
| 6108 | |
| 6109 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6110 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 6111 | #ifdef V8_ENABLE_CHECKS |
| 6112 | CheckCast(value); |
| 6113 | #endif |
| 6114 | return static_cast<SymbolObject*>(value); |
| 6115 | } |
| 6116 | |
| 6117 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6118 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 6119 | #ifdef V8_ENABLE_CHECKS |
| 6120 | CheckCast(value); |
| 6121 | #endif |
| 6122 | return static_cast<NumberObject*>(value); |
| 6123 | } |
| 6124 | |
| 6125 | |
| 6126 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 6127 | #ifdef V8_ENABLE_CHECKS |
| 6128 | CheckCast(value); |
| 6129 | #endif |
| 6130 | return static_cast<BooleanObject*>(value); |
| 6131 | } |
| 6132 | |
| 6133 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 6134 | RegExp* RegExp::Cast(v8::Value* value) { |
| 6135 | #ifdef V8_ENABLE_CHECKS |
| 6136 | CheckCast(value); |
| 6137 | #endif |
| 6138 | return static_cast<RegExp*>(value); |
| 6139 | } |
| 6140 | |
| 6141 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6142 | Object* Object::Cast(v8::Value* value) { |
| 6143 | #ifdef V8_ENABLE_CHECKS |
| 6144 | CheckCast(value); |
| 6145 | #endif |
| 6146 | return static_cast<Object*>(value); |
| 6147 | } |
| 6148 | |
| 6149 | |
| 6150 | Array* Array::Cast(v8::Value* value) { |
| 6151 | #ifdef V8_ENABLE_CHECKS |
| 6152 | CheckCast(value); |
| 6153 | #endif |
| 6154 | return static_cast<Array*>(value); |
| 6155 | } |
| 6156 | |
| 6157 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6158 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 6159 | #ifdef V8_ENABLE_CHECKS |
| 6160 | CheckCast(value); |
| 6161 | #endif |
| 6162 | return static_cast<ArrayBuffer*>(value); |
| 6163 | } |
| 6164 | |
| 6165 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6166 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 6167 | #ifdef V8_ENABLE_CHECKS |
| 6168 | CheckCast(value); |
| 6169 | #endif |
| 6170 | return static_cast<TypedArray*>(value); |
| 6171 | } |
| 6172 | |
| 6173 | |
| 6174 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 6175 | #ifdef V8_ENABLE_CHECKS |
| 6176 | CheckCast(value); |
| 6177 | #endif |
| 6178 | return static_cast<Uint8Array*>(value); |
| 6179 | } |
| 6180 | |
| 6181 | |
| 6182 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 6183 | #ifdef V8_ENABLE_CHECKS |
| 6184 | CheckCast(value); |
| 6185 | #endif |
| 6186 | return static_cast<Int8Array*>(value); |
| 6187 | } |
| 6188 | |
| 6189 | |
| 6190 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 6191 | #ifdef V8_ENABLE_CHECKS |
| 6192 | CheckCast(value); |
| 6193 | #endif |
| 6194 | return static_cast<Uint16Array*>(value); |
| 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 6199 | #ifdef V8_ENABLE_CHECKS |
| 6200 | CheckCast(value); |
| 6201 | #endif |
| 6202 | return static_cast<Int16Array*>(value); |
| 6203 | } |
| 6204 | |
| 6205 | |
| 6206 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 6207 | #ifdef V8_ENABLE_CHECKS |
| 6208 | CheckCast(value); |
| 6209 | #endif |
| 6210 | return static_cast<Uint32Array*>(value); |
| 6211 | } |
| 6212 | |
| 6213 | |
| 6214 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 6215 | #ifdef V8_ENABLE_CHECKS |
| 6216 | CheckCast(value); |
| 6217 | #endif |
| 6218 | return static_cast<Int32Array*>(value); |
| 6219 | } |
| 6220 | |
| 6221 | |
| 6222 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 6223 | #ifdef V8_ENABLE_CHECKS |
| 6224 | CheckCast(value); |
| 6225 | #endif |
| 6226 | return static_cast<Float32Array*>(value); |
| 6227 | } |
| 6228 | |
| 6229 | |
| 6230 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 6231 | #ifdef V8_ENABLE_CHECKS |
| 6232 | CheckCast(value); |
| 6233 | #endif |
| 6234 | return static_cast<Float64Array*>(value); |
| 6235 | } |
| 6236 | |
| 6237 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 6238 | Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) { |
| 6239 | #ifdef V8_ENABLE_CHECKS |
| 6240 | CheckCast(value); |
| 6241 | #endif |
| 6242 | return static_cast<Uint8ClampedArray*>(value); |
| 6243 | } |
| 6244 | |
| 6245 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6246 | Function* Function::Cast(v8::Value* value) { |
| 6247 | #ifdef V8_ENABLE_CHECKS |
| 6248 | CheckCast(value); |
| 6249 | #endif |
| 6250 | return static_cast<Function*>(value); |
| 6251 | } |
| 6252 | |
| 6253 | |
| 6254 | External* External::Cast(v8::Value* value) { |
| 6255 | #ifdef V8_ENABLE_CHECKS |
| 6256 | CheckCast(value); |
| 6257 | #endif |
| 6258 | return static_cast<External*>(value); |
| 6259 | } |
| 6260 | |
| 6261 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6262 | template<typename T> |
| 6263 | Isolate* PropertyCallbackInfo<T>::GetIsolate() const { |
| 6264 | return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6268 | template<typename T> |
| 6269 | Local<Value> PropertyCallbackInfo<T>::Data() const { |
| 6270 | return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6274 | template<typename T> |
| 6275 | Local<Object> PropertyCallbackInfo<T>::This() const { |
| 6276 | return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6280 | template<typename T> |
| 6281 | Local<Object> PropertyCallbackInfo<T>::Holder() const { |
| 6282 | return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex])); |
| 6283 | } |
| 6284 | |
| 6285 | |
| 6286 | template<typename T> |
| 6287 | ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { |
| 6288 | return ReturnValue<T>(&args_[kReturnValueIndex]); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 6292 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 6293 | typedef internal::Object* S; |
| 6294 | typedef internal::Internals I; |
| 6295 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 6296 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 6297 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6298 | } |
| 6299 | |
| 6300 | |
| 6301 | Handle<Primitive> Null(Isolate* isolate) { |
| 6302 | typedef internal::Object* S; |
| 6303 | typedef internal::Internals I; |
| 6304 | if (!I::IsInitialized(isolate)) return Null(); |
| 6305 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 6306 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6307 | } |
| 6308 | |
| 6309 | |
| 6310 | Handle<Boolean> True(Isolate* isolate) { |
| 6311 | typedef internal::Object* S; |
| 6312 | typedef internal::Internals I; |
| 6313 | if (!I::IsInitialized(isolate)) return True(); |
| 6314 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 6315 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6316 | } |
| 6317 | |
| 6318 | |
| 6319 | Handle<Boolean> False(Isolate* isolate) { |
| 6320 | typedef internal::Object* S; |
| 6321 | typedef internal::Internals I; |
| 6322 | if (!I::IsInitialized(isolate)) return False(); |
| 6323 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 6324 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6325 | } |
| 6326 | |
| 6327 | |
| 6328 | void Isolate::SetData(void* data) { |
| 6329 | typedef internal::Internals I; |
| 6330 | I::SetEmbedderData(this, data); |
| 6331 | } |
| 6332 | |
| 6333 | |
| 6334 | void* Isolate::GetData() { |
| 6335 | typedef internal::Internals I; |
| 6336 | return I::GetEmbedderData(this); |
| 6337 | } |
| 6338 | |
| 6339 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 6340 | Local<Value> Context::GetEmbedderData(int index) { |
| 6341 | #ifndef V8_ENABLE_CHECKS |
| 6342 | typedef internal::Object O; |
| 6343 | typedef internal::Internals I; |
| 6344 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 6345 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 6346 | #else |
| 6347 | return SlowGetEmbedderData(index); |
| 6348 | #endif |
| 6349 | } |
| 6350 | |
| 6351 | |
| 6352 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 6353 | #ifndef V8_ENABLE_CHECKS |
| 6354 | typedef internal::Internals I; |
| 6355 | return I::ReadEmbedderData<void*>(this, index); |
| 6356 | #else |
| 6357 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 6358 | #endif |
| 6359 | } |
| 6360 | |
| 6361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6362 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 6363 | * \example shell.cc |
| 6364 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6365 | * command-line and executes them. |
| 6366 | */ |
| 6367 | |
| 6368 | |
| 6369 | /** |
| 6370 | * \example process.cc |
| 6371 | */ |
| 6372 | |
| 6373 | |
| 6374 | } // namespace v8 |
| 6375 | |
| 6376 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6377 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6378 | #undef TYPE_CHECK |
| 6379 | |
| 6380 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6381 | #endif // V8_H_ |