jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 32 | * This set of documents provides reference material generated from the |
| 33 | * V8 header file, include/v8.h. |
| 34 | * |
| 35 | * For other documentation see http://code.google.com/apis/v8/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 66 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 67 | (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 68 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 70 | #else |
| 71 | #define V8EXPORT |
| 72 | #endif |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 73 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 75 | #endif |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // _WIN32 |
| 78 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 79 | #if defined(__GNUC__) && !defined(DEBUG) |
| 80 | #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 81 | #elif defined(_MSC_VER) && !defined(DEBUG) |
| 82 | #define V8_INLINE(declarator) __forceinline declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 83 | #else |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 84 | #define V8_INLINE(declarator) inline declarator |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS |
| 88 | #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated)) |
| 89 | #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS |
| 90 | #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 91 | #else |
| 92 | #define V8_DEPRECATED(declarator) declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 95 | #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 96 | #define V8_UNLIKELY(condition) __builtin_expect((condition), 0) |
| 97 | #define V8_LIKELY(condition) __builtin_expect((condition), 1) |
| 98 | #else |
| 99 | #define V8_UNLIKELY(condition) (condition) |
| 100 | #define V8_LIKELY(condition) (condition) |
| 101 | #endif |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 104 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | */ |
| 106 | namespace v8 { |
| 107 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 108 | class AccessorInfo; |
| 109 | class AccessorSignature; |
| 110 | class Array; |
| 111 | class Boolean; |
| 112 | class BooleanObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | class Context; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 114 | class CpuProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 115 | class Data; |
| 116 | class Date; |
| 117 | class DeclaredAccessorDescriptor; |
| 118 | class External; |
| 119 | class Function; |
| 120 | class FunctionTemplate; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 121 | class HeapProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 122 | class ImplementationUtilities; |
| 123 | class Int32; |
| 124 | class Integer; |
| 125 | class Isolate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | class LocalContext; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 128 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 130 | class ObjectOperationDescriptor; |
| 131 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 133 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 135 | class StackFrame; |
| 136 | class StackTrace; |
| 137 | class String; |
| 138 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 139 | class Symbol; |
| 140 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 141 | class Uint32; |
| 142 | class Utils; |
| 143 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | template <class T> class Handle; |
| 145 | template <class T> class Local; |
| 146 | template <class T> class Persistent; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 147 | class FunctionTemplate; |
| 148 | class ObjectTemplate; |
| 149 | class Data; |
| 150 | class AccessorInfo; |
| 151 | template<typename T> class PropertyCallbackInfo; |
| 152 | class StackTrace; |
| 153 | class StackFrame; |
| 154 | class Isolate; |
| 155 | class DeclaredAccessorDescriptor; |
| 156 | class ObjectOperationDescriptor; |
| 157 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 159 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 160 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 161 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 162 | class HeapObject; |
| 163 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 164 | class Object; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 165 | template<typename T> |
| 166 | class CustomArguments; |
| 167 | class PropertyCallbackArguments; |
| 168 | class FunctionCallbackArguments; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 169 | } |
| 170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 172 | /** |
| 173 | * General purpose unique identifier. |
| 174 | */ |
| 175 | class UniqueId { |
| 176 | public: |
| 177 | explicit UniqueId(intptr_t data) |
| 178 | : data_(data) {} |
| 179 | |
| 180 | bool operator==(const UniqueId& other) const { |
| 181 | return data_ == other.data_; |
| 182 | } |
| 183 | |
| 184 | bool operator!=(const UniqueId& other) const { |
| 185 | return data_ != other.data_; |
| 186 | } |
| 187 | |
| 188 | bool operator<(const UniqueId& other) const { |
| 189 | return data_ < other.data_; |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | intptr_t data_; |
| 194 | }; |
| 195 | |
| 196 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 197 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | |
| 199 | |
| 200 | /** |
| 201 | * A weak reference callback function. |
| 202 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 203 | * This callback should either explicitly invoke Dispose on |object| if |
| 204 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 205 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | * \param object the weak global object to be reclaimed by the garbage collector |
| 207 | * \param parameter the value passed in when making the weak global object |
| 208 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 209 | template<typename T, typename P> |
| 210 | class WeakReferenceCallbacks { |
| 211 | public: |
| 212 | typedef void (*Revivable)(Isolate* isolate, |
| 213 | Persistent<T>* object, |
| 214 | P* parameter); |
| 215 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 217 | // TODO(svenpanne) Temporary definition until Chrome is in sync. |
| 218 | typedef void (*NearDeathCallback)(Isolate* isolate, |
| 219 | Persistent<Value> object, |
| 220 | void* parameter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 222 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 224 | #define TYPE_CHECK(T, S) \ |
| 225 | while (false) { \ |
| 226 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | } |
| 228 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 229 | |
| 230 | #define V8_USE_UNSAFE_HANDLES |
| 231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | /** |
| 233 | * An object reference managed by the v8 garbage collector. |
| 234 | * |
| 235 | * All objects returned from v8 have to be tracked by the garbage |
| 236 | * collector so that it knows that the objects are still alive. Also, |
| 237 | * because the garbage collector may move objects, it is unsafe to |
| 238 | * point directly to an object. Instead, all objects are stored in |
| 239 | * handles which are known by the garbage collector and updated |
| 240 | * whenever an object moves. Handles should always be passed by value |
| 241 | * (except in cases like out-parameters) and they should never be |
| 242 | * allocated on the heap. |
| 243 | * |
| 244 | * There are two types of handles: local and persistent handles. |
| 245 | * Local handles are light-weight and transient and typically used in |
| 246 | * local operations. They are managed by HandleScopes. Persistent |
| 247 | * handles can be used when storing objects across several independent |
| 248 | * operations and have to be explicitly deallocated when they're no |
| 249 | * longer used. |
| 250 | * |
| 251 | * It is safe to extract the object stored in the handle by |
| 252 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 253 | * 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] | 254 | * behind the scenes and the same rules apply to these values as to |
| 255 | * their handles. |
| 256 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 257 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | /** |
| 260 | * Creates an empty handle. |
| 261 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 262 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 264 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | /** |
| 266 | * Creates a new handle for the specified value. |
| 267 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 268 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 269 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Creates a handle for the contents of the specified handle. This |
| 273 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 274 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 276 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | * between compatible handles, for instance assigning a |
| 278 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 279 | * because String is a subclass of Value. |
| 280 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 281 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | : val_(reinterpret_cast<T*>(*that)) { |
| 283 | /** |
| 284 | * This check fails when trying to convert between incompatible |
| 285 | * handles. For example, converting from a Handle<String> to a |
| 286 | * Handle<Number>. |
| 287 | */ |
| 288 | TYPE_CHECK(T, S); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Returns true if the handle is empty. |
| 293 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 294 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | /** |
| 297 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 298 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 299 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 300 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 301 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 302 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 303 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * Checks whether two handles are the same. |
| 307 | * Returns true if both are empty, or if the objects |
| 308 | * to which they refer are identical. |
| 309 | * The handles' references are not checked. |
| 310 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 311 | 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] | 312 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 313 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | if (a == 0) return b == 0; |
| 315 | if (b == 0) return false; |
| 316 | return *a == *b; |
| 317 | } |
| 318 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 319 | #ifndef V8_USE_UNSAFE_HANDLES |
| 320 | template <class S> V8_INLINE( |
| 321 | bool operator==(const Persistent<S>& that) const) { |
| 322 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 323 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 324 | if (a == 0) return b == 0; |
| 325 | if (b == 0) return false; |
| 326 | return *a == *b; |
| 327 | } |
| 328 | #endif |
| 329 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | /** |
| 331 | * Checks whether two handles are different. |
| 332 | * Returns true if only one of the handles is empty, or if |
| 333 | * the objects to which they refer are different. |
| 334 | * The handles' references are not checked. |
| 335 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 336 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | return !operator==(that); |
| 338 | } |
| 339 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 340 | 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] | 341 | #ifdef V8_ENABLE_CHECKS |
| 342 | // If we're going to perform the type check then we have to check |
| 343 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 345 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | return Handle<T>(T::Cast(*that)); |
| 347 | } |
| 348 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 349 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 350 | return Handle<S>::Cast(*this); |
| 351 | } |
| 352 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 353 | #ifndef V8_USE_UNSAFE_HANDLES |
| 354 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 355 | return New(isolate, that.val_); |
| 356 | } |
| 357 | // TODO(dcarney): remove before cutover |
| 358 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 359 | return New(isolate, that.val_); |
| 360 | } |
| 361 | |
| 362 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 365 | #endif |
| 366 | /** |
| 367 | * Creates a new handle for the specified value. |
| 368 | */ |
| 369 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 370 | #endif |
| 371 | |
| 372 | private: |
| 373 | template<class F> |
| 374 | friend class Persistent; |
| 375 | template<class F> |
| 376 | friend class Local; |
| 377 | friend class Arguments; |
| 378 | friend class String; |
| 379 | friend class Object; |
| 380 | friend class AccessorInfo; |
| 381 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 382 | friend Handle<Primitive> Null(Isolate* isolate); |
| 383 | friend Handle<Boolean> True(Isolate* isolate); |
| 384 | friend Handle<Boolean> False(Isolate* isolate); |
| 385 | friend class Context; |
| 386 | friend class InternalHandleHelper; |
| 387 | friend class LocalContext; |
| 388 | |
| 389 | #ifndef V8_USE_UNSAFE_HANDLES |
| 390 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 391 | #endif |
| 392 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | T* val_; |
| 394 | }; |
| 395 | |
| 396 | |
| 397 | /** |
| 398 | * A light-weight stack-allocated object handle. All operations |
| 399 | * that return objects from within v8 return them in local handles. They |
| 400 | * are created within HandleScopes, and all local handles allocated within a |
| 401 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 402 | * is not necessary to explicitly deallocate local handles. |
| 403 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 404 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 405 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 406 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 407 | V8_INLINE(Local()); |
| 408 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 410 | /** |
| 411 | * This check fails when trying to convert between incompatible |
| 412 | * handles. For example, converting from a Handle<String> to a |
| 413 | * Handle<Number>. |
| 414 | */ |
| 415 | TYPE_CHECK(T, S); |
| 416 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 417 | |
| 418 | |
| 419 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 420 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 421 | #endif |
| 422 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 423 | 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] | 424 | #ifdef V8_ENABLE_CHECKS |
| 425 | // If we're going to perform the type check then we have to check |
| 426 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 428 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | return Local<T>(T::Cast(*that)); |
| 430 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 431 | #ifndef V8_USE_UNSAFE_HANDLES |
| 432 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 433 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 434 | TYPE_CHECK(T, S); |
| 435 | } |
| 436 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 438 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 439 | return Local<S>::Cast(*this); |
| 440 | } |
| 441 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 442 | /** |
| 443 | * Create a local handle for the content of another handle. |
| 444 | * The referee is kept alive by the local handle even when |
| 445 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 447 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 448 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 449 | #ifndef V8_USE_UNSAFE_HANDLES |
| 450 | // TODO(dcarney): remove before cutover |
| 451 | 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] | 452 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 453 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 454 | |
| 455 | private: |
| 456 | #endif |
| 457 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 458 | #endif |
| 459 | |
| 460 | private: |
| 461 | template<class F> |
| 462 | friend class Persistent; |
| 463 | template<class F> |
| 464 | friend class Handle; |
| 465 | friend class Arguments; |
| 466 | friend class String; |
| 467 | friend class Object; |
| 468 | friend class AccessorInfo; |
| 469 | friend class Context; |
| 470 | friend class InternalHandleHelper; |
| 471 | friend class LocalContext; |
| 472 | |
| 473 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 474 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 478 | * 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] | 479 | * allocated, a Persistent handle remains valid until it is explicitly |
| 480 | * disposed. |
| 481 | * |
| 482 | * A persistent handle contains a reference to a storage cell within |
| 483 | * the v8 engine which holds an object value and which is updated by |
| 484 | * the garbage collector whenever the object is moved. A new storage |
| 485 | * cell can be created using Persistent::New and existing handles can |
| 486 | * be disposed using Persistent::Dispose. Since persistent handles |
| 487 | * are passed by value you may have many persistent handle objects |
| 488 | * that point to the same storage cell. For instance, if you pass a |
| 489 | * persistent handle as an argument to a function you will not get two |
| 490 | * different storage cells but rather two references to the same |
| 491 | * storage cell. |
| 492 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 493 | template <class T> class Persistent // NOLINT |
| 494 | #ifdef V8_USE_UNSAFE_HANDLES |
| 495 | : public Handle<T> { |
| 496 | #else |
| 497 | { // NOLINT |
| 498 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 500 | #ifndef V8_USE_UNSAFE_HANDLES |
| 501 | V8_INLINE(Persistent()) : val_(0) { } |
| 502 | V8_INLINE(~Persistent()) { |
| 503 | // TODO(dcarney): add this back before cutover. |
| 504 | // Dispose(); |
| 505 | } |
| 506 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 507 | // TODO(dcarney): remove somehow before cutover |
| 508 | // The handle should either be 0, or a pointer to a live cell. |
| 509 | V8_INLINE(void Clear()) { val_ = 0; } |
| 510 | |
| 511 | /** |
| 512 | * A constructor that creates a new global cell pointing to that. In contrast |
| 513 | * to the copy constructor, this creates a new persistent handle which needs |
| 514 | * to be separately disposed. |
| 515 | */ |
| 516 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 517 | : val_(*New(isolate, that)) { } |
| 518 | |
| 519 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | /** |
| 521 | * Creates an empty persistent handle that doesn't point to any |
| 522 | * storage cell. |
| 523 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 524 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * Creates a persistent handle for the same storage cell as the |
| 528 | * specified handle. This constructor allows you to pass persistent |
| 529 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 530 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 532 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | * between compatible persistent handles, for instance assigning a |
| 534 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 535 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 537 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 539 | /** |
| 540 | * This check fails when trying to convert between incompatible |
| 541 | * handles. For example, converting from a Handle<String> to a |
| 542 | * Handle<Number>. |
| 543 | */ |
| 544 | TYPE_CHECK(T, S); |
| 545 | } |
| 546 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 547 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 549 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 550 | * A constructor that creates a new global cell pointing to that. In contrast |
| 551 | * to the copy constructor, this creates a new persistent handle which needs |
| 552 | * to be separately disposed. |
| 553 | */ |
| 554 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 555 | : Handle<T>(New(isolate, that)) { } |
| 556 | |
| 557 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 558 | * "Casts" a plain handle which is known to be a persistent handle |
| 559 | * to a persistent handle. |
| 560 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 561 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | : Handle<T>(*that) { } |
| 563 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 564 | #endif |
| 565 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 566 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 567 | 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] | 568 | #ifdef V8_ENABLE_CHECKS |
| 569 | // If we're going to perform the type check then we have to check |
| 570 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 572 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | return Persistent<T>(T::Cast(*that)); |
| 574 | } |
| 575 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 576 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 577 | return Persistent<S>::Cast(*this); |
| 578 | } |
| 579 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 580 | #else |
| 581 | template <class S> |
| 582 | V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT |
| 583 | #ifdef V8_ENABLE_CHECKS |
| 584 | // If we're going to perform the type check then we have to check |
| 585 | // that the handle isn't empty before doing the checked cast. |
| 586 | if (!that.IsEmpty()) T::Cast(*that); |
| 587 | #endif |
| 588 | return reinterpret_cast<Persistent<T>&>(that); |
| 589 | } |
| 590 | |
| 591 | template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| 592 | return Persistent<S>::Cast(*this); |
| 593 | } |
| 594 | #endif |
| 595 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 596 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 597 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 599 | * Creates a new persistent handle for an existing local or persistent handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 600 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 601 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 602 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 603 | #ifndef V8_USE_UNSAFE_HANDLES |
| 604 | // TODO(dcarney): remove before cutover |
| 605 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 606 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 607 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 608 | #ifndef V8_USE_UNSAFE_HANDLES |
| 609 | template <class S> V8_INLINE( |
| 610 | bool operator==(const Persistent<S>& that) const) { |
| 611 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 612 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 613 | if (a == 0) return b == 0; |
| 614 | if (b == 0) return false; |
| 615 | return *a == *b; |
| 616 | } |
| 617 | |
| 618 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 619 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 620 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 621 | if (a == 0) return b == 0; |
| 622 | if (b == 0) return false; |
| 623 | return *a == *b; |
| 624 | } |
| 625 | #endif |
| 626 | |
| 627 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | |
| 629 | /** |
| 630 | * Releases the storage cell referenced by this persistent handle. |
| 631 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 632 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | * cell remain and IsEmpty will still return false. |
| 634 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 635 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 636 | V8_INLINE(void Dispose(Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 638 | template<typename S, typename P> |
| 639 | V8_INLINE(void MakeWeak( |
| 640 | Isolate* isolate, |
| 641 | P* parameters, |
| 642 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 643 | |
| 644 | template<typename P> |
| 645 | V8_INLINE(void MakeWeak( |
| 646 | Isolate* isolate, |
| 647 | P* parameters, |
| 648 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 649 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 650 | /** |
| 651 | * Make the reference to this object weak. When only weak handles |
| 652 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 653 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | * it the object reference and the given parameters. |
| 655 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 656 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 657 | V8_INLINE(void MakeWeak(Isolate* isolate, |
| 658 | void* parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 659 | NearDeathCallback callback)); |
| 660 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 661 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 663 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 664 | V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 665 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 666 | V8_INLINE(void MarkIndependent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 667 | |
| 668 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 669 | * Marks the reference to this object independent. Garbage collector is free |
| 670 | * to ignore any object groups containing this object. Weak callback for an |
| 671 | * independent handle should not assume that it will be preceded by a global |
| 672 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 673 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 674 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 675 | V8_INLINE(void MarkIndependent(Isolate* isolate)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 676 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 677 | V8_INLINE(void MarkPartiallyDependent()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 678 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 679 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 680 | * Marks the reference to this object partially dependent. Partially dependent |
| 681 | * handles only depend on other partially dependent handles and these |
| 682 | * dependencies are provided through object groups. It provides a way to build |
| 683 | * smaller object groups for young objects that represent only a subset of all |
| 684 | * external dependencies. This mark is automatically cleared after each |
| 685 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 686 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 687 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 688 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 689 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 690 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 691 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 692 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 693 | V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 694 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 695 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 696 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 697 | /** Checks if the handle holds the only reference to an object. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 698 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 699 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 700 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 701 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 703 | /** Returns true if the handle's reference is weak. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 704 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 705 | V8_INLINE(bool IsWeak(Isolate* isolate) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 707 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 708 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 709 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 710 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 711 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 712 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 713 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 714 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 715 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 716 | V8_INLINE(uint16_t WrapperClassId() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 717 | |
| 718 | /** |
| 719 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 720 | * was previously assigned. |
| 721 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 722 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 723 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 724 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 725 | /** |
| 726 | * Disposes the current contents of the handle and replaces it. |
| 727 | */ |
| 728 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 729 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 730 | /** |
| 731 | * Returns the underlying raw pointer and clears the handle. The caller is |
| 732 | * responsible of eventually destroying the underlying object (by creating a |
| 733 | * Persistent handle which points to it and Disposing it). In the future, |
| 734 | * destructing a Persistent will also Dispose it. With this function, the |
| 735 | * embedder can let the Persistent go out of scope without it getting |
| 736 | * disposed. |
| 737 | */ |
| 738 | V8_INLINE(T* ClearAndLeak()); |
| 739 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 740 | #ifndef V8_USE_UNSAFE_HANDLES |
| 741 | |
| 742 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 743 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 744 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 745 | #endif |
| 746 | // TODO(dcarney): make unlinkable before cutover |
| 747 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 748 | // TODO(dcarney): make unlinkable before cutover |
| 749 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 750 | this->val_ = that.val_; |
| 751 | return *this; |
| 752 | } |
| 753 | |
| 754 | public: |
| 755 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 756 | |
| 757 | private: |
| 758 | #endif |
| 759 | // TODO(dcarney): remove before cutover |
| 760 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 761 | // TODO(dcarney): remove before cutover |
| 762 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 763 | : val_(*that) { |
| 764 | TYPE_CHECK(T, S); |
| 765 | } |
| 766 | // TODO(dcarney): remove before cutover |
| 767 | V8_INLINE(T* operator*() const) { return val_; } |
| 768 | public: |
| 769 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 770 | |
| 771 | private: |
| 772 | #endif |
| 773 | // TODO(dcarney): remove before cutover |
| 774 | V8_INLINE(T* operator->() const) { return val_; } |
| 775 | public: |
| 776 | #endif |
| 777 | |
| 778 | private: |
| 779 | template<class F> |
| 780 | friend class Handle; |
| 781 | template<class F> |
| 782 | friend class Local; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | friend class ImplementationUtilities; |
| 784 | friend class ObjectTemplate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 785 | friend class Context; |
| 786 | friend class InternalHandleHelper; |
| 787 | friend class LocalContext; |
| 788 | |
| 789 | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 790 | |
| 791 | #ifndef V8_USE_UNSAFE_HANDLES |
| 792 | T* val_; |
| 793 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 797 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 798 | * A stack-allocated class that governs a number of local handles. |
| 799 | * After a handle scope has been created, all local handles will be |
| 800 | * allocated within that handle scope until either the handle scope is |
| 801 | * deleted or another handle scope is created. If there is already a |
| 802 | * 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] | 803 | * 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] | 804 | * new handles will again be allocated in the original handle scope. |
| 805 | * |
| 806 | * After the handle scope of a local handle has been deleted the |
| 807 | * garbage collector will no longer track the object stored in the |
| 808 | * handle and may deallocate it. The behavior of accessing a handle |
| 809 | * for which the handle scope has been deleted is undefined. |
| 810 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 811 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 813 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 814 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 816 | HandleScope(Isolate* isolate); |
| 817 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 818 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 819 | |
| 820 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | * Closes the handle scope and returns the value as a handle in the |
| 822 | * previous scope, which is the new current scope after the call. |
| 823 | */ |
| 824 | template <class T> Local<T> Close(Handle<T> value); |
| 825 | |
| 826 | /** |
| 827 | * Counts the number of allocated handles. |
| 828 | */ |
| 829 | static int NumberOfHandles(); |
| 830 | |
| 831 | /** |
| 832 | * Creates a new handle with the given value. |
| 833 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 834 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 835 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 836 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 837 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 838 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | |
| 840 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 841 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 842 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | HandleScope(const HandleScope&); |
| 844 | void operator=(const HandleScope&); |
| 845 | void* operator new(size_t size); |
| 846 | void operator delete(void*, size_t); |
| 847 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 848 | // This Data class is accessible internally as HandleScopeData through a |
| 849 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 850 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 851 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 852 | internal::Object** next; |
| 853 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 854 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 855 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 857 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | } |
| 859 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 860 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 861 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 862 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 864 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 865 | internal::Object** prev_next_; |
| 866 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 868 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 869 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 871 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | friend class ImplementationUtilities; |
| 874 | }; |
| 875 | |
| 876 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 877 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | |
| 879 | |
| 880 | /** |
| 881 | * The superclass of values and API object templates. |
| 882 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 883 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | private: |
| 885 | Data(); |
| 886 | }; |
| 887 | |
| 888 | |
| 889 | /** |
| 890 | * Pre-compilation data that can be associated with a script. This |
| 891 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 892 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 893 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 895 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | public: |
| 897 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 898 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 899 | /** |
| 900 | * Pre-compiles the specified script (context-independent). |
| 901 | * |
| 902 | * \param input Pointer to UTF-8 script source code. |
| 903 | * \param length Length of UTF-8 script source code. |
| 904 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 905 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 906 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 907 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 908 | * Pre-compiles the specified script (context-independent). |
| 909 | * |
| 910 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 911 | * without using Lockers. |
| 912 | * |
| 913 | * \param source Script source code. |
| 914 | */ |
| 915 | static ScriptData* PreCompile(Handle<String> source); |
| 916 | |
| 917 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 918 | * Load previous pre-compilation data. |
| 919 | * |
| 920 | * \param data Pointer to data returned by a call to Data() of a previous |
| 921 | * ScriptData. Ownership is not transferred. |
| 922 | * \param length Length of data. |
| 923 | */ |
| 924 | static ScriptData* New(const char* data, int length); |
| 925 | |
| 926 | /** |
| 927 | * Returns the length of Data(). |
| 928 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 929 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 930 | |
| 931 | /** |
| 932 | * Returns a serialized representation of this ScriptData that can later be |
| 933 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 934 | */ |
| 935 | virtual const char* Data() = 0; |
| 936 | |
| 937 | /** |
| 938 | * Returns true if the source code could not be parsed. |
| 939 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 940 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 941 | }; |
| 942 | |
| 943 | |
| 944 | /** |
| 945 | * The origin, within a file, of a script. |
| 946 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 947 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 949 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 950 | Handle<Value> resource_name, |
| 951 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 952 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 953 | : resource_name_(resource_name), |
| 954 | resource_line_offset_(resource_line_offset), |
| 955 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 956 | V8_INLINE(Handle<Value> ResourceName() const); |
| 957 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 958 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 959 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 960 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | Handle<Integer> resource_line_offset_; |
| 962 | Handle<Integer> resource_column_offset_; |
| 963 | }; |
| 964 | |
| 965 | |
| 966 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 967 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 969 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 972 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 973 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 974 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 975 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 976 | * when New() returns |
| 977 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 978 | * using pre_data speeds compilation if it's done multiple times. |
| 979 | * Owned by caller, no references are kept when New() returns. |
| 980 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 981 | * 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] | 982 | * available to compile event handlers. |
| 983 | * \return Compiled script object (context independent; when run it |
| 984 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 985 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 986 | static Local<Script> New(Handle<String> source, |
| 987 | ScriptOrigin* origin = NULL, |
| 988 | ScriptData* pre_data = NULL, |
| 989 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 991 | /** |
| 992 | * Compiles the specified script using the specified file name |
| 993 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 994 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 995 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 996 | * \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] | 997 | * as the script's origin. |
| 998 | * \return Compiled script object (context independent; when run it |
| 999 | * will use the currently entered context). |
| 1000 | */ |
| 1001 | static Local<Script> New(Handle<String> source, |
| 1002 | Handle<Value> file_name); |
| 1003 | |
| 1004 | /** |
| 1005 | * Compiles the specified script (bound to current context). |
| 1006 | * |
| 1007 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1008 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1009 | * when Compile() returns |
| 1010 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 1011 | * using pre_data speeds compilation if it's done multiple times. |
| 1012 | * Owned by caller, no references are kept when Compile() returns. |
| 1013 | * \param script_data Arbitrary data associated with script. Using |
| 1014 | * this has same effect as calling SetData(), but makes data available |
| 1015 | * earlier (i.e. to compile event handlers). |
| 1016 | * \return Compiled script object, bound to the context that was active |
| 1017 | * when this function was called. When run it will always use this |
| 1018 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1019 | */ |
| 1020 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1021 | ScriptOrigin* origin = NULL, |
| 1022 | ScriptData* pre_data = NULL, |
| 1023 | Handle<String> script_data = Handle<String>()); |
| 1024 | |
| 1025 | /** |
| 1026 | * Compiles the specified script using the specified file name |
| 1027 | * object (typically a string) as the script's origin. |
| 1028 | * |
| 1029 | * \param source Script source code. |
| 1030 | * \param file_name File name to use as script's origin |
| 1031 | * \param script_data Arbitrary data associated with script. Using |
| 1032 | * this has same effect as calling SetData(), but makes data available |
| 1033 | * earlier (i.e. to compile event handlers). |
| 1034 | * \return Compiled script object, bound to the context that was active |
| 1035 | * when this function was called. When run it will always use this |
| 1036 | * context. |
| 1037 | */ |
| 1038 | static Local<Script> Compile(Handle<String> source, |
| 1039 | Handle<Value> file_name, |
| 1040 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1041 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1042 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1043 | * Runs the script returning the resulting value. If the script is |
| 1044 | * context independent (created using ::New) it will be run in the |
| 1045 | * currently entered context. If it is context specific (created |
| 1046 | * using ::Compile) it will be run in the context in which it was |
| 1047 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1048 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1049 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1050 | |
| 1051 | /** |
| 1052 | * Returns the script id value. |
| 1053 | */ |
| 1054 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1055 | |
| 1056 | /** |
| 1057 | * Associate an additional data object with the script. This is mainly used |
| 1058 | * with the debugger as this data object is only available through the |
| 1059 | * debugger API. |
| 1060 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1061 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1062 | |
| 1063 | /** |
| 1064 | * Returns the name value of one Script. |
| 1065 | */ |
| 1066 | Handle<Value> GetScriptName(); |
| 1067 | |
| 1068 | /** |
| 1069 | * Returns zero based line number of the code_pos location in the script. |
| 1070 | * -1 will be returned if no information available. |
| 1071 | */ |
| 1072 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | }; |
| 1074 | |
| 1075 | |
| 1076 | /** |
| 1077 | * An error message. |
| 1078 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1079 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1080 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1081 | Local<String> Get() const; |
| 1082 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1083 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1084 | /** |
| 1085 | * Returns the resource name for the script from where the function causing |
| 1086 | * the error originates. |
| 1087 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1088 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1089 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1090 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1091 | * Returns the resource data for the script from where the function causing |
| 1092 | * the error originates. |
| 1093 | */ |
| 1094 | Handle<Value> GetScriptData() const; |
| 1095 | |
| 1096 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1097 | * Exception stack trace. By default stack traces are not captured for |
| 1098 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1099 | * to change this option. |
| 1100 | */ |
| 1101 | Handle<StackTrace> GetStackTrace() const; |
| 1102 | |
| 1103 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1104 | * Returns the number, 1-based, of the line where the error occurred. |
| 1105 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1106 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1108 | /** |
| 1109 | * Returns the index within the script of the first character where |
| 1110 | * the error occurred. |
| 1111 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1112 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1113 | |
| 1114 | /** |
| 1115 | * Returns the index within the script of the last character where |
| 1116 | * the error occurred. |
| 1117 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1118 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1119 | |
| 1120 | /** |
| 1121 | * Returns the index within the line of the first character where |
| 1122 | * the error occurred. |
| 1123 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1124 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1125 | |
| 1126 | /** |
| 1127 | * Returns the index within the line of the last character where |
| 1128 | * the error occurred. |
| 1129 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1130 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1132 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1133 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1134 | |
| 1135 | static const int kNoLineNumberInfo = 0; |
| 1136 | static const int kNoColumnInfo = 0; |
| 1137 | }; |
| 1138 | |
| 1139 | |
| 1140 | /** |
| 1141 | * Representation of a JavaScript stack trace. The information collected is a |
| 1142 | * snapshot of the execution stack and the information remains valid after |
| 1143 | * execution continues. |
| 1144 | */ |
| 1145 | class V8EXPORT StackTrace { |
| 1146 | public: |
| 1147 | /** |
| 1148 | * Flags that determine what information is placed captured for each |
| 1149 | * StackFrame when grabbing the current stack trace. |
| 1150 | */ |
| 1151 | enum StackTraceOptions { |
| 1152 | kLineNumber = 1, |
| 1153 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1154 | kScriptName = 1 << 2, |
| 1155 | kFunctionName = 1 << 3, |
| 1156 | kIsEval = 1 << 4, |
| 1157 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1158 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1159 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1160 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1161 | }; |
| 1162 | |
| 1163 | /** |
| 1164 | * Returns a StackFrame at a particular index. |
| 1165 | */ |
| 1166 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1167 | |
| 1168 | /** |
| 1169 | * Returns the number of StackFrames. |
| 1170 | */ |
| 1171 | int GetFrameCount() const; |
| 1172 | |
| 1173 | /** |
| 1174 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1175 | */ |
| 1176 | Local<Array> AsArray(); |
| 1177 | |
| 1178 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1179 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1180 | * |
| 1181 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1182 | * \param options Enumerates the set of things we will capture for each |
| 1183 | * StackFrame. |
| 1184 | */ |
| 1185 | static Local<StackTrace> CurrentStackTrace( |
| 1186 | int frame_limit, |
| 1187 | StackTraceOptions options = kOverview); |
| 1188 | }; |
| 1189 | |
| 1190 | |
| 1191 | /** |
| 1192 | * A single JavaScript stack frame. |
| 1193 | */ |
| 1194 | class V8EXPORT StackFrame { |
| 1195 | public: |
| 1196 | /** |
| 1197 | * Returns the number, 1-based, of the line for the associate function call. |
| 1198 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1199 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1200 | * when capturing the StackTrace. |
| 1201 | */ |
| 1202 | int GetLineNumber() const; |
| 1203 | |
| 1204 | /** |
| 1205 | * Returns the 1-based column offset on the line for the associated function |
| 1206 | * call. |
| 1207 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1208 | * the column number, or if kColumnOffset was not passed as an option when |
| 1209 | * capturing the StackTrace. |
| 1210 | */ |
| 1211 | int GetColumn() const; |
| 1212 | |
| 1213 | /** |
| 1214 | * Returns the name of the resource that contains the script for the |
| 1215 | * function for this StackFrame. |
| 1216 | */ |
| 1217 | Local<String> GetScriptName() const; |
| 1218 | |
| 1219 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1220 | * Returns the name of the resource that contains the script for the |
| 1221 | * function for this StackFrame or sourceURL value if the script name |
| 1222 | * is undefined and its source ends with //@ sourceURL=... string. |
| 1223 | */ |
| 1224 | Local<String> GetScriptNameOrSourceURL() const; |
| 1225 | |
| 1226 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1227 | * Returns the name of the function associated with this stack frame. |
| 1228 | */ |
| 1229 | Local<String> GetFunctionName() const; |
| 1230 | |
| 1231 | /** |
| 1232 | * Returns whether or not the associated function is compiled via a call to |
| 1233 | * eval(). |
| 1234 | */ |
| 1235 | bool IsEval() const; |
| 1236 | |
| 1237 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1238 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1239 | * constructor via "new". |
| 1240 | */ |
| 1241 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | }; |
| 1243 | |
| 1244 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1245 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | |
| 1247 | |
| 1248 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1249 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1250 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1251 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1252 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1253 | /** |
| 1254 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1255 | * 4.3.10. |
| 1256 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1257 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | |
| 1259 | /** |
| 1260 | * Returns true if this value is the null value. See ECMA-262 |
| 1261 | * 4.3.11. |
| 1262 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1263 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | |
| 1265 | /** |
| 1266 | * Returns true if this value is true. |
| 1267 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1268 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | |
| 1270 | /** |
| 1271 | * Returns true if this value is false. |
| 1272 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1273 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | |
| 1275 | /** |
| 1276 | * Returns true if this value is an instance of the String type. |
| 1277 | * See ECMA-262 8.4. |
| 1278 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1279 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1280 | |
| 1281 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1282 | * Returns true if this value is a symbol. |
| 1283 | * This is an experimental feature. |
| 1284 | */ |
| 1285 | bool IsSymbol() const; |
| 1286 | |
| 1287 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1288 | * Returns true if this value is a function. |
| 1289 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1290 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1291 | |
| 1292 | /** |
| 1293 | * Returns true if this value is an array. |
| 1294 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1295 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1297 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | * Returns true if this value is an object. |
| 1299 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1300 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1302 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1303 | * Returns true if this value is boolean. |
| 1304 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1305 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1306 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1307 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1308 | * Returns true if this value is a number. |
| 1309 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1310 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1311 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1312 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | * Returns true if this value is external. |
| 1314 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1315 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1317 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | * Returns true if this value is a 32-bit signed integer. |
| 1319 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1320 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1321 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1322 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1323 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1324 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1325 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1326 | |
| 1327 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1328 | * Returns true if this value is a Date. |
| 1329 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1330 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1331 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1332 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1333 | * Returns true if this value is a Boolean object. |
| 1334 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1335 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1336 | |
| 1337 | /** |
| 1338 | * Returns true if this value is a Number object. |
| 1339 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1340 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1341 | |
| 1342 | /** |
| 1343 | * Returns true if this value is a String object. |
| 1344 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1345 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1346 | |
| 1347 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1348 | * Returns true if this value is a Symbol object. |
| 1349 | * This is an experimental feature. |
| 1350 | */ |
| 1351 | bool IsSymbolObject() const; |
| 1352 | |
| 1353 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1354 | * Returns true if this value is a NativeError. |
| 1355 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1356 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1357 | |
| 1358 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1359 | * Returns true if this value is a RegExp. |
| 1360 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1361 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1362 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1363 | |
| 1364 | /** |
| 1365 | * Returns true if this value is an ArrayBuffer. |
| 1366 | * This is an experimental feature. |
| 1367 | */ |
| 1368 | bool IsArrayBuffer() const; |
| 1369 | |
| 1370 | /** |
| 1371 | * Returns true if this value is one of TypedArrays. |
| 1372 | * This is an experimental feature. |
| 1373 | */ |
| 1374 | bool IsTypedArray() const; |
| 1375 | |
| 1376 | /** |
| 1377 | * Returns true if this value is an Uint8Array. |
| 1378 | * This is an experimental feature. |
| 1379 | */ |
| 1380 | bool IsUint8Array() const; |
| 1381 | |
| 1382 | /** |
| 1383 | * Returns true if this value is an Uint8ClampedArray. |
| 1384 | * This is an experimental feature. |
| 1385 | */ |
| 1386 | bool IsUint8ClampedArray() const; |
| 1387 | |
| 1388 | /** |
| 1389 | * Returns true if this value is an Int8Array. |
| 1390 | * This is an experimental feature. |
| 1391 | */ |
| 1392 | bool IsInt8Array() const; |
| 1393 | |
| 1394 | /** |
| 1395 | * Returns true if this value is an Uint16Array. |
| 1396 | * This is an experimental feature. |
| 1397 | */ |
| 1398 | bool IsUint16Array() const; |
| 1399 | |
| 1400 | /** |
| 1401 | * Returns true if this value is an Int16Array. |
| 1402 | * This is an experimental feature. |
| 1403 | */ |
| 1404 | bool IsInt16Array() const; |
| 1405 | |
| 1406 | /** |
| 1407 | * Returns true if this value is an Uint32Array. |
| 1408 | * This is an experimental feature. |
| 1409 | */ |
| 1410 | bool IsUint32Array() const; |
| 1411 | |
| 1412 | /** |
| 1413 | * Returns true if this value is an Int32Array. |
| 1414 | * This is an experimental feature. |
| 1415 | */ |
| 1416 | bool IsInt32Array() const; |
| 1417 | |
| 1418 | /** |
| 1419 | * Returns true if this value is a Float32Array. |
| 1420 | * This is an experimental feature. |
| 1421 | */ |
| 1422 | bool IsFloat32Array() const; |
| 1423 | |
| 1424 | /** |
| 1425 | * Returns true if this value is a Float64Array. |
| 1426 | * This is an experimental feature. |
| 1427 | */ |
| 1428 | bool IsFloat64Array() const; |
| 1429 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1430 | Local<Boolean> ToBoolean() const; |
| 1431 | Local<Number> ToNumber() const; |
| 1432 | Local<String> ToString() const; |
| 1433 | Local<String> ToDetailString() const; |
| 1434 | Local<Object> ToObject() const; |
| 1435 | Local<Integer> ToInteger() const; |
| 1436 | Local<Uint32> ToUint32() const; |
| 1437 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1438 | |
| 1439 | /** |
| 1440 | * Attempts to convert a string to an array index. |
| 1441 | * Returns an empty handle if the conversion fails. |
| 1442 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1443 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1445 | bool BooleanValue() const; |
| 1446 | double NumberValue() const; |
| 1447 | int64_t IntegerValue() const; |
| 1448 | uint32_t Uint32Value() const; |
| 1449 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1450 | |
| 1451 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1452 | bool Equals(Handle<Value> that) const; |
| 1453 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1454 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1455 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1456 | V8_INLINE(bool QuickIsUndefined() const); |
| 1457 | V8_INLINE(bool QuickIsNull() const); |
| 1458 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1459 | bool FullIsUndefined() const; |
| 1460 | bool FullIsNull() const; |
| 1461 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | }; |
| 1463 | |
| 1464 | |
| 1465 | /** |
| 1466 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1467 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1468 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | |
| 1470 | |
| 1471 | /** |
| 1472 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1473 | * or false value. |
| 1474 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1475 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1477 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1478 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | }; |
| 1480 | |
| 1481 | |
| 1482 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1483 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1484 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1485 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1487 | enum Encoding { |
| 1488 | UNKNOWN_ENCODING = 0x1, |
| 1489 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1490 | ASCII_ENCODING = 0x4, |
| 1491 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1492 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1493 | /** |
| 1494 | * Returns the number of characters in this string. |
| 1495 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1496 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1497 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1498 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1499 | * Returns the number of bytes in the UTF-8 encoded |
| 1500 | * representation of this string. |
| 1501 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1502 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1503 | |
| 1504 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1505 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1506 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1507 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1508 | |
| 1509 | /** |
| 1510 | * Returns whether this string contains only one byte data. |
| 1511 | */ |
| 1512 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1513 | |
| 1514 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1515 | * Write the contents of the string to an external buffer. |
| 1516 | * If no arguments are given, expects the buffer to be large |
| 1517 | * enough to hold the entire string and NULL terminator. Copies |
| 1518 | * the contents of the string and the NULL terminator into the |
| 1519 | * buffer. |
| 1520 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1521 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1522 | * before the end of the buffer. |
| 1523 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1524 | * Copies up to length characters into the output buffer. |
| 1525 | * Only null-terminates if there is enough space in the buffer. |
| 1526 | * |
| 1527 | * \param buffer The buffer into which the string will be copied. |
| 1528 | * \param start The starting position within the string at which |
| 1529 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1530 | * \param length The number of characters to copy from the string. For |
| 1531 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1532 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1533 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1534 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1535 | * \return The number of characters copied to the buffer excluding the null |
| 1536 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1537 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1538 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1539 | enum WriteOptions { |
| 1540 | NO_OPTIONS = 0, |
| 1541 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1542 | NO_NULL_TERMINATION = 2, |
| 1543 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1544 | }; |
| 1545 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1546 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1547 | int Write(uint16_t* buffer, |
| 1548 | int start = 0, |
| 1549 | int length = -1, |
| 1550 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1551 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1552 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1553 | int start = 0, |
| 1554 | int length = -1, |
| 1555 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1556 | // One byte characters. |
| 1557 | int WriteOneByte(uint8_t* buffer, |
| 1558 | int start = 0, |
| 1559 | int length = -1, |
| 1560 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1561 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1562 | int WriteUtf8(char* buffer, |
| 1563 | int length = -1, |
| 1564 | int* nchars_ref = NULL, |
| 1565 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1566 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1567 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1568 | * A zero length string. |
| 1569 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1570 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1571 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1572 | |
| 1573 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1574 | * Returns true if the string is external |
| 1575 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1576 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1577 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1578 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1579 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1580 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1581 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1582 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1583 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1584 | public: |
| 1585 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1586 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1587 | protected: |
| 1588 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1589 | |
| 1590 | /** |
| 1591 | * Internally V8 will call this Dispose method when the external string |
| 1592 | * resource is no longer needed. The default implementation will use the |
| 1593 | * delete operator. This method can be overridden in subclasses to |
| 1594 | * control how allocated external string resources are disposed. |
| 1595 | */ |
| 1596 | virtual void Dispose() { delete this; } |
| 1597 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1598 | private: |
| 1599 | // Disallow copying and assigning. |
| 1600 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1601 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1602 | |
| 1603 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1604 | }; |
| 1605 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1606 | /** |
| 1607 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1608 | * buffer that resides outside V8's heap. Implement an |
| 1609 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1610 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1611 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1612 | class V8EXPORT ExternalStringResource |
| 1613 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1614 | public: |
| 1615 | /** |
| 1616 | * Override the destructor to manage the life cycle of the underlying |
| 1617 | * buffer. |
| 1618 | */ |
| 1619 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1620 | |
| 1621 | /** |
| 1622 | * The string data from the underlying buffer. |
| 1623 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1624 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1625 | |
| 1626 | /** |
| 1627 | * The length of the string. That is, the number of two-byte characters. |
| 1628 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1629 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1630 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1631 | protected: |
| 1632 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | }; |
| 1634 | |
| 1635 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1636 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1637 | * string buffer that resides outside V8's heap. Implement an |
| 1638 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1639 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1640 | * 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] | 1641 | * UTF-8, which would require special treatment internally in the |
| 1642 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1643 | * 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] | 1644 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1646 | class V8EXPORT ExternalAsciiStringResource |
| 1647 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1648 | public: |
| 1649 | /** |
| 1650 | * Override the destructor to manage the life cycle of the underlying |
| 1651 | * buffer. |
| 1652 | */ |
| 1653 | virtual ~ExternalAsciiStringResource() {} |
| 1654 | /** The string data from the underlying buffer.*/ |
| 1655 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1656 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | virtual size_t length() const = 0; |
| 1658 | protected: |
| 1659 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | }; |
| 1661 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1662 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1663 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1664 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1665 | * If the string is an external string, return the ExternalStringResourceBase |
| 1666 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1667 | * string is returned in encoding_out. |
| 1668 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1669 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1670 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1671 | |
| 1672 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1673 | * Get the ExternalStringResource for an external string. Returns |
| 1674 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1675 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1676 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | |
| 1678 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1679 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1680 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1681 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1682 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1684 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1685 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1686 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1687 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1688 | * 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] | 1689 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1690 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1691 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1692 | 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] | 1693 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1694 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1695 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1696 | 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] | 1697 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1698 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1699 | /** |
| 1700 | * Creates an internalized string (historically called a "symbol", |
| 1701 | * 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] | 1702 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1703 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1704 | |
| 1705 | enum NewStringType { |
| 1706 | kNormalString, kInternalizedString, kUndetectableString |
| 1707 | }; |
| 1708 | |
| 1709 | /** Allocates a new string from UTF-8 data.*/ |
| 1710 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1711 | const char* data, |
| 1712 | NewStringType type = kNormalString, |
| 1713 | int length = -1); |
| 1714 | |
| 1715 | /** Allocates a new string from Latin-1 data.*/ |
| 1716 | static Local<String> NewFromOneByte( |
| 1717 | Isolate* isolate, |
| 1718 | const uint8_t* data, |
| 1719 | NewStringType type = kNormalString, |
| 1720 | int length = -1); |
| 1721 | |
| 1722 | /** Allocates a new string from UTF-16 data.*/ |
| 1723 | static Local<String> NewFromTwoByte( |
| 1724 | Isolate* isolate, |
| 1725 | const uint16_t* data, |
| 1726 | NewStringType type = kNormalString, |
| 1727 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1728 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1729 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1730 | * Creates a new string by concatenating the left and the right strings |
| 1731 | * passed in as parameters. |
| 1732 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1733 | 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] | 1734 | |
| 1735 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1736 | * 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] | 1737 | * 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] | 1738 | * resource will be disposed by calling its Dispose method. The caller of |
| 1739 | * this function should not otherwise delete or modify the resource. Neither |
| 1740 | * should the underlying buffer be deallocated or modified except through the |
| 1741 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1742 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1743 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1744 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1745 | /** |
| 1746 | * Associate an external string resource with this string by transforming it |
| 1747 | * in place so that existing references to this string in the JavaScript heap |
| 1748 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1749 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1750 | * 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] | 1751 | * The string is not modified if the operation fails. See NewExternal for |
| 1752 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1753 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1754 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1756 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1757 | * 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] | 1758 | * 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] | 1759 | * resource will be disposed by calling its Dispose method. The caller of |
| 1760 | * this function should not otherwise delete or modify the resource. Neither |
| 1761 | * should the underlying buffer be deallocated or modified except through the |
| 1762 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1763 | */ |
| 1764 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1765 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1766 | /** |
| 1767 | * Associate an external string resource with this string by transforming it |
| 1768 | * in place so that existing references to this string in the JavaScript heap |
| 1769 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1770 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1771 | * 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] | 1772 | * The string is not modified if the operation fails. See NewExternal for |
| 1773 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1774 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1775 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1776 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1777 | /** |
| 1778 | * Returns true if this string can be made external. |
| 1779 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1780 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1781 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1782 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1783 | /** 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] | 1784 | V8_INLINE( |
| 1785 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1787 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1788 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1789 | V8_INLINE(static Local<String> NewUndetectable( |
| 1790 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1791 | |
| 1792 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1793 | * 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] | 1794 | * 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] | 1795 | * (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] | 1796 | * then the length() method returns 0 and the * operator returns |
| 1797 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1798 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1799 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1800 | public: |
| 1801 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1802 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1803 | char* operator*() { return str_; } |
| 1804 | const char* operator*() const { return str_; } |
| 1805 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1806 | private: |
| 1807 | char* str_; |
| 1808 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1809 | |
| 1810 | // Disallow copying and assigning. |
| 1811 | Utf8Value(const Utf8Value&); |
| 1812 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1813 | }; |
| 1814 | |
| 1815 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1816 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1817 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1818 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1819 | * method of the object) then the length() method returns 0 and the * operator |
| 1820 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1821 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1822 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1823 | public: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1824 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1825 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1826 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1827 | char* operator*() { return str_; } |
| 1828 | const char* operator*() const { return str_; } |
| 1829 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | private: |
| 1831 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1832 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1833 | |
| 1834 | // Disallow copying and assigning. |
| 1835 | AsciiValue(const AsciiValue&); |
| 1836 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1837 | }; |
| 1838 | |
| 1839 | /** |
| 1840 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1841 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1842 | * method of the object) then the length() method returns 0 and the * operator |
| 1843 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1844 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1845 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1846 | public: |
| 1847 | explicit Value(Handle<v8::Value> obj); |
| 1848 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1849 | uint16_t* operator*() { return str_; } |
| 1850 | const uint16_t* operator*() const { return str_; } |
| 1851 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | private: |
| 1853 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1854 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1855 | |
| 1856 | // Disallow copying and assigning. |
| 1857 | Value(const Value&); |
| 1858 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1860 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1861 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1862 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1863 | Encoding encoding) const; |
| 1864 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1865 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1866 | }; |
| 1867 | |
| 1868 | |
| 1869 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1870 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1871 | * |
| 1872 | * This is an experimental feature. Use at your own risk. |
| 1873 | */ |
| 1874 | class V8EXPORT Symbol : public Primitive { |
| 1875 | public: |
| 1876 | // Returns the print name string of the symbol, or undefined if none. |
| 1877 | Local<Value> Name() const; |
| 1878 | |
| 1879 | // Create a symbol without a print name. |
| 1880 | static Local<Symbol> New(Isolate* isolate); |
| 1881 | |
| 1882 | // Create a symbol with a print name. |
| 1883 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1884 | |
| 1885 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1886 | private: |
| 1887 | Symbol(); |
| 1888 | static void CheckCast(v8::Value* obj); |
| 1889 | }; |
| 1890 | |
| 1891 | |
| 1892 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1893 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1895 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1896 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1897 | double Value() const; |
| 1898 | static Local<Number> New(double value); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1899 | static Local<Number> New(Isolate* isolate, double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1900 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1901 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1902 | Number(); |
| 1903 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | }; |
| 1905 | |
| 1906 | |
| 1907 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1908 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1909 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1910 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1912 | static Local<Integer> New(int32_t value); |
| 1913 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1914 | static Local<Integer> New(int32_t value, Isolate*); |
| 1915 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1916 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1917 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1918 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1919 | Integer(); |
| 1920 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | }; |
| 1922 | |
| 1923 | |
| 1924 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1925 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1926 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1927 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1928 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1929 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1930 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1931 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1932 | }; |
| 1933 | |
| 1934 | |
| 1935 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1936 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1937 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1938 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1939 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1940 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1941 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1942 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1943 | }; |
| 1944 | |
| 1945 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1946 | enum PropertyAttribute { |
| 1947 | None = 0, |
| 1948 | ReadOnly = 1 << 0, |
| 1949 | DontEnum = 1 << 1, |
| 1950 | DontDelete = 1 << 2 |
| 1951 | }; |
| 1952 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1953 | enum ExternalArrayType { |
| 1954 | kExternalByteArray = 1, |
| 1955 | kExternalUnsignedByteArray, |
| 1956 | kExternalShortArray, |
| 1957 | kExternalUnsignedShortArray, |
| 1958 | kExternalIntArray, |
| 1959 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1960 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1961 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1962 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1963 | }; |
| 1964 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1965 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1966 | * Accessor[Getter|Setter] are used as callback functions when |
| 1967 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1968 | * method SetAccessor. |
| 1969 | */ |
| 1970 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1971 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1972 | typedef void (*AccessorGetterCallback)( |
| 1973 | Local<String> property, |
| 1974 | const PropertyCallbackInfo<Value>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1975 | |
| 1976 | |
| 1977 | typedef void (*AccessorSetter)(Local<String> property, |
| 1978 | Local<Value> value, |
| 1979 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1980 | typedef void (*AccessorSetterCallback)( |
| 1981 | Local<String> property, |
| 1982 | Local<Value> value, |
| 1983 | const PropertyCallbackInfo<void>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1984 | |
| 1985 | |
| 1986 | /** |
| 1987 | * Access control specifications. |
| 1988 | * |
| 1989 | * Some accessors should be accessible across contexts. These |
| 1990 | * accessors have an explicit access control parameter which specifies |
| 1991 | * the kind of cross-context access that should be allowed. |
| 1992 | * |
| 1993 | * Additionally, for security, accessors can prohibit overwriting by |
| 1994 | * accessors defined in JavaScript. For objects that have such |
| 1995 | * accessors either locally or in their prototype chain it is not |
| 1996 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1997 | * __defineSetter__ from JavaScript code. |
| 1998 | */ |
| 1999 | enum AccessControl { |
| 2000 | DEFAULT = 0, |
| 2001 | ALL_CAN_READ = 1, |
| 2002 | ALL_CAN_WRITE = 1 << 1, |
| 2003 | PROHIBITS_OVERWRITING = 1 << 2 |
| 2004 | }; |
| 2005 | |
| 2006 | |
| 2007 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2008 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2009 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2010 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2011 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2012 | bool Set(Handle<Value> key, |
| 2013 | Handle<Value> value, |
| 2014 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2015 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2016 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2017 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2018 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2019 | // overriding accessors or read-only properties. |
| 2020 | // |
| 2021 | // Note that if the object has an interceptor the property will be set |
| 2022 | // locally, but since the interceptor takes precedence the local property |
| 2023 | // will only be returned if the interceptor doesn't return a value. |
| 2024 | // |
| 2025 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2026 | bool ForceSet(Handle<Value> key, |
| 2027 | Handle<Value> value, |
| 2028 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2029 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2030 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2032 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2033 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2034 | /** |
| 2035 | * Gets the property attributes of a property which can be None or |
| 2036 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 2037 | * None when the property doesn't exist. |
| 2038 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2039 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2040 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2041 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2042 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2043 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2044 | |
| 2045 | // Delete a property on this object bypassing interceptors and |
| 2046 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2047 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2048 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2049 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2050 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2051 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2053 | // TODO(dcarney): deprecate |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2054 | bool SetAccessor(Handle<String> name, |
| 2055 | AccessorGetter getter, |
| 2056 | AccessorSetter setter = 0, |
| 2057 | Handle<Value> data = Handle<Value>(), |
| 2058 | AccessControl settings = DEFAULT, |
| 2059 | PropertyAttribute attribute = None); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2060 | bool SetAccessor(Handle<String> name, |
| 2061 | AccessorGetterCallback getter, |
| 2062 | AccessorSetterCallback setter = 0, |
| 2063 | Handle<Value> data = Handle<Value>(), |
| 2064 | AccessControl settings = DEFAULT, |
| 2065 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2066 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2067 | // This function is not yet stable and should not be used at this time. |
| 2068 | bool SetAccessor(Handle<String> name, |
| 2069 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2070 | AccessControl settings = DEFAULT, |
| 2071 | PropertyAttribute attribute = None); |
| 2072 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2073 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2074 | * Returns an array containing the names of the enumerable properties |
| 2075 | * of this object, including properties from prototype objects. The |
| 2076 | * array returned by this method contains the same values as would |
| 2077 | * be enumerated by a for-in statement over this object. |
| 2078 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2079 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2080 | |
| 2081 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2082 | * This function has the same functionality as GetPropertyNames but |
| 2083 | * the returned array doesn't contain the names of properties from |
| 2084 | * prototype objects. |
| 2085 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2086 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2087 | |
| 2088 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2089 | * Get the prototype object. This does not skip objects marked to |
| 2090 | * be skipped by __proto__ and it does not consult the security |
| 2091 | * handler. |
| 2092 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2093 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2094 | |
| 2095 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2096 | * Set the prototype object. This does not skip objects marked to |
| 2097 | * be skipped by __proto__ and it does not consult the security |
| 2098 | * handler. |
| 2099 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2100 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2101 | |
| 2102 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2103 | * Finds an instance of the given function template in the prototype |
| 2104 | * chain. |
| 2105 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2106 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2107 | |
| 2108 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2109 | * Call builtin Object.prototype.toString on this object. |
| 2110 | * This is different from Value::ToString() that may call |
| 2111 | * user-defined toString function. This one does not. |
| 2112 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2113 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2114 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2115 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2116 | * Returns the function invoked as a constructor for this object. |
| 2117 | * May be the null value. |
| 2118 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2119 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2120 | |
| 2121 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2122 | * Returns the name of the function invoked as a constructor for this object. |
| 2123 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2124 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2125 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2126 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2127 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2128 | |
| 2129 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2130 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2131 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2132 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2133 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2134 | |
| 2135 | /** |
| 2136 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2137 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2138 | * leads to undefined behavior. |
| 2139 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2140 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2141 | |
| 2142 | /** |
| 2143 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2144 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2145 | * leads to undefined behavior. |
| 2146 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2147 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2148 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2149 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2150 | bool HasOwnProperty(Handle<String> key); |
| 2151 | bool HasRealNamedProperty(Handle<String> key); |
| 2152 | bool HasRealIndexedProperty(uint32_t index); |
| 2153 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2154 | |
| 2155 | /** |
| 2156 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2157 | * This means interceptors in the prototype chain are not called. |
| 2158 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2159 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2160 | |
| 2161 | /** |
| 2162 | * If result.IsEmpty() no real property was located on the object or |
| 2163 | * in the prototype chain. |
| 2164 | * This means interceptors in the prototype chain are not called. |
| 2165 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2166 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2167 | |
| 2168 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2169 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2170 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2171 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2172 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2173 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2174 | /** |
| 2175 | * Turns on access check on the object if the object is an instance of |
| 2176 | * a template that has access check callbacks. If an object has no |
| 2177 | * access check info, the object cannot be accessed by anyone. |
| 2178 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2179 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2180 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2181 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2182 | * Returns the identity hash for this object. The current implementation |
| 2183 | * 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] | 2184 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2185 | * 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] | 2186 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2187 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2188 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2189 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2190 | /** |
| 2191 | * Access hidden properties on JavaScript objects. These properties are |
| 2192 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2193 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2194 | * identity hash) are prefixed with "v8::". |
| 2195 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2196 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2197 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2198 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2199 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2200 | /** |
| 2201 | * Returns true if this is an instance of an api function (one |
| 2202 | * created from a function created from a function template) and has |
| 2203 | * been modified since it was created. Note that this method is |
| 2204 | * conservative and may return true for objects that haven't actually |
| 2205 | * been modified. |
| 2206 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2207 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2208 | |
| 2209 | /** |
| 2210 | * Clone this object with a fast but shallow copy. Values will point |
| 2211 | * to the same values as the original object. |
| 2212 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2213 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2214 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2215 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2216 | * Returns the context in which the object was created. |
| 2217 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2218 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2219 | |
| 2220 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2221 | * Set the backing store of the indexed properties to be managed by the |
| 2222 | * embedding layer. Access to the indexed properties will follow the rules |
| 2223 | * spelled out in CanvasPixelArray. |
| 2224 | * Note: The embedding program still owns the data and needs to ensure that |
| 2225 | * the backing store is preserved while V8 has a reference. |
| 2226 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2227 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2228 | bool HasIndexedPropertiesInPixelData(); |
| 2229 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2230 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2231 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2232 | /** |
| 2233 | * Set the backing store of the indexed properties to be managed by the |
| 2234 | * embedding layer. Access to the indexed properties will follow the rules |
| 2235 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2236 | * Note: The embedding program still owns the data and needs to ensure that |
| 2237 | * the backing store is preserved while V8 has a reference. |
| 2238 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2239 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2240 | ExternalArrayType array_type, |
| 2241 | int number_of_elements); |
| 2242 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2243 | void* GetIndexedPropertiesExternalArrayData(); |
| 2244 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2245 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2246 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2247 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2248 | * Checks whether a callback is set by the |
| 2249 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2250 | * When an Object is callable this method returns true. |
| 2251 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2252 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2253 | |
| 2254 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2255 | * 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] | 2256 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2257 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2258 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2259 | int argc, |
| 2260 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2261 | |
| 2262 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2263 | * 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] | 2264 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2265 | * Note: This method behaves like the Function::NewInstance method. |
| 2266 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2267 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2268 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2269 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2270 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2271 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2272 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2273 | Object(); |
| 2274 | static void CheckCast(Value* obj); |
| 2275 | Local<Value> SlowGetInternalField(int index); |
| 2276 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2277 | }; |
| 2278 | |
| 2279 | |
| 2280 | /** |
| 2281 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2282 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2283 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2284 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2285 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2287 | /** |
| 2288 | * Clones an element at index |index|. Returns an empty |
| 2289 | * handle if cloning fails (for any reason). |
| 2290 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2291 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2292 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2293 | /** |
| 2294 | * Creates a JavaScript array with the given length. If the length |
| 2295 | * is negative the returned array will have length 0. |
| 2296 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2297 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2298 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2299 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2300 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2301 | Array(); |
| 2302 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2303 | }; |
| 2304 | |
| 2305 | |
| 2306 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2307 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2308 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2309 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2310 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2311 | Local<Object> NewInstance() const; |
| 2312 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2313 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2314 | void SetName(Handle<String> name); |
| 2315 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2316 | |
| 2317 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2318 | * Name inferred from variable or property assignment of this function. |
| 2319 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2320 | * in an OO style, where many functions are anonymous but are assigned |
| 2321 | * to object properties. |
| 2322 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2323 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2324 | |
| 2325 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2326 | * Returns zero based line number of function body and |
| 2327 | * kLineOffsetNotFound if no information available. |
| 2328 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2329 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2330 | /** |
| 2331 | * Returns zero based column number of function body and |
| 2332 | * kLineOffsetNotFound if no information available. |
| 2333 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2334 | int GetScriptColumnNumber() const; |
| 2335 | Handle<Value> GetScriptId() const; |
| 2336 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2337 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2338 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2339 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2341 | Function(); |
| 2342 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | }; |
| 2344 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2345 | /** |
| 2346 | * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 2347 | * populates an instance of this class with a pointer to data and byte length. |
| 2348 | * |
| 2349 | * |ArrayBufferContents| is the owner of its data. When an instance of |
| 2350 | * this class is destructed, the |Data| is freed. |
| 2351 | * |
| 2352 | * This API is experimental and may change significantly. |
| 2353 | */ |
| 2354 | class V8EXPORT ArrayBufferContents { |
| 2355 | public: |
| 2356 | ArrayBufferContents() : data_(NULL), byte_length_(0) {} |
| 2357 | ~ArrayBufferContents(); |
| 2358 | |
| 2359 | void* Data() const { return data_; } |
| 2360 | size_t ByteLength() const { return byte_length_; } |
| 2361 | |
| 2362 | private: |
| 2363 | void* data_; |
| 2364 | size_t byte_length_; |
| 2365 | |
| 2366 | friend class ArrayBuffer; |
| 2367 | }; |
| 2368 | |
| 2369 | #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 2370 | #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
| 2371 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2372 | |
| 2373 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2374 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2375 | * This API is experimental and may change significantly. |
| 2376 | */ |
| 2377 | class V8EXPORT ArrayBuffer : public Object { |
| 2378 | public: |
| 2379 | /** |
| 2380 | * Data length in bytes. |
| 2381 | */ |
| 2382 | size_t ByteLength() const; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2383 | |
| 2384 | /** |
| 2385 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2386 | * Allocated memory will be owned by a created ArrayBuffer and |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2387 | * will be deallocated when it is garbage-collected, |
| 2388 | * unless the object is externalized. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2389 | */ |
| 2390 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2391 | |
| 2392 | /** |
| 2393 | * Create a new ArrayBuffer over an existing memory block. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2394 | * The created array buffer is immediately in externalized state. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2395 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2396 | * is garbage-collected. |
| 2397 | */ |
| 2398 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2399 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2400 | /** |
| 2401 | * Returns true if ArrayBuffer is extrenalized, that is, does not |
| 2402 | * own its memory block. |
| 2403 | */ |
| 2404 | bool IsExternal() const; |
| 2405 | |
| 2406 | /** |
| 2407 | * Pass the ownership of this ArrayBuffer's backing store to |
| 2408 | * a given ArrayBufferContents. |
| 2409 | */ |
| 2410 | void Externalize(ArrayBufferContents* contents); |
| 2411 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2412 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2413 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2414 | |
| 2415 | static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
| 2416 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2417 | private: |
| 2418 | ArrayBuffer(); |
| 2419 | static void CheckCast(Value* obj); |
| 2420 | }; |
| 2421 | |
| 2422 | |
| 2423 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2424 | * A base class for an instance of TypedArray series of constructors |
| 2425 | * (ES6 draft 15.13.6). |
| 2426 | * This API is experimental and may change significantly. |
| 2427 | */ |
| 2428 | class V8EXPORT TypedArray : public Object { |
| 2429 | public: |
| 2430 | /** |
| 2431 | * Returns underlying ArrayBuffer. |
| 2432 | */ |
| 2433 | Local<ArrayBuffer> Buffer(); |
| 2434 | /** |
| 2435 | * Byte offset in |Buffer| |
| 2436 | */ |
| 2437 | size_t ByteOffset(); |
| 2438 | /** |
| 2439 | * Numbe of elements in this typed array. |
| 2440 | */ |
| 2441 | size_t Length(); |
| 2442 | /** |
| 2443 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2444 | */ |
| 2445 | size_t ByteLength(); |
| 2446 | /** |
| 2447 | * Base address of typed array. |
| 2448 | */ |
| 2449 | void* BaseAddress(); |
| 2450 | |
| 2451 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2452 | |
| 2453 | private: |
| 2454 | TypedArray(); |
| 2455 | static void CheckCast(Value* obj); |
| 2456 | }; |
| 2457 | |
| 2458 | |
| 2459 | /** |
| 2460 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2461 | * This API is experimental and may change significantly. |
| 2462 | */ |
| 2463 | class V8EXPORT Uint8Array : public TypedArray { |
| 2464 | public: |
| 2465 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2466 | size_t byte_offset, size_t length); |
| 2467 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2468 | |
| 2469 | private: |
| 2470 | Uint8Array(); |
| 2471 | static void CheckCast(Value* obj); |
| 2472 | }; |
| 2473 | |
| 2474 | |
| 2475 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2476 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2477 | * This API is experimental and may change significantly. |
| 2478 | */ |
| 2479 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2480 | public: |
| 2481 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2482 | size_t byte_offset, size_t length); |
| 2483 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2484 | |
| 2485 | private: |
| 2486 | Uint8ClampedArray(); |
| 2487 | static void CheckCast(Value* obj); |
| 2488 | }; |
| 2489 | |
| 2490 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2491 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2492 | * This API is experimental and may change significantly. |
| 2493 | */ |
| 2494 | class V8EXPORT Int8Array : public TypedArray { |
| 2495 | public: |
| 2496 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2497 | size_t byte_offset, size_t length); |
| 2498 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2499 | |
| 2500 | private: |
| 2501 | Int8Array(); |
| 2502 | static void CheckCast(Value* obj); |
| 2503 | }; |
| 2504 | |
| 2505 | |
| 2506 | /** |
| 2507 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2508 | * This API is experimental and may change significantly. |
| 2509 | */ |
| 2510 | class V8EXPORT Uint16Array : public TypedArray { |
| 2511 | public: |
| 2512 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2513 | size_t byte_offset, size_t length); |
| 2514 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2515 | |
| 2516 | private: |
| 2517 | Uint16Array(); |
| 2518 | static void CheckCast(Value* obj); |
| 2519 | }; |
| 2520 | |
| 2521 | |
| 2522 | /** |
| 2523 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2524 | * This API is experimental and may change significantly. |
| 2525 | */ |
| 2526 | class V8EXPORT Int16Array : public TypedArray { |
| 2527 | public: |
| 2528 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2529 | size_t byte_offset, size_t length); |
| 2530 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2531 | |
| 2532 | private: |
| 2533 | Int16Array(); |
| 2534 | static void CheckCast(Value* obj); |
| 2535 | }; |
| 2536 | |
| 2537 | |
| 2538 | /** |
| 2539 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2540 | * This API is experimental and may change significantly. |
| 2541 | */ |
| 2542 | class V8EXPORT Uint32Array : public TypedArray { |
| 2543 | public: |
| 2544 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2545 | size_t byte_offset, size_t length); |
| 2546 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2547 | |
| 2548 | private: |
| 2549 | Uint32Array(); |
| 2550 | static void CheckCast(Value* obj); |
| 2551 | }; |
| 2552 | |
| 2553 | |
| 2554 | /** |
| 2555 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2556 | * This API is experimental and may change significantly. |
| 2557 | */ |
| 2558 | class V8EXPORT Int32Array : public TypedArray { |
| 2559 | public: |
| 2560 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2561 | size_t byte_offset, size_t length); |
| 2562 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2563 | |
| 2564 | private: |
| 2565 | Int32Array(); |
| 2566 | static void CheckCast(Value* obj); |
| 2567 | }; |
| 2568 | |
| 2569 | |
| 2570 | /** |
| 2571 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2572 | * This API is experimental and may change significantly. |
| 2573 | */ |
| 2574 | class V8EXPORT Float32Array : public TypedArray { |
| 2575 | public: |
| 2576 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2577 | size_t byte_offset, size_t length); |
| 2578 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2579 | |
| 2580 | private: |
| 2581 | Float32Array(); |
| 2582 | static void CheckCast(Value* obj); |
| 2583 | }; |
| 2584 | |
| 2585 | |
| 2586 | /** |
| 2587 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2588 | * This API is experimental and may change significantly. |
| 2589 | */ |
| 2590 | class V8EXPORT Float64Array : public TypedArray { |
| 2591 | public: |
| 2592 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2593 | size_t byte_offset, size_t length); |
| 2594 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2595 | |
| 2596 | private: |
| 2597 | Float64Array(); |
| 2598 | static void CheckCast(Value* obj); |
| 2599 | }; |
| 2600 | |
| 2601 | |
| 2602 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2603 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2604 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2605 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2606 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2607 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2608 | |
| 2609 | /** |
| 2610 | * A specialization of Value::NumberValue that is more efficient |
| 2611 | * because we know the structure of this object. |
| 2612 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2613 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2614 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2615 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2616 | |
| 2617 | /** |
| 2618 | * Notification that the embedder has changed the time zone, |
| 2619 | * daylight savings time, or other date / time configuration |
| 2620 | * parameters. V8 keeps a cache of various values used for |
| 2621 | * date / time computation. This notification will reset |
| 2622 | * those cached values for the current context so that date / |
| 2623 | * time configuration changes would be reflected in the Date |
| 2624 | * object. |
| 2625 | * |
| 2626 | * This API should not be called more than needed as it will |
| 2627 | * negatively impact the performance of date operations. |
| 2628 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2629 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2630 | |
| 2631 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2632 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2633 | }; |
| 2634 | |
| 2635 | |
| 2636 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2637 | * A Number object (ECMA-262, 4.3.21). |
| 2638 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2639 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2640 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2641 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2642 | |
| 2643 | /** |
| 2644 | * Returns the Number held by the object. |
| 2645 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2646 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2647 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2648 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2649 | |
| 2650 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2651 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2652 | }; |
| 2653 | |
| 2654 | |
| 2655 | /** |
| 2656 | * A Boolean object (ECMA-262, 4.3.15). |
| 2657 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2658 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2659 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2660 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2661 | |
| 2662 | /** |
| 2663 | * Returns the Boolean held by the object. |
| 2664 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2665 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2666 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2667 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +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); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2671 | }; |
| 2672 | |
| 2673 | |
| 2674 | /** |
| 2675 | * A String object (ECMA-262, 4.3.18). |
| 2676 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2677 | class V8EXPORT StringObject : 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(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2680 | |
| 2681 | /** |
| 2682 | * Returns the String held by the object. |
| 2683 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2684 | Local<String> StringValue() 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 StringObject* 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 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2694 | * A Symbol object (ECMA-262 edition 6). |
| 2695 | * |
| 2696 | * This is an experimental feature. Use at your own risk. |
| 2697 | */ |
| 2698 | class V8EXPORT SymbolObject : public Object { |
| 2699 | public: |
| 2700 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2701 | |
| 2702 | /** |
| 2703 | * Returns the Symbol held by the object. |
| 2704 | */ |
| 2705 | Local<Symbol> SymbolValue() const; |
| 2706 | |
| 2707 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2708 | |
| 2709 | private: |
| 2710 | static void CheckCast(v8::Value* obj); |
| 2711 | }; |
| 2712 | |
| 2713 | |
| 2714 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2715 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2716 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2717 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2718 | public: |
| 2719 | /** |
| 2720 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2721 | * of flags. |
| 2722 | */ |
| 2723 | enum Flags { |
| 2724 | kNone = 0, |
| 2725 | kGlobal = 1, |
| 2726 | kIgnoreCase = 2, |
| 2727 | kMultiline = 4 |
| 2728 | }; |
| 2729 | |
| 2730 | /** |
| 2731 | * Creates a regular expression from the given pattern string and |
| 2732 | * the flags bit field. May throw a JavaScript exception as |
| 2733 | * described in ECMA-262, 15.10.4.1. |
| 2734 | * |
| 2735 | * For example, |
| 2736 | * RegExp::New(v8::String::New("foo"), |
| 2737 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2738 | * is equivalent to evaluating "/foo/gm". |
| 2739 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2740 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2741 | |
| 2742 | /** |
| 2743 | * Returns the value of the source property: a string representing |
| 2744 | * the regular expression. |
| 2745 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2746 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2747 | |
| 2748 | /** |
| 2749 | * Returns the flags bit field. |
| 2750 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2751 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2752 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2753 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2754 | |
| 2755 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2756 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2757 | }; |
| 2758 | |
| 2759 | |
| 2760 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2761 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2762 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2763 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2764 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2765 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2766 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2767 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2768 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2769 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2770 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2771 | }; |
| 2772 | |
| 2773 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2774 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2775 | |
| 2776 | |
| 2777 | /** |
| 2778 | * The superclass of object and function templates. |
| 2779 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2780 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2781 | public: |
| 2782 | /** Adds a property to each instance created by this template.*/ |
| 2783 | void Set(Handle<String> name, Handle<Data> value, |
| 2784 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2785 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2786 | private: |
| 2787 | Template(); |
| 2788 | |
| 2789 | friend class ObjectTemplate; |
| 2790 | friend class FunctionTemplate; |
| 2791 | }; |
| 2792 | |
| 2793 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2794 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2795 | class ReturnValue { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2796 | public: |
| 2797 | V8_INLINE(explicit ReturnValue(internal::Object** slot)); |
| 2798 | // Handle setters |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 2799 | template <typename S> V8_INLINE(void Set(const Persistent<S>& handle)); |
| 2800 | template <typename S> V8_INLINE(void Set(const Handle<S> handle)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2801 | // Fast primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2802 | V8_INLINE(void Set(bool value)); |
| 2803 | V8_INLINE(void Set(double i)); |
| 2804 | V8_INLINE(void Set(int32_t i)); |
| 2805 | V8_INLINE(void Set(uint32_t i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2806 | // Fast JS primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2807 | V8_INLINE(void SetNull()); |
| 2808 | V8_INLINE(void SetUndefined()); |
| 2809 | // Convenience getter for Isolate |
| 2810 | V8_INLINE(Isolate* GetIsolate()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2811 | private: |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2812 | internal::Object** value_; |
| 2813 | }; |
| 2814 | |
| 2815 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2816 | /** |
| 2817 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2818 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2819 | * including the receiver, the number and values of arguments, and |
| 2820 | * the holder of the function. |
| 2821 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2822 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2823 | class FunctionCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2824 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2825 | V8_INLINE(int Length() const); |
| 2826 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2827 | V8_INLINE(Local<Function> Callee() const); |
| 2828 | V8_INLINE(Local<Object> This() const); |
| 2829 | V8_INLINE(Local<Object> Holder() const); |
| 2830 | V8_INLINE(bool IsConstructCall() const); |
| 2831 | V8_INLINE(Local<Value> Data() const); |
| 2832 | V8_INLINE(Isolate* GetIsolate() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2833 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2834 | // This shouldn't be public, but the arm compiler needs it. |
| 2835 | static const int kArgsLength = 5; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2836 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2837 | protected: |
| 2838 | friend class internal::FunctionCallbackArguments; |
| 2839 | friend class internal::CustomArguments<FunctionCallbackInfo>; |
| 2840 | static const int kReturnValueIndex = 0; |
| 2841 | static const int kIsolateIndex = -1; |
| 2842 | static const int kDataIndex = -2; |
| 2843 | static const int kCalleeIndex = -3; |
| 2844 | static const int kHolderIndex = -4; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2845 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2846 | V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2847 | internal::Object** values, |
| 2848 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2849 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2850 | internal::Object** implicit_args_; |
| 2851 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2852 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2853 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2854 | }; |
| 2855 | |
| 2856 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2857 | class V8EXPORT Arguments : public FunctionCallbackInfo<Value> { |
| 2858 | private: |
| 2859 | friend class internal::FunctionCallbackArguments; |
| 2860 | V8_INLINE(Arguments(internal::Object** implicit_args, |
| 2861 | internal::Object** values, |
| 2862 | int length, |
| 2863 | bool is_construct_call)); |
| 2864 | }; |
| 2865 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2866 | /** |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2867 | * The information passed to a property callback about the context |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2868 | * of the property access. |
| 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 PropertyCallbackInfo { |
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(Isolate* GetIsolate() const); |
| 2874 | V8_INLINE(Local<Value> Data() const); |
| 2875 | V8_INLINE(Local<Object> This() const); |
| 2876 | V8_INLINE(Local<Object> Holder() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2877 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2878 | // This shouldn't be public, but the arm compiler needs it. |
| 2879 | static const int kArgsLength = 5; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2880 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2881 | protected: |
| 2882 | friend class MacroAssembler; |
| 2883 | friend class internal::PropertyCallbackArguments; |
| 2884 | friend class internal::CustomArguments<PropertyCallbackInfo>; |
| 2885 | static const int kThisIndex = 0; |
| 2886 | static const int kHolderIndex = -1; |
| 2887 | static const int kDataIndex = -2; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2888 | static const int kReturnValueIndex = -3; |
| 2889 | static const int kIsolateIndex = -4; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2890 | |
| 2891 | V8_INLINE(PropertyCallbackInfo(internal::Object** args)) |
| 2892 | : args_(args) { } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2893 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2894 | }; |
| 2895 | |
| 2896 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2897 | class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> { |
| 2898 | private: |
| 2899 | friend class internal::PropertyCallbackArguments; |
| 2900 | V8_INLINE(AccessorInfo(internal::Object** args)) |
| 2901 | : PropertyCallbackInfo<Value>(args) { } |
| 2902 | }; |
| 2903 | |
| 2904 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2905 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2906 | typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2907 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2908 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2909 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2910 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2911 | */ |
| 2912 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2913 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2914 | typedef void (*NamedPropertyGetterCallback)( |
| 2915 | Local<String> property, |
| 2916 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2917 | |
| 2918 | |
| 2919 | /** |
| 2920 | * Returns the value if the setter intercepts the request. |
| 2921 | * Otherwise, returns an empty handle. |
| 2922 | */ |
| 2923 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2924 | Local<Value> value, |
| 2925 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2926 | typedef void (*NamedPropertySetterCallback)( |
| 2927 | Local<String> property, |
| 2928 | Local<Value> value, |
| 2929 | const PropertyCallbackInfo<Value>& info); |
| 2930 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2931 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2932 | /** |
| 2933 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2934 | * The result is an integer encoding property attributes (like v8::None, |
| 2935 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2936 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2937 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2938 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2939 | typedef void (*NamedPropertyQueryCallback)( |
| 2940 | Local<String> property, |
| 2941 | const PropertyCallbackInfo<Integer>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2942 | |
| 2943 | |
| 2944 | /** |
| 2945 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2946 | * The return value is true if the property could be deleted and false |
| 2947 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | */ |
| 2949 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2950 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2951 | typedef void (*NamedPropertyDeleterCallback)( |
| 2952 | Local<String> property, |
| 2953 | const PropertyCallbackInfo<Boolean>& info); |
| 2954 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | |
| 2956 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2957 | * Returns an array containing the names of the properties the named |
| 2958 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2959 | */ |
| 2960 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2961 | typedef void (*NamedPropertyEnumeratorCallback)( |
| 2962 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2963 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2964 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2965 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2966 | * Returns the value of the property if the getter intercepts the |
| 2967 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2968 | */ |
| 2969 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 2970 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2971 | typedef void (*IndexedPropertyGetterCallback)( |
| 2972 | uint32_t index, |
| 2973 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2974 | |
| 2975 | |
| 2976 | /** |
| 2977 | * Returns the value if the setter intercepts the request. |
| 2978 | * Otherwise, returns an empty handle. |
| 2979 | */ |
| 2980 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 2981 | Local<Value> value, |
| 2982 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2983 | typedef void (*IndexedPropertySetterCallback)( |
| 2984 | uint32_t index, |
| 2985 | Local<Value> value, |
| 2986 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2987 | |
| 2988 | |
| 2989 | /** |
| 2990 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2991 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2992 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2993 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 2994 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2995 | typedef void (*IndexedPropertyQueryCallback)( |
| 2996 | uint32_t index, |
| 2997 | const PropertyCallbackInfo<Integer>& info); |
| 2998 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2999 | |
| 3000 | /** |
| 3001 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3002 | * The return value is true if the property could be deleted and false |
| 3003 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3004 | */ |
| 3005 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 3006 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3007 | typedef void (*IndexedPropertyDeleterCallback)( |
| 3008 | uint32_t index, |
| 3009 | const PropertyCallbackInfo<Boolean>& info); |
| 3010 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3011 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3012 | /** |
| 3013 | * Returns an array containing the indices of the properties the |
| 3014 | * indexed property getter intercepts. |
| 3015 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3016 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3017 | typedef void (*IndexedPropertyEnumeratorCallback)( |
| 3018 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3019 | |
| 3020 | |
| 3021 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3022 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3023 | */ |
| 3024 | enum AccessType { |
| 3025 | ACCESS_GET, |
| 3026 | ACCESS_SET, |
| 3027 | ACCESS_HAS, |
| 3028 | ACCESS_DELETE, |
| 3029 | ACCESS_KEYS |
| 3030 | }; |
| 3031 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3032 | |
| 3033 | /** |
| 3034 | * 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] | 3035 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3036 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3037 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3038 | Local<Value> key, |
| 3039 | AccessType type, |
| 3040 | Local<Value> data); |
| 3041 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3042 | |
| 3043 | /** |
| 3044 | * 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] | 3045 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3046 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3047 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3048 | uint32_t index, |
| 3049 | AccessType type, |
| 3050 | Local<Value> data); |
| 3051 | |
| 3052 | |
| 3053 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3054 | * A FunctionTemplate is used to create functions at runtime. There |
| 3055 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3056 | * context. The lifetime of the created function is equal to the |
| 3057 | * lifetime of the context. So in case the embedder needs to create |
| 3058 | * temporary functions that can be collected using Scripts is |
| 3059 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3060 | * |
| 3061 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3062 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3063 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3064 | * A FunctionTemplate has a corresponding instance template which is |
| 3065 | * used to create object instances when the function is used as a |
| 3066 | * constructor. Properties added to the instance template are added to |
| 3067 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3068 | * |
| 3069 | * A FunctionTemplate can have a prototype template. The prototype template |
| 3070 | * is used to create the prototype object of the function. |
| 3071 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3072 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3074 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3075 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 3076 | * t->Set("func_property", v8::Number::New(1)); |
| 3077 | * |
| 3078 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 3079 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 3080 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 3081 | * |
| 3082 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 3083 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 3084 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 3085 | * instance_t->Set("instance_property", Number::New(3)); |
| 3086 | * |
| 3087 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 3088 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3089 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3090 | * |
| 3091 | * 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] | 3092 | * and "instance" for the instance object created above. The function |
| 3093 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3094 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3095 | * \code |
| 3096 | * func_property in function == true; |
| 3097 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3098 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3099 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 3100 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3101 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3102 | * instance instanceof function == true; |
| 3103 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 3104 | * instance.instance_property == 3; |
| 3105 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3106 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3107 | * A FunctionTemplate can inherit from another one by calling the |
| 3108 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 3109 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3110 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3111 | * \code |
| 3112 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 3113 | * ^ ^ |
| 3114 | * | Inherit(Parent) | .__proto__ |
| 3115 | * | | |
| 3116 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 3117 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3118 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3119 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 3120 | * object of the Child() function has __proto__ pointing to the |
| 3121 | * Parent() function's prototype object. An instance of the Child |
| 3122 | * function has all properties on Parent's instance templates. |
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 | * Let Parent be the FunctionTemplate initialized in the previous |
| 3125 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3126 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3127 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3128 | * Local<FunctionTemplate> parent = t; |
| 3129 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 3130 | * child->Inherit(parent); |
| 3131 | * |
| 3132 | * Local<Function> child_function = child->GetFunction(); |
| 3133 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3134 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3135 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3136 | * The Child function and Child instance will have the following |
| 3137 | * properties: |
| 3138 | * |
| 3139 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3140 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3141 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3142 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3143 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3144 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3145 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3146 | public: |
| 3147 | /** Creates a function template.*/ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3148 | // TODO(dcarney): deprecate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3149 | static Local<FunctionTemplate> New( |
| 3150 | InvocationCallback callback = 0, |
| 3151 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3152 | Handle<Signature> signature = Handle<Signature>(), |
| 3153 | int length = 0); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3154 | static Local<FunctionTemplate> New( |
| 3155 | FunctionCallback callback, // TODO(dcarney): add back default param. |
| 3156 | Handle<Value> data = Handle<Value>(), |
| 3157 | Handle<Signature> signature = Handle<Signature>(), |
| 3158 | int length = 0); |
| 3159 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3160 | /** Returns the unique function instance in the current execution context.*/ |
| 3161 | Local<Function> GetFunction(); |
| 3162 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3163 | /** |
| 3164 | * Set the call-handler callback for a FunctionTemplate. This |
| 3165 | * callback is called whenever the function created from this |
| 3166 | * FunctionTemplate is called. |
| 3167 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3168 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3169 | void SetCallHandler(InvocationCallback callback, |
| 3170 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3171 | void SetCallHandler(FunctionCallback callback, |
| 3172 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3173 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3174 | /** Set the predefined length property for the FunctionTemplate. */ |
| 3175 | void SetLength(int length); |
| 3176 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3177 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3178 | Local<ObjectTemplate> InstanceTemplate(); |
| 3179 | |
| 3180 | /** Causes the function template to inherit from a parent function template.*/ |
| 3181 | void Inherit(Handle<FunctionTemplate> parent); |
| 3182 | |
| 3183 | /** |
| 3184 | * A PrototypeTemplate is the template used to create the prototype object |
| 3185 | * of the function created by this template. |
| 3186 | */ |
| 3187 | Local<ObjectTemplate> PrototypeTemplate(); |
| 3188 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3189 | /** |
| 3190 | * Set the class name of the FunctionTemplate. This is used for |
| 3191 | * printing objects created with the function created from the |
| 3192 | * FunctionTemplate as its constructor. |
| 3193 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3194 | void SetClassName(Handle<String> name); |
| 3195 | |
| 3196 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3197 | * Determines whether the __proto__ accessor ignores instances of |
| 3198 | * the function template. If instances of the function template are |
| 3199 | * ignored, __proto__ skips all instances and instead returns the |
| 3200 | * next object in the prototype chain. |
| 3201 | * |
| 3202 | * Call with a value of true to make the __proto__ accessor ignore |
| 3203 | * instances of the function template. Call with a value of false |
| 3204 | * to make the __proto__ accessor not ignore instances of the |
| 3205 | * function template. By default, instances of a function template |
| 3206 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | */ |
| 3208 | void SetHiddenPrototype(bool value); |
| 3209 | |
| 3210 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3211 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3212 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3213 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3214 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3215 | |
| 3216 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3217 | * Returns true if the given object is an instance of this function |
| 3218 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3219 | */ |
| 3220 | bool HasInstance(Handle<Value> object); |
| 3221 | |
| 3222 | private: |
| 3223 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3224 | friend class Context; |
| 3225 | friend class ObjectTemplate; |
| 3226 | }; |
| 3227 | |
| 3228 | |
| 3229 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3230 | * An ObjectTemplate is used to create objects at runtime. |
| 3231 | * |
| 3232 | * Properties added to an ObjectTemplate are added to each object |
| 3233 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3234 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3235 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3236 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3237 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3238 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3239 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3240 | /** Creates a new instance of this template.*/ |
| 3241 | Local<Object> NewInstance(); |
| 3242 | |
| 3243 | /** |
| 3244 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3245 | * |
| 3246 | * Whenever the property with the given name is accessed on objects |
| 3247 | * created from this ObjectTemplate the getter and setter callbacks |
| 3248 | * are called instead of getting and setting the property directly |
| 3249 | * on the JavaScript object. |
| 3250 | * |
| 3251 | * \param name The name of the property for which an accessor is added. |
| 3252 | * \param getter The callback to invoke when getting the property. |
| 3253 | * \param setter The callback to invoke when setting the property. |
| 3254 | * \param data A piece of data that will be passed to the getter and setter |
| 3255 | * callbacks whenever they are invoked. |
| 3256 | * \param settings Access control settings for the accessor. This is a bit |
| 3257 | * field consisting of one of more of |
| 3258 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3259 | * The default is to not allow cross-context access. |
| 3260 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3261 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3262 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3263 | * cross-context access. |
| 3264 | * \param attribute The attributes of the property for which an accessor |
| 3265 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3266 | * \param signature The signature describes valid receivers for the accessor |
| 3267 | * and is used to perform implicit instance checks against them. If the |
| 3268 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3269 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3270 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3271 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3272 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3273 | void SetAccessor(Handle<String> name, |
| 3274 | AccessorGetter getter, |
| 3275 | AccessorSetter setter = 0, |
| 3276 | Handle<Value> data = Handle<Value>(), |
| 3277 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3278 | PropertyAttribute attribute = None, |
| 3279 | Handle<AccessorSignature> signature = |
| 3280 | Handle<AccessorSignature>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3281 | void SetAccessor(Handle<String> name, |
| 3282 | AccessorGetterCallback getter, |
| 3283 | AccessorSetterCallback setter = 0, |
| 3284 | Handle<Value> data = Handle<Value>(), |
| 3285 | AccessControl settings = DEFAULT, |
| 3286 | PropertyAttribute attribute = None, |
| 3287 | Handle<AccessorSignature> signature = |
| 3288 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3289 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3290 | // This function is not yet stable and should not be used at this time. |
| 3291 | bool SetAccessor(Handle<String> name, |
| 3292 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3293 | AccessControl settings = DEFAULT, |
| 3294 | PropertyAttribute attribute = None, |
| 3295 | Handle<AccessorSignature> signature = |
| 3296 | Handle<AccessorSignature>()); |
| 3297 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3298 | /** |
| 3299 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3300 | * |
| 3301 | * Whenever a named property is accessed on objects created from |
| 3302 | * this object template, the provided callback is invoked instead of |
| 3303 | * accessing the property directly on the JavaScript object. |
| 3304 | * |
| 3305 | * \param getter The callback to invoke when getting a property. |
| 3306 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3307 | * \param query The callback to invoke to check if a property is present, |
| 3308 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3309 | * \param deleter The callback to invoke when deleting a property. |
| 3310 | * \param enumerator The callback to invoke to enumerate all the named |
| 3311 | * properties of an object. |
| 3312 | * \param data A piece of data that will be passed to the callbacks |
| 3313 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3314 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3315 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3316 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3317 | NamedPropertySetter setter = 0, |
| 3318 | NamedPropertyQuery query = 0, |
| 3319 | NamedPropertyDeleter deleter = 0, |
| 3320 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3321 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3322 | void SetNamedPropertyHandler( |
| 3323 | NamedPropertyGetterCallback getter, |
| 3324 | NamedPropertySetterCallback setter = 0, |
| 3325 | NamedPropertyQueryCallback query = 0, |
| 3326 | NamedPropertyDeleterCallback deleter = 0, |
| 3327 | NamedPropertyEnumeratorCallback enumerator = 0, |
| 3328 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3329 | |
| 3330 | /** |
| 3331 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3332 | * |
| 3333 | * Whenever an indexed property is accessed on objects created from |
| 3334 | * this object template, the provided callback is invoked instead of |
| 3335 | * accessing the property directly on the JavaScript object. |
| 3336 | * |
| 3337 | * \param getter The callback to invoke when getting a property. |
| 3338 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3339 | * \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] | 3340 | * \param deleter The callback to invoke when deleting a property. |
| 3341 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3342 | * properties of an object. |
| 3343 | * \param data A piece of data that will be passed to the callbacks |
| 3344 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3345 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3346 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3347 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3348 | IndexedPropertySetter setter = 0, |
| 3349 | IndexedPropertyQuery query = 0, |
| 3350 | IndexedPropertyDeleter deleter = 0, |
| 3351 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3352 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3353 | void SetIndexedPropertyHandler( |
| 3354 | IndexedPropertyGetterCallback getter, |
| 3355 | IndexedPropertySetterCallback setter = 0, |
| 3356 | IndexedPropertyQueryCallback query = 0, |
| 3357 | IndexedPropertyDeleterCallback deleter = 0, |
| 3358 | IndexedPropertyEnumeratorCallback enumerator = 0, |
| 3359 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3360 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3361 | /** |
| 3362 | * Sets the callback to be used when calling instances created from |
| 3363 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3364 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3365 | * function. |
| 3366 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3367 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3368 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3369 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3370 | void SetCallAsFunctionHandler(FunctionCallback callback, |
| 3371 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3372 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3373 | /** |
| 3374 | * Mark object instances of the template as undetectable. |
| 3375 | * |
| 3376 | * In many ways, undetectable objects behave as though they are not |
| 3377 | * there. They behave like 'undefined' in conditionals and when |
| 3378 | * printed. However, properties can be accessed and called as on |
| 3379 | * normal objects. |
| 3380 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3381 | void MarkAsUndetectable(); |
| 3382 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3383 | /** |
| 3384 | * Sets access check callbacks on the object template. |
| 3385 | * |
| 3386 | * When accessing properties on instances of this object template, |
| 3387 | * the access check callback will be called to determine whether or |
| 3388 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3389 | * The last parameter specifies whether access checks are turned |
| 3390 | * on by default on instances. If access checks are off by default, |
| 3391 | * they can be turned on on individual instances by calling |
| 3392 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3393 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3395 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3396 | Handle<Value> data = Handle<Value>(), |
| 3397 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3398 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3399 | /** |
| 3400 | * Gets the number of internal fields for objects generated from |
| 3401 | * this template. |
| 3402 | */ |
| 3403 | int InternalFieldCount(); |
| 3404 | |
| 3405 | /** |
| 3406 | * Sets the number of internal fields for objects generated from |
| 3407 | * this template. |
| 3408 | */ |
| 3409 | void SetInternalFieldCount(int value); |
| 3410 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3411 | private: |
| 3412 | ObjectTemplate(); |
| 3413 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3414 | friend class FunctionTemplate; |
| 3415 | }; |
| 3416 | |
| 3417 | |
| 3418 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3419 | * A Signature specifies which receivers and arguments are valid |
| 3420 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3421 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3422 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3423 | public: |
| 3424 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3425 | Handle<FunctionTemplate>(), |
| 3426 | int argc = 0, |
| 3427 | Handle<FunctionTemplate> argv[] = 0); |
| 3428 | private: |
| 3429 | Signature(); |
| 3430 | }; |
| 3431 | |
| 3432 | |
| 3433 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3434 | * An AccessorSignature specifies which receivers are valid parameters |
| 3435 | * to an accessor callback. |
| 3436 | */ |
| 3437 | class V8EXPORT AccessorSignature : public Data { |
| 3438 | public: |
| 3439 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3440 | Handle<FunctionTemplate>()); |
| 3441 | private: |
| 3442 | AccessorSignature(); |
| 3443 | }; |
| 3444 | |
| 3445 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3446 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3447 | private: |
| 3448 | DeclaredAccessorDescriptor(); |
| 3449 | }; |
| 3450 | |
| 3451 | |
| 3452 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3453 | public: |
| 3454 | // This function is not yet stable and should not be used at this time. |
| 3455 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3456 | Isolate* isolate, |
| 3457 | int internal_field); |
| 3458 | private: |
| 3459 | ObjectOperationDescriptor(); |
| 3460 | }; |
| 3461 | |
| 3462 | |
| 3463 | enum DeclaredAccessorDescriptorDataType { |
| 3464 | kDescriptorBoolType, |
| 3465 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3466 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3467 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3468 | kDescriptorFloatType, kDescriptorDoubleType |
| 3469 | }; |
| 3470 | |
| 3471 | |
| 3472 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3473 | public: |
| 3474 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3475 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3476 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3477 | int16_t byte_offset); |
| 3478 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3479 | void* compare_value); |
| 3480 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3481 | Isolate* isolate, |
| 3482 | DeclaredAccessorDescriptorDataType data_type, |
| 3483 | uint8_t bool_offset = 0); |
| 3484 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3485 | uint8_t bitmask, |
| 3486 | uint8_t compare_value); |
| 3487 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3488 | Isolate* isolate, |
| 3489 | uint16_t bitmask, |
| 3490 | uint16_t compare_value); |
| 3491 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3492 | Isolate* isolate, |
| 3493 | uint32_t bitmask, |
| 3494 | uint32_t compare_value); |
| 3495 | |
| 3496 | private: |
| 3497 | RawOperationDescriptor(); |
| 3498 | }; |
| 3499 | |
| 3500 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3501 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3502 | * A utility for determining the type of objects based on the template |
| 3503 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3504 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3505 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3506 | public: |
| 3507 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3508 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3509 | int match(Handle<Value> value); |
| 3510 | private: |
| 3511 | TypeSwitch(); |
| 3512 | }; |
| 3513 | |
| 3514 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3515 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3516 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3517 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3518 | : public String::ExternalAsciiStringResource { |
| 3519 | public: |
| 3520 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3521 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3522 | : data_(data), length_(length) {} |
| 3523 | const char* data() const { return data_; } |
| 3524 | size_t length() const { return length_; } |
| 3525 | |
| 3526 | private: |
| 3527 | const char* data_; |
| 3528 | size_t length_; |
| 3529 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3530 | |
| 3531 | /** |
| 3532 | * Ignore |
| 3533 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3534 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3535 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3536 | // Note that the strings passed into this constructor must live as long |
| 3537 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3538 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3539 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3540 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3541 | const char** deps = 0, |
| 3542 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3543 | virtual ~Extension() { } |
| 3544 | virtual v8::Handle<v8::FunctionTemplate> |
| 3545 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3546 | return v8::Handle<v8::FunctionTemplate>(); |
| 3547 | } |
| 3548 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3549 | const char* name() const { return name_; } |
| 3550 | size_t source_length() const { return source_length_; } |
| 3551 | const String::ExternalAsciiStringResource* source() const { |
| 3552 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3553 | int dependency_count() { return dep_count_; } |
| 3554 | const char** dependencies() { return deps_; } |
| 3555 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3556 | bool auto_enable() { return auto_enable_; } |
| 3557 | |
| 3558 | private: |
| 3559 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3560 | size_t source_length_; // expected to initialize before source_ |
| 3561 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3562 | int dep_count_; |
| 3563 | const char** deps_; |
| 3564 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3565 | |
| 3566 | // Disallow copying and assigning. |
| 3567 | Extension(const Extension&); |
| 3568 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3569 | }; |
| 3570 | |
| 3571 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3572 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3573 | |
| 3574 | |
| 3575 | /** |
| 3576 | * Ignore |
| 3577 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3578 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3579 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3580 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3581 | RegisterExtension(extension); |
| 3582 | } |
| 3583 | }; |
| 3584 | |
| 3585 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3586 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3587 | |
| 3588 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3589 | Handle<Primitive> V8EXPORT Undefined(); |
| 3590 | Handle<Primitive> V8EXPORT Null(); |
| 3591 | Handle<Boolean> V8EXPORT True(); |
| 3592 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3593 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3594 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3595 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3596 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3597 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3598 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3599 | |
| 3600 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3601 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3602 | * You must set the heap size before initializing the VM - the size cannot be |
| 3603 | * adjusted after the VM is initialized. |
| 3604 | * |
| 3605 | * If you are using threads then you should hold the V8::Locker lock while |
| 3606 | * setting the stack limit and you must set a non-default stack limit separately |
| 3607 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3608 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3609 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3610 | public: |
| 3611 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3612 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3613 | 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] | 3614 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3615 | 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] | 3616 | int max_executable_size() { return max_executable_size_; } |
| 3617 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3618 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3619 | // 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] | 3620 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3621 | private: |
| 3622 | int max_young_space_size_; |
| 3623 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3624 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3625 | uint32_t* stack_limit_; |
| 3626 | }; |
| 3627 | |
| 3628 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3629 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3630 | |
| 3631 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3632 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3633 | |
| 3634 | |
| 3635 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3636 | |
| 3637 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3638 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3639 | |
| 3640 | |
| 3641 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3642 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3643 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3644 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3645 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3646 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3647 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3648 | |
| 3649 | /** |
| 3650 | * Create new error objects by calling the corresponding error object |
| 3651 | * constructor with the message. |
| 3652 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3653 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3654 | public: |
| 3655 | static Local<Value> RangeError(Handle<String> message); |
| 3656 | static Local<Value> ReferenceError(Handle<String> message); |
| 3657 | static Local<Value> SyntaxError(Handle<String> message); |
| 3658 | static Local<Value> TypeError(Handle<String> message); |
| 3659 | static Local<Value> Error(Handle<String> message); |
| 3660 | }; |
| 3661 | |
| 3662 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3663 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3664 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3665 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3666 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3667 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3668 | int min, |
| 3669 | int max, |
| 3670 | size_t buckets); |
| 3671 | |
| 3672 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3673 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3674 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3675 | enum ObjectSpace { |
| 3676 | kObjectSpaceNewSpace = 1 << 0, |
| 3677 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3678 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3679 | kObjectSpaceCodeSpace = 1 << 3, |
| 3680 | kObjectSpaceMapSpace = 1 << 4, |
| 3681 | kObjectSpaceLoSpace = 1 << 5, |
| 3682 | |
| 3683 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3684 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3685 | kObjectSpaceLoSpace |
| 3686 | }; |
| 3687 | |
| 3688 | enum AllocationAction { |
| 3689 | kAllocationActionAllocate = 1 << 0, |
| 3690 | kAllocationActionFree = 1 << 1, |
| 3691 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3692 | }; |
| 3693 | |
| 3694 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3695 | AllocationAction action, |
| 3696 | int size); |
| 3697 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3698 | // --- Leave Script Callback --- |
| 3699 | typedef void (*CallCompletedCallback)(); |
| 3700 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3701 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3702 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3703 | AccessType type, |
| 3704 | Local<Value> data); |
| 3705 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3706 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3707 | |
| 3708 | /** |
| 3709 | * Callback to check if code generation from strings is allowed. See |
| 3710 | * Context::AllowCodeGenerationFromStrings. |
| 3711 | */ |
| 3712 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3713 | |
| 3714 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3715 | |
| 3716 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3717 | * Applications can register callback functions which will be called |
| 3718 | * before and after a garbage collection. Allocations are not |
| 3719 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3720 | * objects (set or delete properties for example) since it is possible |
| 3721 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3722 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3723 | enum GCType { |
| 3724 | kGCTypeScavenge = 1 << 0, |
| 3725 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3726 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3727 | }; |
| 3728 | |
| 3729 | enum GCCallbackFlags { |
| 3730 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3731 | kGCCallbackFlagCompacted = 1 << 0, |
| 3732 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3733 | }; |
| 3734 | |
| 3735 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3736 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3737 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3738 | typedef void (*GCCallback)(); |
| 3739 | |
| 3740 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3741 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3742 | * Collection of V8 heap information. |
| 3743 | * |
| 3744 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3745 | * get heap statistics from V8. |
| 3746 | */ |
| 3747 | class V8EXPORT HeapStatistics { |
| 3748 | public: |
| 3749 | HeapStatistics(); |
| 3750 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3751 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3752 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3753 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3754 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3755 | |
| 3756 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3757 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3758 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3759 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3760 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3761 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3762 | |
| 3763 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3764 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3765 | }; |
| 3766 | |
| 3767 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3768 | class RetainedObjectInfo; |
| 3769 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3770 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3771 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3772 | * isolates have completely separate states. Objects from one isolate |
| 3773 | * must not be used in other isolates. When V8 is initialized a |
| 3774 | * default isolate is implicitly created and entered. The embedder |
| 3775 | * can create additional isolates and use them in parallel in multiple |
| 3776 | * 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] | 3777 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3778 | */ |
| 3779 | class V8EXPORT Isolate { |
| 3780 | public: |
| 3781 | /** |
| 3782 | * Stack-allocated class which sets the isolate for all operations |
| 3783 | * executed within a local scope. |
| 3784 | */ |
| 3785 | class V8EXPORT Scope { |
| 3786 | public: |
| 3787 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3788 | isolate->Enter(); |
| 3789 | } |
| 3790 | |
| 3791 | ~Scope() { isolate_->Exit(); } |
| 3792 | |
| 3793 | private: |
| 3794 | Isolate* const isolate_; |
| 3795 | |
| 3796 | // Prevent copying of Scope objects. |
| 3797 | Scope(const Scope&); |
| 3798 | Scope& operator=(const Scope&); |
| 3799 | }; |
| 3800 | |
| 3801 | /** |
| 3802 | * Creates a new isolate. Does not change the currently entered |
| 3803 | * isolate. |
| 3804 | * |
| 3805 | * When an isolate is no longer used its resources should be freed |
| 3806 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3807 | */ |
| 3808 | static Isolate* New(); |
| 3809 | |
| 3810 | /** |
| 3811 | * Returns the entered isolate for the current thread or NULL in |
| 3812 | * case there is no current isolate. |
| 3813 | */ |
| 3814 | static Isolate* GetCurrent(); |
| 3815 | |
| 3816 | /** |
| 3817 | * Methods below this point require holding a lock (using Locker) in |
| 3818 | * a multi-threaded environment. |
| 3819 | */ |
| 3820 | |
| 3821 | /** |
| 3822 | * Sets this isolate as the entered one for the current thread. |
| 3823 | * Saves the previously entered one (if any), so that it can be |
| 3824 | * restored when exiting. Re-entering an isolate is allowed. |
| 3825 | */ |
| 3826 | void Enter(); |
| 3827 | |
| 3828 | /** |
| 3829 | * Exits this isolate by restoring the previously entered one in the |
| 3830 | * current thread. The isolate may still stay the same, if it was |
| 3831 | * entered more than once. |
| 3832 | * |
| 3833 | * Requires: this == Isolate::GetCurrent(). |
| 3834 | */ |
| 3835 | void Exit(); |
| 3836 | |
| 3837 | /** |
| 3838 | * Disposes the isolate. The isolate must not be entered by any |
| 3839 | * thread to be disposable. |
| 3840 | */ |
| 3841 | void Dispose(); |
| 3842 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3843 | /** |
| 3844 | * Associate embedder-specific data with the isolate |
| 3845 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3846 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3847 | |
| 3848 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3849 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3850 | * Returns NULL if SetData has never been called. |
| 3851 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3852 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3853 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3854 | /** |
| 3855 | * Get statistics about the heap memory usage. |
| 3856 | */ |
| 3857 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3858 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3859 | /** |
| 3860 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3861 | * indication of the amount of externally allocated memory that is kept alive |
| 3862 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3863 | * garbage collections. Registering externally allocated memory will trigger |
| 3864 | * global garbage collections more often than it would otherwise in an attempt |
| 3865 | * to garbage collect the JavaScript objects that keep the externally |
| 3866 | * allocated memory alive. |
| 3867 | * |
| 3868 | * \param change_in_bytes the change in externally allocated memory that is |
| 3869 | * kept alive by JavaScript objects. |
| 3870 | * \returns the adjusted value. |
| 3871 | */ |
| 3872 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3873 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3874 | /** |
| 3875 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3876 | * is initialized. |
| 3877 | */ |
| 3878 | HeapProfiler* GetHeapProfiler(); |
| 3879 | |
| 3880 | /** |
| 3881 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3882 | * is initialized. |
| 3883 | */ |
| 3884 | CpuProfiler* GetCpuProfiler(); |
| 3885 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3886 | /** Returns the context that is on the top of the stack. */ |
| 3887 | Local<Context> GetCurrentContext(); |
| 3888 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3889 | /** |
| 3890 | * Allows the host application to group objects together. If one |
| 3891 | * object in the group is alive, all objects in the group are alive. |
| 3892 | * After each garbage collection, object groups are removed. It is |
| 3893 | * intended to be used in the before-garbage-collection callback |
| 3894 | * function, for instance to simulate DOM tree connections among JS |
| 3895 | * wrapper objects. Object groups for all dependent handles need to |
| 3896 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3897 | * garbage collection types it is sufficient to provide object groups |
| 3898 | * for partially dependent handles only. |
| 3899 | */ |
| 3900 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3901 | UniqueId id); |
| 3902 | |
| 3903 | /** |
| 3904 | * Allows the host application to declare implicit references from an object |
| 3905 | * group to an object. If the objects of the object group are alive, the child |
| 3906 | * object is alive too. After each garbage collection, all implicit references |
| 3907 | * are removed. It is intended to be used in the before-garbage-collection |
| 3908 | * callback function. |
| 3909 | */ |
| 3910 | void SetReferenceFromGroup(UniqueId id, |
| 3911 | const Persistent<Value>& child); |
| 3912 | |
| 3913 | /** |
| 3914 | * Allows the host application to declare implicit references from an object |
| 3915 | * to another object. If the parent object is alive, the child object is alive |
| 3916 | * too. After each garbage collection, all implicit references are removed. It |
| 3917 | * is intended to be used in the before-garbage-collection callback function. |
| 3918 | */ |
| 3919 | void SetReference(const Persistent<Object>& parent, |
| 3920 | const Persistent<Value>& child); |
| 3921 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3922 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3923 | Isolate(); |
| 3924 | Isolate(const Isolate&); |
| 3925 | ~Isolate(); |
| 3926 | Isolate& operator=(const Isolate&); |
| 3927 | void* operator new(size_t size); |
| 3928 | void operator delete(void*, size_t); |
| 3929 | }; |
| 3930 | |
| 3931 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3932 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3933 | public: |
| 3934 | enum CompressionAlgorithm { |
| 3935 | kUncompressed, |
| 3936 | kBZip2 |
| 3937 | }; |
| 3938 | |
| 3939 | const char* data; |
| 3940 | int compressed_size; |
| 3941 | int raw_size; |
| 3942 | }; |
| 3943 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3944 | |
| 3945 | /** |
| 3946 | * A helper class for driving V8 startup data decompression. It is based on |
| 3947 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3948 | * for an embedder to use this class, instead, API functions can be used |
| 3949 | * directly. |
| 3950 | * |
| 3951 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3952 | */ |
| 3953 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 3954 | public: |
| 3955 | StartupDataDecompressor(); |
| 3956 | virtual ~StartupDataDecompressor(); |
| 3957 | int Decompress(); |
| 3958 | |
| 3959 | protected: |
| 3960 | virtual int DecompressData(char* raw_data, |
| 3961 | int* raw_data_size, |
| 3962 | const char* compressed_data, |
| 3963 | int compressed_data_size) = 0; |
| 3964 | |
| 3965 | private: |
| 3966 | char** raw_data; |
| 3967 | }; |
| 3968 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3969 | |
| 3970 | /** |
| 3971 | * EntropySource is used as a callback function when v8 needs a source |
| 3972 | * of entropy. |
| 3973 | */ |
| 3974 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 3975 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3976 | |
| 3977 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3978 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 3979 | * resolving the location of a return address on the stack. Profilers that |
| 3980 | * change the return address on the stack can use this to resolve the stack |
| 3981 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3982 | * |
| 3983 | * \param return_addr_location points to a location on stack where a machine |
| 3984 | * return address resides. |
| 3985 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 3986 | * copy of the original return address. |
| 3987 | * |
| 3988 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3989 | */ |
| 3990 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 3991 | uintptr_t return_addr_location); |
| 3992 | |
| 3993 | |
| 3994 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3995 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 3996 | * any generated function when function-level profiling is enabled. |
| 3997 | * |
| 3998 | * \param function the address of the function that's being entered. |
| 3999 | * \param return_addr_location points to a location on stack where the machine |
| 4000 | * return address resides. This can be used to identify the caller of |
| 4001 | * \p function, and/or modified to divert execution when \p function exits. |
| 4002 | * |
| 4003 | * \note the entry hook must not cause garbage collection. |
| 4004 | */ |
| 4005 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 4006 | uintptr_t return_addr_location); |
| 4007 | |
| 4008 | |
| 4009 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4010 | * A JIT code event is issued each time code is added, moved or removed. |
| 4011 | * |
| 4012 | * \note removal events are not currently issued. |
| 4013 | */ |
| 4014 | struct JitCodeEvent { |
| 4015 | enum EventType { |
| 4016 | CODE_ADDED, |
| 4017 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4018 | CODE_REMOVED, |
| 4019 | CODE_ADD_LINE_POS_INFO, |
| 4020 | CODE_START_LINE_INFO_RECORDING, |
| 4021 | CODE_END_LINE_INFO_RECORDING |
| 4022 | }; |
| 4023 | // Definition of the code position type. The "POSITION" type means the place |
| 4024 | // in the source code which are of interest when making stack traces to |
| 4025 | // pin-point the source location of a stack frame as close as possible. |
| 4026 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 4027 | // statement, and is used to indicate possible break locations. |
| 4028 | enum PositionType { |
| 4029 | POSITION, |
| 4030 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4031 | }; |
| 4032 | |
| 4033 | // Type of event. |
| 4034 | EventType type; |
| 4035 | // Start of the instructions. |
| 4036 | void* code_start; |
| 4037 | // Size of the instructions. |
| 4038 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4039 | // Script info for CODE_ADDED event. |
| 4040 | Handle<Script> script; |
| 4041 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 4042 | // code line information which is returned from the |
| 4043 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 4044 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 4045 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4046 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4047 | struct name_t { |
| 4048 | // Name of the object associated with the code, note that the string is not |
| 4049 | // zero-terminated. |
| 4050 | const char* str; |
| 4051 | // Number of chars in str. |
| 4052 | size_t len; |
| 4053 | }; |
| 4054 | |
| 4055 | struct line_info_t { |
| 4056 | // PC offset |
| 4057 | size_t offset; |
| 4058 | // Code postion |
| 4059 | size_t pos; |
| 4060 | // The position type. |
| 4061 | PositionType position_type; |
| 4062 | }; |
| 4063 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4064 | union { |
| 4065 | // Only valid for CODE_ADDED. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4066 | struct name_t name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4067 | |
| 4068 | // Only valid for CODE_ADD_LINE_POS_INFO |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4069 | struct line_info_t line_info; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4070 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4071 | // New location of instructions. Only valid for CODE_MOVED. |
| 4072 | void* new_code_start; |
| 4073 | }; |
| 4074 | }; |
| 4075 | |
| 4076 | /** |
| 4077 | * Option flags passed to the SetJitCodeEventHandler function. |
| 4078 | */ |
| 4079 | enum JitCodeEventOptions { |
| 4080 | kJitCodeEventDefault = 0, |
| 4081 | // Generate callbacks for already existent code. |
| 4082 | kJitCodeEventEnumExisting = 1 |
| 4083 | }; |
| 4084 | |
| 4085 | |
| 4086 | /** |
| 4087 | * Callback function passed to SetJitCodeEventHandler. |
| 4088 | * |
| 4089 | * \param event code add, move or removal event. |
| 4090 | */ |
| 4091 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 4092 | |
| 4093 | |
| 4094 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4095 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4096 | */ |
| 4097 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 4098 | public: |
| 4099 | virtual ~ExternalResourceVisitor() {} |
| 4100 | virtual void VisitExternalString(Handle<String> string) {} |
| 4101 | }; |
| 4102 | |
| 4103 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4104 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4105 | * Interface for iterating through all the persistent handles in the heap. |
| 4106 | */ |
| 4107 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 4108 | public: |
| 4109 | virtual ~PersistentHandleVisitor() {} |
| 4110 | virtual void VisitPersistentHandle(Persistent<Value> value, |
| 4111 | uint16_t class_id) {} |
| 4112 | }; |
| 4113 | |
| 4114 | |
| 4115 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4116 | * Asserts that no action is performed that could cause a handle's value |
| 4117 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 4118 | * be performed. |
| 4119 | */ |
| 4120 | class V8EXPORT AssertNoGCScope { |
| 4121 | #ifndef DEBUG |
| 4122 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} |
| 4123 | #else |
| 4124 | AssertNoGCScope(Isolate* isolate); |
| 4125 | ~AssertNoGCScope(); |
| 4126 | private: |
| 4127 | Isolate* isolate_; |
| 4128 | bool last_state_; |
| 4129 | #endif |
| 4130 | }; |
| 4131 | |
| 4132 | |
| 4133 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4134 | * Container class for static utility functions. |
| 4135 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4136 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4137 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4138 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4139 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 4140 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4141 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4142 | * Set the callback to invoke to check if code generation from |
| 4143 | * strings should be allowed. |
| 4144 | */ |
| 4145 | static void SetAllowCodeGenerationFromStringsCallback( |
| 4146 | AllowCodeGenerationFromStringsCallback that); |
| 4147 | |
| 4148 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4149 | * Ignore out-of-memory exceptions. |
| 4150 | * |
| 4151 | * V8 running out of memory is treated as a fatal error by default. |
| 4152 | * This means that the fatal error handler is called and that V8 is |
| 4153 | * terminated. |
| 4154 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4155 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4156 | * out-of-memory situation as a fatal error. This way, the contexts |
| 4157 | * that did not cause the out of memory problem might be able to |
| 4158 | * continue execution. |
| 4159 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4160 | static void IgnoreOutOfMemoryException(); |
| 4161 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4162 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4163 | * 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] | 4164 | * fatal errors such as out-of-memory situations. |
| 4165 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4166 | static bool IsDead(); |
| 4167 | |
| 4168 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4169 | * The following 4 functions are to be used when V8 is built with |
| 4170 | * the 'compress_startup_data' flag enabled. In this case, the |
| 4171 | * embedder must decompress startup data prior to initializing V8. |
| 4172 | * |
| 4173 | * This is how interaction with V8 should look like: |
| 4174 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 4175 | * v8::StartupData* compressed_data = |
| 4176 | * new v8::StartupData[compressed_data_count]; |
| 4177 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 4178 | * ... decompress data (compressed_data can be updated in-place) ... |
| 4179 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 4180 | * ... now V8 can be initialized |
| 4181 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4182 | * |
| 4183 | * A helper class StartupDataDecompressor is provided. It implements |
| 4184 | * the protocol of the interaction described above, and can be used in |
| 4185 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4186 | */ |
| 4187 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 4188 | static int GetCompressedStartupDataCount(); |
| 4189 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 4190 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 4191 | |
| 4192 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4193 | * Adds a message listener. |
| 4194 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4195 | * 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] | 4196 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4197 | * |
| 4198 | * If data is specified, it will be passed to the callback when it is called. |
| 4199 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4200 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4201 | static bool AddMessageListener(MessageCallback that, |
| 4202 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4203 | |
| 4204 | /** |
| 4205 | * Remove all message listeners from the specified callback function. |
| 4206 | */ |
| 4207 | static void RemoveMessageListeners(MessageCallback that); |
| 4208 | |
| 4209 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4210 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 4211 | * and report it to the message listeners. The option is off by default. |
| 4212 | */ |
| 4213 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 4214 | bool capture, |
| 4215 | int frame_limit = 10, |
| 4216 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 4217 | |
| 4218 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4219 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4220 | */ |
| 4221 | static void SetFlagsFromString(const char* str, int length); |
| 4222 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4223 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4224 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4225 | */ |
| 4226 | static void SetFlagsFromCommandLine(int* argc, |
| 4227 | char** argv, |
| 4228 | bool remove_flags); |
| 4229 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4230 | /** Get the version string. */ |
| 4231 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4232 | |
| 4233 | /** |
| 4234 | * Enables the host application to provide a mechanism for recording |
| 4235 | * statistics counters. |
| 4236 | */ |
| 4237 | static void SetCounterFunction(CounterLookupCallback); |
| 4238 | |
| 4239 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4240 | * Enables the host application to provide a mechanism for recording |
| 4241 | * histograms. The CreateHistogram function returns a |
| 4242 | * histogram which will later be passed to the AddHistogramSample |
| 4243 | * function. |
| 4244 | */ |
| 4245 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4246 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4247 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4248 | /** Callback function for reporting failed access checks.*/ |
| 4249 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4250 | |
| 4251 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4252 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4253 | * garbage collection. Allocations are not allowed in the |
| 4254 | * callback function, you therefore cannot manipulate objects (set |
| 4255 | * or delete properties for example) since it is possible such |
| 4256 | * operations will result in the allocation of objects. It is possible |
| 4257 | * to specify the GCType filter for your callback. But it is not possible to |
| 4258 | * register the same callback function two times with different |
| 4259 | * GCType filters. |
| 4260 | */ |
| 4261 | static void AddGCPrologueCallback( |
| 4262 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4263 | |
| 4264 | /** |
| 4265 | * This function removes callback which was installed by |
| 4266 | * AddGCPrologueCallback function. |
| 4267 | */ |
| 4268 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4269 | |
| 4270 | /** |
| 4271 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4272 | * Enables the host application to receive a notification before a |
| 4273 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4274 | * callback function, you therefore cannot manipulate objects (set |
| 4275 | * or delete properties for example) since it is possible such |
| 4276 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4277 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4278 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4279 | |
| 4280 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4281 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4282 | * garbage collection. Allocations are not allowed in the |
| 4283 | * callback function, you therefore cannot manipulate objects (set |
| 4284 | * or delete properties for example) since it is possible such |
| 4285 | * operations will result in the allocation of objects. It is possible |
| 4286 | * to specify the GCType filter for your callback. But it is not possible to |
| 4287 | * register the same callback function two times with different |
| 4288 | * GCType filters. |
| 4289 | */ |
| 4290 | static void AddGCEpilogueCallback( |
| 4291 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4292 | |
| 4293 | /** |
| 4294 | * This function removes callback which was installed by |
| 4295 | * AddGCEpilogueCallback function. |
| 4296 | */ |
| 4297 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4298 | |
| 4299 | /** |
| 4300 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4301 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4302 | * major garbage collection. Allocations are not allowed in the |
| 4303 | * callback function, you therefore cannot manipulate objects (set |
| 4304 | * or delete properties for example) since it is possible such |
| 4305 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4306 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4307 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4308 | |
| 4309 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4310 | * Enables the host application to provide a mechanism to be notified |
| 4311 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4312 | */ |
| 4313 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4314 | ObjectSpace space, |
| 4315 | AllocationAction action); |
| 4316 | |
| 4317 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4318 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4319 | */ |
| 4320 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4321 | |
| 4322 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4323 | * Adds a callback to notify the host application when a script finished |
| 4324 | * running. If a script re-enters the runtime during executing, the |
| 4325 | * CallCompletedCallback is only invoked when the outer-most script |
| 4326 | * execution ends. Executing scripts inside the callback do not trigger |
| 4327 | * further callbacks. |
| 4328 | */ |
| 4329 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4330 | |
| 4331 | /** |
| 4332 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4333 | */ |
| 4334 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4335 | |
| 4336 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4337 | * Allows the host application to group objects together. If one |
| 4338 | * object in the group is alive, all objects in the group are alive. |
| 4339 | * After each garbage collection, object groups are removed. It is |
| 4340 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4341 | * function, for instance to simulate DOM tree connections among JS |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4342 | * wrapper objects. Object groups for all dependent handles need to |
| 4343 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 4344 | * garbage collection types it is sufficient to provide object groups |
| 4345 | * for partially dependent handles only. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4346 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4347 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4348 | // TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId and |
| 4349 | // HeapProfiler::SetRetainedObjectInfo instead. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4350 | static void AddObjectGroup(Persistent<Value>* objects, |
| 4351 | size_t length, |
| 4352 | RetainedObjectInfo* info = NULL); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4353 | static void AddObjectGroup(Isolate* isolate, |
| 4354 | Persistent<Value>* objects, |
| 4355 | size_t length, |
| 4356 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4357 | |
| 4358 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4359 | * Allows the host application to declare implicit references between |
| 4360 | * the objects: if |parent| is alive, all |children| are alive too. |
| 4361 | * After each garbage collection, all implicit references |
| 4362 | * are removed. It is intended to be used in the before-garbage-collection |
| 4363 | * callback function. |
| 4364 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4365 | // TODO(marja): Deprecate AddImplicitReferences. Use |
| 4366 | // Isolate::SetReferenceFromGroup instead. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4367 | static void AddImplicitReferences(Persistent<Object> parent, |
| 4368 | Persistent<Value>* children, |
| 4369 | size_t length); |
| 4370 | |
| 4371 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4372 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4373 | * initialize from scratch. This function is called implicitly if |
| 4374 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4375 | */ |
| 4376 | static bool Initialize(); |
| 4377 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4378 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4379 | * Allows the host application to provide a callback which can be used |
| 4380 | * as a source of entropy for random number generators. |
| 4381 | */ |
| 4382 | static void SetEntropySource(EntropySource source); |
| 4383 | |
| 4384 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4385 | * Allows the host application to provide a callback that allows v8 to |
| 4386 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4387 | */ |
| 4388 | static void SetReturnAddressLocationResolver( |
| 4389 | ReturnAddressLocationResolver return_address_resolver); |
| 4390 | |
| 4391 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4392 | * Allows the host application to provide the address of a function that's |
| 4393 | * invoked on entry to every V8-generated function. |
| 4394 | * Note that \p entry_hook is invoked at the very start of each |
| 4395 | * generated function. |
| 4396 | * |
| 4397 | * \param entry_hook a function that will be invoked on entry to every |
| 4398 | * V8-generated function. |
| 4399 | * \returns true on success on supported platforms, false on failure. |
| 4400 | * \note Setting a new entry hook function when one is already active will |
| 4401 | * fail. |
| 4402 | */ |
| 4403 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4404 | |
| 4405 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4406 | * Allows the host application to provide the address of a function that is |
| 4407 | * notified each time code is added, moved or removed. |
| 4408 | * |
| 4409 | * \param options options for the JIT code event handler. |
| 4410 | * \param event_handler the JIT code event handler, which will be invoked |
| 4411 | * each time code is added, moved or removed. |
| 4412 | * \note \p event_handler won't get notified of existent code. |
| 4413 | * \note since code removal notifications are not currently issued, the |
| 4414 | * \p event_handler may get notifications of code that overlaps earlier |
| 4415 | * code notifications. This happens when code areas are reused, and the |
| 4416 | * earlier overlapping code areas should therefore be discarded. |
| 4417 | * \note the events passed to \p event_handler and the strings they point to |
| 4418 | * are not guaranteed to live past each call. The \p event_handler must |
| 4419 | * copy strings and other parameters it needs to keep around. |
| 4420 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4421 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4422 | * new members. The \p event_handler function must ignore event codes |
| 4423 | * it does not recognize to maintain future compatibility. |
| 4424 | */ |
| 4425 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4426 | JitCodeEventHandler event_handler); |
| 4427 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4428 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4429 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4430 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4431 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4432 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4433 | /** |
| 4434 | * Suspends recording of tick samples in the profiler. |
| 4435 | * When the V8 profiling mode is enabled (usually via command line |
| 4436 | * switches) this function suspends recording of tick samples. |
| 4437 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4438 | * |
| 4439 | * See also the --prof and --prof_auto command line switches to |
| 4440 | * enable V8 profiling. |
| 4441 | */ |
| 4442 | static void PauseProfiler(); |
| 4443 | |
| 4444 | /** |
| 4445 | * Resumes recording of tick samples in the profiler. |
| 4446 | * See also PauseProfiler(). |
| 4447 | */ |
| 4448 | static void ResumeProfiler(); |
| 4449 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4450 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4451 | * Return whether profiler is currently paused. |
| 4452 | */ |
| 4453 | static bool IsProfilerPaused(); |
| 4454 | |
| 4455 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4456 | * Retrieve the V8 thread id of the calling thread. |
| 4457 | * |
| 4458 | * The thread id for a thread should only be retrieved after the V8 |
| 4459 | * lock has been acquired with a Locker object with that thread. |
| 4460 | */ |
| 4461 | static int GetCurrentThreadId(); |
| 4462 | |
| 4463 | /** |
| 4464 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4465 | * be used to terminate long-running scripts. |
| 4466 | * |
| 4467 | * TerminateExecution should only be called when then V8 lock has |
| 4468 | * been acquired with a Locker object. Therefore, in order to be |
| 4469 | * able to terminate long-running threads, preemption must be |
| 4470 | * enabled to allow the user of TerminateExecution to acquire the |
| 4471 | * lock. |
| 4472 | * |
| 4473 | * The termination is achieved by throwing an exception that is |
| 4474 | * uncatchable by JavaScript exception handlers. Termination |
| 4475 | * 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] | 4476 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4477 | * exception handler that catches an exception should check if that |
| 4478 | * exception is a termination exception and immediately return if |
| 4479 | * that is the case. Returning immediately in that case will |
| 4480 | * continue the propagation of the termination exception if needed. |
| 4481 | * |
| 4482 | * The thread id passed to TerminateExecution must have been |
| 4483 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4484 | * |
| 4485 | * \param thread_id The thread id of the thread to terminate. |
| 4486 | */ |
| 4487 | static void TerminateExecution(int thread_id); |
| 4488 | |
| 4489 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4490 | * Forcefully terminate the current thread of JavaScript execution |
| 4491 | * in the given isolate. If no isolate is provided, the default |
| 4492 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4493 | * |
| 4494 | * This method can be used by any thread even if that thread has not |
| 4495 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4496 | * |
| 4497 | * \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] | 4498 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4499 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4500 | |
| 4501 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4502 | * Is V8 terminating JavaScript execution. |
| 4503 | * |
| 4504 | * Returns true if JavaScript execution is currently terminating |
| 4505 | * because of a call to TerminateExecution. In that case there are |
| 4506 | * still JavaScript frames on the stack and the termination |
| 4507 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4508 | * |
| 4509 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4510 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4511 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4512 | |
| 4513 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4514 | * Resume execution capability in the given isolate, whose execution |
| 4515 | * was previously forcefully terminated using TerminateExecution(). |
| 4516 | * |
| 4517 | * When execution is forcefully terminated using TerminateExecution(), |
| 4518 | * the isolate can not resume execution until all JavaScript frames |
| 4519 | * have propagated the uncatchable exception which is generated. This |
| 4520 | * method allows the program embedding the engine to handle the |
| 4521 | * termination event and resume execution capability, even if |
| 4522 | * JavaScript frames remain on the stack. |
| 4523 | * |
| 4524 | * This method can be used by any thread even if that thread has not |
| 4525 | * acquired the V8 lock with a Locker object. |
| 4526 | * |
| 4527 | * \param isolate The isolate in which to resume execution capability. |
| 4528 | */ |
| 4529 | static void CancelTerminateExecution(Isolate* isolate); |
| 4530 | |
| 4531 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4532 | * Releases any resources used by v8 and stops any utility threads |
| 4533 | * that may be running. Note that disposing v8 is permanent, it |
| 4534 | * cannot be reinitialized. |
| 4535 | * |
| 4536 | * It should generally not be necessary to dispose v8 before exiting |
| 4537 | * a process, this should happen automatically. It is only necessary |
| 4538 | * to use if the process needs the resources taken up by v8. |
| 4539 | */ |
| 4540 | static bool Dispose(); |
| 4541 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4542 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4543 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4544 | |
| 4545 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4546 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4547 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4548 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4549 | */ |
| 4550 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4551 | |
| 4552 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4553 | * Iterates through all the persistent handles in the current isolate's heap |
| 4554 | * that have class_ids. |
| 4555 | */ |
| 4556 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4557 | |
| 4558 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4559 | * Iterates through all the persistent handles in the current isolate's heap |
| 4560 | * that have class_ids and are candidates to be marked as partially dependent |
| 4561 | * handles. This will visit handles to young objects created since the last |
| 4562 | * garbage collection but is free to visit an arbitrary superset of these |
| 4563 | * objects. |
| 4564 | */ |
| 4565 | static void VisitHandlesForPartialDependence( |
| 4566 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4567 | |
| 4568 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4569 | * Optional notification that the embedder is idle. |
| 4570 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4571 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4572 | * Returns true if the embedder should stop calling IdleNotification |
| 4573 | * until real work has been done. This indicates that V8 has done |
| 4574 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4575 | * |
| 4576 | * The hint argument specifies the amount of work to be done in the function |
| 4577 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4578 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4579 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4580 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4581 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4582 | /** |
| 4583 | * Optional notification that the system is running low on memory. |
| 4584 | * V8 uses these notifications to attempt to free memory. |
| 4585 | */ |
| 4586 | static void LowMemoryNotification(); |
| 4587 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4588 | /** |
| 4589 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4590 | * these notifications to guide the GC heuristic. Returns the number |
| 4591 | * of context disposals - including this one - since the last time |
| 4592 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4593 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4594 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4596 | private: |
| 4597 | V8(); |
| 4598 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4599 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4600 | internal::Object** handle); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4601 | static void DisposeGlobal(internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4602 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4603 | static void MakeWeak(internal::Isolate* isolate, |
| 4604 | internal::Object** global_handle, |
| 4605 | void* data, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4606 | RevivableCallback weak_reference_callback, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4607 | NearDeathCallback near_death_callback); |
| 4608 | static void ClearWeak(internal::Isolate* isolate, |
| 4609 | internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4610 | |
| 4611 | template <class T> friend class Handle; |
| 4612 | template <class T> friend class Local; |
| 4613 | template <class T> friend class Persistent; |
| 4614 | friend class Context; |
| 4615 | }; |
| 4616 | |
| 4617 | |
| 4618 | /** |
| 4619 | * An external exception handler. |
| 4620 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4621 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4622 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4623 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4624 | * Creates a new try/catch block and registers it with v8. Note that |
| 4625 | * all TryCatch blocks should be stack allocated because the memory |
| 4626 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4627 | */ |
| 4628 | TryCatch(); |
| 4629 | |
| 4630 | /** |
| 4631 | * Unregisters and deletes this try/catch block. |
| 4632 | */ |
| 4633 | ~TryCatch(); |
| 4634 | |
| 4635 | /** |
| 4636 | * Returns true if an exception has been caught by this try/catch block. |
| 4637 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4638 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4639 | |
| 4640 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4641 | * 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] | 4642 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4643 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4644 | * cleanup needed and then return. If CanContinue returns false and |
| 4645 | * HasTerminated returns true, it is possible to call |
| 4646 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4647 | */ |
| 4648 | bool CanContinue() const; |
| 4649 | |
| 4650 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4651 | * Returns true if an exception has been caught due to script execution |
| 4652 | * being terminated. |
| 4653 | * |
| 4654 | * There is no JavaScript representation of an execution termination |
| 4655 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4656 | * methods are called to terminate a long-running script. |
| 4657 | * |
| 4658 | * If such an exception has been thrown, HasTerminated will return true, |
| 4659 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4660 | * to continue calling into the engine. |
| 4661 | */ |
| 4662 | bool HasTerminated() const; |
| 4663 | |
| 4664 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4665 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4666 | * it being caught again by this same TryCatch. As with ThrowException |
| 4667 | * it is illegal to execute any JavaScript operations after calling |
| 4668 | * ReThrow; the caller must return immediately to where the exception |
| 4669 | * is caught. |
| 4670 | */ |
| 4671 | Handle<Value> ReThrow(); |
| 4672 | |
| 4673 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4674 | * Returns the exception caught by this try/catch block. If no exception has |
| 4675 | * been caught an empty handle is returned. |
| 4676 | * |
| 4677 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4678 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4679 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4680 | |
| 4681 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4682 | * Returns the .stack property of the thrown object. If no .stack |
| 4683 | * property is present an empty handle is returned. |
| 4684 | */ |
| 4685 | Local<Value> StackTrace() const; |
| 4686 | |
| 4687 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4688 | * Returns the message associated with this exception. If there is |
| 4689 | * no message associated an empty handle is returned. |
| 4690 | * |
| 4691 | * The returned handle is valid until this TryCatch block has been |
| 4692 | * destroyed. |
| 4693 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4694 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4695 | |
| 4696 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4697 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4698 | * After this method has been called, HasCaught() will return false. |
| 4699 | * |
| 4700 | * It is not necessary to clear a try/catch block before using it again; if |
| 4701 | * another exception is thrown the previously caught exception will just be |
| 4702 | * overwritten. However, it is often a good idea since it makes it easier |
| 4703 | * to determine which operation threw a given exception. |
| 4704 | */ |
| 4705 | void Reset(); |
| 4706 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4707 | /** |
| 4708 | * Set verbosity of the external exception handler. |
| 4709 | * |
| 4710 | * By default, exceptions that are caught by an external exception |
| 4711 | * handler are not reported. Call SetVerbose with true on an |
| 4712 | * external exception handler to have exceptions caught by the |
| 4713 | * handler reported as if they were not caught. |
| 4714 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4715 | void SetVerbose(bool value); |
| 4716 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4717 | /** |
| 4718 | * Set whether or not this TryCatch should capture a Message object |
| 4719 | * which holds source information about where the exception |
| 4720 | * occurred. True by default. |
| 4721 | */ |
| 4722 | void SetCaptureMessage(bool value); |
| 4723 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4724 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4725 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4726 | TryCatch(const TryCatch&); |
| 4727 | void operator=(const TryCatch&); |
| 4728 | void* operator new(size_t size); |
| 4729 | void operator delete(void*, size_t); |
| 4730 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4731 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4732 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4733 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4734 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4735 | bool is_verbose_ : 1; |
| 4736 | bool can_continue_ : 1; |
| 4737 | bool capture_message_ : 1; |
| 4738 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4739 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4740 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4741 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4742 | }; |
| 4743 | |
| 4744 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4745 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4746 | |
| 4747 | |
| 4748 | /** |
| 4749 | * Ignore |
| 4750 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4751 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4752 | public: |
| 4753 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4754 | : name_count_(name_count), names_(names) { } |
| 4755 | private: |
| 4756 | friend class ImplementationUtilities; |
| 4757 | int name_count_; |
| 4758 | const char** names_; |
| 4759 | }; |
| 4760 | |
| 4761 | |
| 4762 | /** |
| 4763 | * A sandboxed execution context with its own set of built-in objects |
| 4764 | * and functions. |
| 4765 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4766 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4767 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4768 | /** |
| 4769 | * Returns the global proxy object or global object itself for |
| 4770 | * detached contexts. |
| 4771 | * |
| 4772 | * Global proxy object is a thin wrapper whose prototype points to |
| 4773 | * actual context's global object with the properties like Object, etc. |
| 4774 | * This is done that way for security reasons (for more details see |
| 4775 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4776 | * |
| 4777 | * Please note that changes to global proxy object prototype most probably |
| 4778 | * would break VM---v8 expects only global object as a prototype of |
| 4779 | * global proxy object. |
| 4780 | * |
| 4781 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4782 | * object until global is reattached with ReattachGlobal(). |
| 4783 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4784 | Local<Object> Global(); |
| 4785 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4786 | /** |
| 4787 | * Detaches the global object from its context before |
| 4788 | * the global object can be reused to create a new context. |
| 4789 | */ |
| 4790 | void DetachGlobal(); |
| 4791 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4792 | /** |
| 4793 | * Reattaches a global object to a context. This can be used to |
| 4794 | * restore the connection between a global object and a context |
| 4795 | * after DetachGlobal has been called. |
| 4796 | * |
| 4797 | * \param global_object The global object to reattach to the |
| 4798 | * context. For this to work, the global object must be the global |
| 4799 | * object that was associated with this context before a call to |
| 4800 | * DetachGlobal. |
| 4801 | */ |
| 4802 | void ReattachGlobal(Handle<Object> global_object); |
| 4803 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4804 | /** |
| 4805 | * Creates a new context and returns a handle to the newly allocated |
| 4806 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4807 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4808 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4809 | * |
| 4810 | * \param extensions An optional extension configuration containing |
| 4811 | * the extensions to be installed in the newly created context. |
| 4812 | * |
| 4813 | * \param global_template An optional object template from which the |
| 4814 | * global object for the newly created context will be created. |
| 4815 | * |
| 4816 | * \param global_object An optional global object to be reused for |
| 4817 | * the newly created context. This global object must have been |
| 4818 | * created by a previous call to Context::New with the same global |
| 4819 | * template. The state of the global object will be completely reset |
| 4820 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4821 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4822 | static Local<Context> New( |
| 4823 | Isolate* isolate, |
| 4824 | ExtensionConfiguration* extensions = NULL, |
| 4825 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4826 | Handle<Value> global_object = Handle<Value>()); |
| 4827 | |
| 4828 | /** Deprecated. Use Isolate version instead. */ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4829 | V8_DEPRECATED(static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4830 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4831 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4832 | Handle<Value> global_object = Handle<Value>())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4833 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4834 | /** Returns the last entered context. */ |
| 4835 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4836 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4837 | // TODO(svenpanne) Actually deprecate this. |
| 4838 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4839 | static Local<Context> GetCurrent(); |
| 4840 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4841 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4842 | * Returns the context of the calling JavaScript code. That is the |
| 4843 | * context of the top-most JavaScript frame. If there are no |
| 4844 | * JavaScript frames an empty handle is returned. |
| 4845 | */ |
| 4846 | static Local<Context> GetCalling(); |
| 4847 | |
| 4848 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4849 | * Sets the security token for the context. To access an object in |
| 4850 | * another context, the security tokens must match. |
| 4851 | */ |
| 4852 | void SetSecurityToken(Handle<Value> token); |
| 4853 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4854 | /** Restores the security token to the default value. */ |
| 4855 | void UseDefaultSecurityToken(); |
| 4856 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4857 | /** Returns the security token of this context.*/ |
| 4858 | Handle<Value> GetSecurityToken(); |
| 4859 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4860 | /** |
| 4861 | * Enter this context. After entering a context, all code compiled |
| 4862 | * and run is compiled and run in this context. If another context |
| 4863 | * is already entered, this old context is saved so it can be |
| 4864 | * restored when the new context is exited. |
| 4865 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4866 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4867 | |
| 4868 | /** |
| 4869 | * Exit this context. Exiting the current context restores the |
| 4870 | * context that was in place when entering the current context. |
| 4871 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4872 | void Exit(); |
| 4873 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4874 | /** 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] | 4875 | bool HasOutOfMemoryException(); |
| 4876 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4877 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4878 | static bool InContext(); |
| 4879 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4880 | /** Returns an isolate associated with a current context. */ |
| 4881 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4882 | |
| 4883 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4884 | * Gets the embedder data with the given index, which must have been set by a |
| 4885 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4886 | * currently has a special meaning for Chrome's debugger. |
| 4887 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4888 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4889 | |
| 4890 | /** |
| 4891 | * Sets the embedder data with the given index, growing the data as |
| 4892 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4893 | * debugger. |
| 4894 | */ |
| 4895 | void SetEmbedderData(int index, Handle<Value> value); |
| 4896 | |
| 4897 | /** |
| 4898 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4899 | * index, which must have bees set by a previous call to |
| 4900 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4901 | * currently has a special meaning for Chrome's debugger. |
| 4902 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4903 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4904 | |
| 4905 | /** |
| 4906 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4907 | * index, growing the data as needed. Note that index 0 currently has a |
| 4908 | * special meaning for Chrome's debugger. |
| 4909 | */ |
| 4910 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4911 | |
| 4912 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4913 | * Control whether code generation from strings is allowed. Calling |
| 4914 | * this method with false will disable 'eval' and the 'Function' |
| 4915 | * constructor for code running in this context. If 'eval' or the |
| 4916 | * 'Function' constructor are used an exception will be thrown. |
| 4917 | * |
| 4918 | * If code generation from strings is not allowed the |
| 4919 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4920 | * set before blocking the call to 'eval' or the 'Function' |
| 4921 | * constructor. If that callback returns true, the call will be |
| 4922 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4923 | * set an exception will be thrown. |
| 4924 | */ |
| 4925 | void AllowCodeGenerationFromStrings(bool allow); |
| 4926 | |
| 4927 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4928 | * Returns true if code generation from strings is allowed for the context. |
| 4929 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4930 | */ |
| 4931 | bool IsCodeGenerationFromStringsAllowed(); |
| 4932 | |
| 4933 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4934 | * Sets the error description for the exception that is thrown when |
| 4935 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4936 | * constructor are called. |
| 4937 | */ |
| 4938 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4939 | |
| 4940 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4941 | * Stack-allocated class which sets the execution context for all |
| 4942 | * operations executed within a local scope. |
| 4943 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4944 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4945 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4946 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4947 | context_->Enter(); |
| 4948 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 4949 | // TODO(dcarney): deprecate |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4950 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4951 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4952 | : context_(Handle<Context>::New(isolate, context)) { |
| 4953 | #else |
| 4954 | : context_(Local<Context>::New(isolate, context)) { |
| 4955 | #endif |
| 4956 | context_->Enter(); |
| 4957 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4958 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4959 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4960 | private: |
| 4961 | Handle<Context> context_; |
| 4962 | }; |
| 4963 | |
| 4964 | private: |
| 4965 | friend class Value; |
| 4966 | friend class Script; |
| 4967 | friend class Object; |
| 4968 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4969 | |
| 4970 | Local<Value> SlowGetEmbedderData(int index); |
| 4971 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4972 | }; |
| 4973 | |
| 4974 | |
| 4975 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4976 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4977 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4978 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4979 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4980 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4981 | * constraint is not violated. In addition to any other synchronization |
| 4982 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4983 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4984 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4985 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4986 | * construction and destruction, the current thread is allowed to use the locked |
| 4987 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4988 | * 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] | 4989 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4990 | * Sample usage: |
| 4991 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4992 | * ... |
| 4993 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4994 | * v8::Locker locker(isolate); |
| 4995 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4996 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4997 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4998 | * ... |
| 4999 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5000 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5001 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5002 | * If you wish to stop using V8 in a thread A you can do this either by |
| 5003 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 5004 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5005 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5006 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5007 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5008 | * isolate->Exit(); |
| 5009 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5010 | * ... |
| 5011 | * // Code not using V8 goes here while V8 can run in another thread. |
| 5012 | * ... |
| 5013 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5014 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5015 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5017 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 5018 | * 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] | 5019 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5020 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 5021 | * given thread. This can be useful if you have code that can be called either |
| 5022 | * from code that holds the lock or from code that does not. The Unlocker is |
| 5023 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 5024 | * 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] | 5025 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5026 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 5027 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5028 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5029 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5030 | * // V8 not locked. |
| 5031 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5032 | * v8::Locker locker(isolate); |
| 5033 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5034 | * // V8 locked. |
| 5035 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5036 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5037 | * // V8 still locked (2 levels). |
| 5038 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5039 | * isolate->Exit(); |
| 5040 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5041 | * // V8 not locked. |
| 5042 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5043 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5044 | * // V8 locked again (2 levels). |
| 5045 | * } |
| 5046 | * // V8 still locked (1 level). |
| 5047 | * } |
| 5048 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5049 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5050 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5051 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5052 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5053 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5054 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5055 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5056 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 5057 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5058 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5059 | V8_DEPRECATED(Unlocker()); |
| 5060 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5062 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5063 | void Initialize(Isolate* isolate); |
| 5064 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5065 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5066 | }; |
| 5067 | |
| 5068 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5069 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5070 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5071 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5072 | * Initialize Locker for a given Isolate. |
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 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 5075 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5076 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5077 | V8_DEPRECATED(Locker()); |
| 5078 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5079 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5080 | |
| 5081 | /** |
| 5082 | * Start preemption. |
| 5083 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5084 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5085 | * that will switch between multiple threads that are in contention |
| 5086 | * for the V8 lock. |
| 5087 | */ |
| 5088 | static void StartPreemption(int every_n_ms); |
| 5089 | |
| 5090 | /** |
| 5091 | * Stop preemption. |
| 5092 | */ |
| 5093 | static void StopPreemption(); |
| 5094 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5095 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5096 | * Returns whether or not the locker for a given isolate, is locked by the |
| 5097 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5098 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5099 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5100 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5101 | /** |
| 5102 | * Returns whether v8::Locker is being used by this V8 instance. |
| 5103 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5104 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5105 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5106 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5107 | void Initialize(Isolate* isolate); |
| 5108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5109 | bool has_lock_; |
| 5110 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5111 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5112 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5113 | static bool active_; |
| 5114 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5115 | // Disallow copying and assigning. |
| 5116 | Locker(const Locker&); |
| 5117 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5118 | }; |
| 5119 | |
| 5120 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5121 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5122 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 5123 | */ |
| 5124 | struct HeapStatsUpdate; |
| 5125 | |
| 5126 | |
| 5127 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5128 | * An interface for exporting data from V8, using "push" model. |
| 5129 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5130 | class V8EXPORT OutputStream { // NOLINT |
| 5131 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5132 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5133 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5134 | }; |
| 5135 | enum WriteResult { |
| 5136 | kContinue = 0, |
| 5137 | kAbort = 1 |
| 5138 | }; |
| 5139 | virtual ~OutputStream() {} |
| 5140 | /** Notify about the end of stream. */ |
| 5141 | virtual void EndOfStream() = 0; |
| 5142 | /** Get preferred output chunk size. Called only once. */ |
| 5143 | virtual int GetChunkSize() { return 1024; } |
| 5144 | /** Get preferred output encoding. Called only once. */ |
| 5145 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 5146 | /** |
| 5147 | * Writes the next chunk of snapshot data into the stream. Writing |
| 5148 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5149 | * will not be called in case writing was aborted. |
| 5150 | */ |
| 5151 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5152 | /** |
| 5153 | * Writes the next chunk of heap stats data into the stream. Writing |
| 5154 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5155 | * will not be called in case writing was aborted. |
| 5156 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5157 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 5158 | return kAbort; |
| 5159 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5160 | }; |
| 5161 | |
| 5162 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5163 | /** |
| 5164 | * An interface for reporting progress and controlling long-running |
| 5165 | * activities. |
| 5166 | */ |
| 5167 | class V8EXPORT ActivityControl { // NOLINT |
| 5168 | public: |
| 5169 | enum ControlOption { |
| 5170 | kContinue = 0, |
| 5171 | kAbort = 1 |
| 5172 | }; |
| 5173 | virtual ~ActivityControl() {} |
| 5174 | /** |
| 5175 | * Notify about current progress. The activity can be stopped by |
| 5176 | * returning kAbort as the callback result. |
| 5177 | */ |
| 5178 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 5179 | }; |
| 5180 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5181 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5182 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5183 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5184 | |
| 5185 | namespace internal { |
| 5186 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5187 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 5188 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5189 | |
| 5190 | // Tag information for HeapObject. |
| 5191 | const int kHeapObjectTag = 1; |
| 5192 | const int kHeapObjectTagSize = 2; |
| 5193 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 5194 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5195 | // Tag information for Smi. |
| 5196 | const int kSmiTag = 0; |
| 5197 | const int kSmiTagSize = 1; |
| 5198 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 5199 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5200 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5201 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5202 | template<int kSmiShiftSize> |
| 5203 | V8_INLINE(internal::Object* IntToSmi(int value)) { |
| 5204 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5205 | intptr_t tagged_value = |
| 5206 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
| 5207 | return reinterpret_cast<internal::Object*>(tagged_value); |
| 5208 | } |
| 5209 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5210 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5211 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5212 | static const int kSmiShiftSize = 0; |
| 5213 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5214 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5215 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5216 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 5217 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 5218 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5219 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5220 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5221 | } |
| 5222 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5223 | // To be representable as an tagged small integer, the two |
| 5224 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 5225 | // sign-extension. To check this we add 01 to the two |
| 5226 | // most-significant bits, and check if the most-significant bit is 0 |
| 5227 | // |
| 5228 | // CAUTION: The original code below: |
| 5229 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 5230 | // may lead to incorrect results according to the C language spec, and |
| 5231 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 5232 | // compiler may produce undefined results in case of signed integer |
| 5233 | // overflow. The computation must be done w/ unsigned ints. |
| 5234 | return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; |
| 5235 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5236 | }; |
| 5237 | |
| 5238 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5239 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5240 | static const int kSmiShiftSize = 31; |
| 5241 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5242 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5243 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5244 | // Shift down and throw away top 32 bits. |
| 5245 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5246 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5247 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5248 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5249 | } |
| 5250 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5251 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 5252 | return (value == static_cast<int32_t>(value)); |
| 5253 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5254 | }; |
| 5255 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5256 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5257 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5258 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5259 | |
| 5260 | /** |
| 5261 | * This class exports constants and functionality from within v8 that |
| 5262 | * is necessary to implement inline functions in the v8 api. Don't |
| 5263 | * depend on functions and constants defined here. |
| 5264 | */ |
| 5265 | class Internals { |
| 5266 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5267 | // These values match non-compiler-dependent values defined within |
| 5268 | // the implementation of v8. |
| 5269 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5270 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5271 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5272 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5273 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5274 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5275 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5276 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5277 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5278 | static const int kContextEmbedderDataIndex = 64; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5279 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5280 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5281 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5282 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5283 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5284 | static const int kIsolateStateOffset = 0; |
| 5285 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5286 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5287 | static const int kUndefinedValueRootIndex = 5; |
| 5288 | static const int kNullValueRootIndex = 7; |
| 5289 | static const int kTrueValueRootIndex = 8; |
| 5290 | static const int kFalseValueRootIndex = 9; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5291 | static const int kEmptyStringRootIndex = 129; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5292 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5293 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5294 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5295 | static const int kNodeStateMask = 0xf; |
| 5296 | static const int kNodeStateIsWeakValue = 2; |
| 5297 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5298 | static const int kNodeIsIndependentShift = 4; |
| 5299 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5300 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5301 | static const int kJSObjectType = 0xae; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5302 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5303 | static const int kOddballType = 0x83; |
| 5304 | static const int kForeignType = 0x86; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5305 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5306 | static const int kUndefinedOddballKind = 5; |
| 5307 | static const int kNullOddballKind = 3; |
| 5308 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5309 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5310 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5311 | kHeapObjectTag); |
| 5312 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5313 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5314 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5315 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5316 | } |
| 5317 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5318 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5319 | return PlatformSmiTagging::IntToSmi(value); |
| 5320 | } |
| 5321 | |
| 5322 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5323 | return PlatformSmiTagging::IsValidSmi(value); |
| 5324 | } |
| 5325 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5326 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5327 | typedef internal::Object O; |
| 5328 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5329 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5330 | } |
| 5331 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5332 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5333 | typedef internal::Object O; |
| 5334 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5335 | } |
| 5336 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5337 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5338 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5339 | return representation == kExternalTwoByteRepresentationTag; |
| 5340 | } |
| 5341 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5342 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5343 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5344 | return *reinterpret_cast<int*>(addr) == 1; |
| 5345 | } |
| 5346 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5347 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5348 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5349 | return *addr & (1 << shift); |
| 5350 | } |
| 5351 | |
| 5352 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5353 | bool value, int shift)) { |
| 5354 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5355 | uint8_t mask = 1 << shift; |
| 5356 | *addr = (*addr & ~mask) | (value << shift); |
| 5357 | } |
| 5358 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5359 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5360 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5361 | return *addr & kNodeStateMask; |
| 5362 | } |
| 5363 | |
| 5364 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5365 | uint8_t value)) { |
| 5366 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5367 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5368 | } |
| 5369 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5370 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5371 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5372 | kIsolateEmbedderDataOffset; |
| 5373 | *reinterpret_cast<void**>(addr) = data; |
| 5374 | } |
| 5375 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5376 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5377 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5378 | kIsolateEmbedderDataOffset; |
| 5379 | return *reinterpret_cast<void**>(addr); |
| 5380 | } |
| 5381 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5382 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5383 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5384 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5385 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5386 | } |
| 5387 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5388 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5389 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5390 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5391 | return *reinterpret_cast<T*>(addr); |
| 5392 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5393 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5394 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5395 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5396 | typedef internal::Object O; |
| 5397 | typedef internal::Internals I; |
| 5398 | O* ctx = *reinterpret_cast<O**>(context); |
| 5399 | int embedder_data_offset = I::kContextHeaderSize + |
| 5400 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5401 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5402 | int value_offset = |
| 5403 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5404 | return I::ReadField<T>(embedder_data, value_offset); |
| 5405 | } |
| 5406 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5407 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5408 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5409 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5410 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5411 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5412 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5413 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5414 | }; |
| 5415 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5416 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5417 | |
| 5418 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5419 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5420 | Local<T>::Local() : Handle<T>() { } |
| 5421 | |
| 5422 | |
| 5423 | template <class T> |
| 5424 | Local<T> Local<T>::New(Handle<T> that) { |
| 5425 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5426 | T* that_ptr = *that; |
| 5427 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5428 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5429 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5430 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5431 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5432 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5433 | } |
| 5434 | |
| 5435 | |
| 5436 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5437 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5438 | return New(isolate, that.val_); |
| 5439 | } |
| 5440 | |
| 5441 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5442 | template <class T> |
| 5443 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5444 | return New(isolate, that.val_); |
| 5445 | } |
| 5446 | |
| 5447 | template <class T> |
| 5448 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5449 | if (that == NULL) return Handle<T>(); |
| 5450 | T* that_ptr = that; |
| 5451 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5452 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5453 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5454 | } |
| 5455 | #endif |
| 5456 | |
| 5457 | |
| 5458 | template <class T> |
| 5459 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5460 | if (that == NULL) return Local<T>(); |
| 5461 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5462 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5463 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5464 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5465 | } |
| 5466 | |
| 5467 | |
| 5468 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5469 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5470 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | |
| 5474 | template <class T> |
| 5475 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5476 | return New(Isolate::GetCurrent(), that.val_); |
| 5477 | } |
| 5478 | |
| 5479 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5480 | template <class T> |
| 5481 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5482 | return New(Isolate::GetCurrent(), that.val_); |
| 5483 | } |
| 5484 | #endif |
| 5485 | |
| 5486 | template <class T> |
| 5487 | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5488 | if (that == NULL) return Persistent<T>(); |
| 5489 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5490 | return Persistent<T>(reinterpret_cast<T*>( |
| 5491 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5492 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | |
| 5496 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5497 | bool Persistent<T>::IsIndependent() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5498 | return IsIndependent(Isolate::GetCurrent()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | |
| 5502 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5503 | bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5504 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5505 | if (this->IsEmpty()) return false; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5506 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5507 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5508 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | |
| 5512 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5513 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5514 | return IsNearDeath(Isolate::GetCurrent()); |
| 5515 | } |
| 5516 | |
| 5517 | |
| 5518 | template <class T> |
| 5519 | bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 5520 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5521 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5522 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5523 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5524 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | |
| 5528 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5529 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5530 | return IsWeak(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | |
| 5534 | template <class T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5535 | bool Persistent<T>::IsWeak(Isolate* isolate) const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5536 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5537 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5538 | if (!I::IsInitialized(isolate)) 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> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5555 | void Persistent<T>::Dispose(Isolate* isolate) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5556 | Dispose(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | |
| 5560 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5561 | template <typename S, typename P> |
| 5562 | void Persistent<T>::MakeWeak( |
| 5563 | Isolate* isolate, |
| 5564 | P* parameters, |
| 5565 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5566 | TYPE_CHECK(S, T); |
| 5567 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5568 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5569 | reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5570 | parameters, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5571 | reinterpret_cast<Revivable>(callback), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5572 | NULL); |
| 5573 | } |
| 5574 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5575 | |
| 5576 | template <class T> |
| 5577 | template <typename P> |
| 5578 | void Persistent<T>::MakeWeak( |
| 5579 | Isolate* isolate, |
| 5580 | P* parameters, |
| 5581 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5582 | MakeWeak<T, P>(isolate, parameters, callback); |
| 5583 | } |
| 5584 | |
| 5585 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5586 | template <class T> |
| 5587 | void Persistent<T>::MakeWeak(Isolate* isolate, |
| 5588 | void* parameters, |
| 5589 | NearDeathCallback callback) { |
| 5590 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5591 | reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5592 | parameters, |
| 5593 | NULL, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5594 | callback); |
| 5595 | } |
| 5596 | |
| 5597 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5598 | void Persistent<T>::ClearWeak() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5599 | ClearWeak(Isolate::GetCurrent()); |
| 5600 | } |
| 5601 | |
| 5602 | template <class T> |
| 5603 | void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 5604 | V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5605 | reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5608 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5609 | void Persistent<T>::MarkIndependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5610 | MarkIndependent(Isolate::GetCurrent()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | template <class T> |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5614 | void Persistent<T>::MarkIndependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5615 | typedef internal::Internals I; |
| 5616 | if (this->IsEmpty()) return; |
| 5617 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5618 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5619 | true, |
| 5620 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | template <class T> |
| 5624 | void Persistent<T>::MarkPartiallyDependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5625 | MarkPartiallyDependent(Isolate::GetCurrent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | template <class T> |
| 5629 | void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5630 | typedef internal::Internals I; |
| 5631 | if (this->IsEmpty()) return; |
| 5632 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5633 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5634 | true, |
| 5635 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5639 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5640 | SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 5641 | } |
| 5642 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5643 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5644 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5645 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5646 | Dispose(isolate); |
| 5647 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5648 | *this = *New(isolate, other); |
| 5649 | #else |
| 5650 | if (other.IsEmpty()) { |
| 5651 | this->val_ = NULL; |
| 5652 | return; |
| 5653 | } |
| 5654 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5655 | this->val_ = reinterpret_cast<T*>( |
| 5656 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5657 | #endif |
| 5658 | } |
| 5659 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5660 | |
| 5661 | template <class T> |
| 5662 | T* Persistent<T>::ClearAndLeak() { |
| 5663 | T* old; |
| 5664 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5665 | old = **this; |
| 5666 | *this = Persistent<T>(); |
| 5667 | #else |
| 5668 | old = val_; |
| 5669 | val_ = NULL; |
| 5670 | #endif |
| 5671 | return old; |
| 5672 | } |
| 5673 | |
| 5674 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5675 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5676 | void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5677 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5678 | if (this->IsEmpty()) return; |
| 5679 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5680 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5681 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5682 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5683 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5684 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5685 | template <class T> |
| 5686 | uint16_t Persistent<T>::WrapperClassId() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5687 | return WrapperClassId(Isolate::GetCurrent()); |
| 5688 | } |
| 5689 | |
| 5690 | template <class T> |
| 5691 | uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5692 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5693 | if (this->IsEmpty()) return 0; |
| 5694 | if (!I::IsInitialized(isolate)) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5695 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5696 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5697 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5700 | |
| 5701 | template<typename T> |
| 5702 | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| 5703 | |
| 5704 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 5705 | template<typename S> |
| 5706 | void ReturnValue<T>::Set(const Persistent<S>& handle) { |
| 5707 | TYPE_CHECK(T, S); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5708 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5709 | } |
| 5710 | |
| 5711 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame^] | 5712 | template<typename S> |
| 5713 | void ReturnValue<T>::Set(const Handle<S> handle) { |
| 5714 | TYPE_CHECK(T, S); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5715 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5716 | } |
| 5717 | |
| 5718 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5719 | void ReturnValue<T>::Set(double i) { |
| 5720 | Set(Number::New(GetIsolate(), i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5724 | void ReturnValue<T>::Set(int32_t i) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5725 | typedef internal::Internals I; |
| 5726 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5727 | *value_ = I::IntToSmi(i); |
| 5728 | return; |
| 5729 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5730 | Set(Integer::New(i, GetIsolate())); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5734 | void ReturnValue<T>::Set(uint32_t i) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5735 | typedef internal::Internals I; |
| 5736 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5737 | *value_ = I::IntToSmi(i); |
| 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) { |
| 5745 | typedef internal::Internals I; |
| 5746 | int root_index; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5747 | if (value) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5748 | root_index = I::kTrueValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5749 | } else { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5750 | root_index = I::kFalseValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5751 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5752 | *value_ = *I::GetRoot(GetIsolate(), root_index); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5756 | void ReturnValue<T>::SetNull() { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5757 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5758 | *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5762 | void ReturnValue<T>::SetUndefined() { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5763 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5764 | *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5768 | Isolate* ReturnValue<T>::GetIsolate() { |
| 5769 | // Isolate is always the pointer below value_ on the stack. |
| 5770 | return *reinterpret_cast<Isolate**>(&value_[-1]); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | |
| 5774 | template<typename T> |
| 5775 | FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, |
| 5776 | internal::Object** values, |
| 5777 | int length, |
| 5778 | bool is_construct_call) |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5779 | : implicit_args_(implicit_args), |
| 5780 | values_(values), |
| 5781 | length_(length), |
| 5782 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5783 | |
| 5784 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5785 | Arguments::Arguments(internal::Object** args, |
| 5786 | internal::Object** values, |
| 5787 | int length, |
| 5788 | bool is_construct_call) |
| 5789 | : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { } |
| 5790 | |
| 5791 | |
| 5792 | template<typename T> |
| 5793 | Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5794 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5795 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5796 | } |
| 5797 | |
| 5798 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5799 | template<typename T> |
| 5800 | Local<Function> FunctionCallbackInfo<T>::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5801 | return Local<Function>(reinterpret_cast<Function*>( |
| 5802 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5806 | template<typename T> |
| 5807 | Local<Object> FunctionCallbackInfo<T>::This() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5808 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5809 | } |
| 5810 | |
| 5811 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5812 | template<typename T> |
| 5813 | Local<Object> FunctionCallbackInfo<T>::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5814 | return Local<Object>(reinterpret_cast<Object*>( |
| 5815 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5819 | template<typename T> |
| 5820 | Local<Value> FunctionCallbackInfo<T>::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5821 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5825 | template<typename T> |
| 5826 | Isolate* FunctionCallbackInfo<T>::GetIsolate() const { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5827 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5828 | } |
| 5829 | |
| 5830 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5831 | template<typename T> |
| 5832 | ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const { |
| 5833 | return ReturnValue<T>(&implicit_args_[kReturnValueIndex]); |
| 5834 | } |
| 5835 | |
| 5836 | |
| 5837 | template<typename T> |
| 5838 | bool FunctionCallbackInfo<T>::IsConstructCall() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5839 | return is_construct_call_; |
| 5840 | } |
| 5841 | |
| 5842 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5843 | template<typename T> |
| 5844 | int FunctionCallbackInfo<T>::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5845 | return length_; |
| 5846 | } |
| 5847 | |
| 5848 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5849 | template <class T> |
| 5850 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5851 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5852 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5853 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5854 | } |
| 5855 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5856 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5857 | return resource_name_; |
| 5858 | } |
| 5859 | |
| 5860 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5861 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5862 | return resource_line_offset_; |
| 5863 | } |
| 5864 | |
| 5865 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5866 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5867 | return resource_column_offset_; |
| 5868 | } |
| 5869 | |
| 5870 | |
| 5871 | Handle<Boolean> Boolean::New(bool value) { |
| 5872 | return value ? True() : False(); |
| 5873 | } |
| 5874 | |
| 5875 | |
| 5876 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5877 | Set(v8::String::New(name), value); |
| 5878 | } |
| 5879 | |
| 5880 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5881 | Local<Value> Object::GetInternalField(int index) { |
| 5882 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5883 | typedef internal::Object O; |
| 5884 | typedef internal::Internals I; |
| 5885 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5886 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5887 | // 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] | 5888 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5889 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5890 | O* value = I::ReadField<O*>(obj, offset); |
| 5891 | O** result = HandleScope::CreateHandle(value); |
| 5892 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5893 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5894 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5895 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5899 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5900 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5901 | typedef internal::Object O; |
| 5902 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5903 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5904 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5905 | // 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] | 5906 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5907 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5908 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5909 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5910 | #endif |
| 5911 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | |
| 5915 | String* String::Cast(v8::Value* value) { |
| 5916 | #ifdef V8_ENABLE_CHECKS |
| 5917 | CheckCast(value); |
| 5918 | #endif |
| 5919 | return static_cast<String*>(value); |
| 5920 | } |
| 5921 | |
| 5922 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5923 | Local<String> String::Empty(Isolate* isolate) { |
| 5924 | typedef internal::Object* S; |
| 5925 | typedef internal::Internals I; |
| 5926 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5927 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5928 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5929 | } |
| 5930 | |
| 5931 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5932 | Local<String> String::New(const char* data, int length) { |
| 5933 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5934 | } |
| 5935 | |
| 5936 | |
| 5937 | Local<String> String::New(const uint16_t* data, int length) { |
| 5938 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5939 | } |
| 5940 | |
| 5941 | |
| 5942 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5943 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5944 | } |
| 5945 | |
| 5946 | |
| 5947 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5948 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5949 | } |
| 5950 | |
| 5951 | |
| 5952 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5953 | return NewFromTwoByte( |
| 5954 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5955 | } |
| 5956 | |
| 5957 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5958 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5959 | typedef internal::Object O; |
| 5960 | typedef internal::Internals I; |
| 5961 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5962 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5963 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5964 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5965 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5966 | } else { |
| 5967 | result = NULL; |
| 5968 | } |
| 5969 | #ifdef V8_ENABLE_CHECKS |
| 5970 | VerifyExternalStringResource(result); |
| 5971 | #endif |
| 5972 | return result; |
| 5973 | } |
| 5974 | |
| 5975 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5976 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5977 | String::Encoding* encoding_out) const { |
| 5978 | typedef internal::Object O; |
| 5979 | typedef internal::Internals I; |
| 5980 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5981 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5982 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5983 | ExternalStringResourceBase* resource = NULL; |
| 5984 | if (type == I::kExternalAsciiRepresentationTag || |
| 5985 | type == I::kExternalTwoByteRepresentationTag) { |
| 5986 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5987 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5988 | } |
| 5989 | #ifdef V8_ENABLE_CHECKS |
| 5990 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5991 | #endif |
| 5992 | return resource; |
| 5993 | } |
| 5994 | |
| 5995 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5996 | bool Value::IsUndefined() const { |
| 5997 | #ifdef V8_ENABLE_CHECKS |
| 5998 | return FullIsUndefined(); |
| 5999 | #else |
| 6000 | return QuickIsUndefined(); |
| 6001 | #endif |
| 6002 | } |
| 6003 | |
| 6004 | bool Value::QuickIsUndefined() const { |
| 6005 | typedef internal::Object O; |
| 6006 | typedef internal::Internals I; |
| 6007 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6008 | if (!I::HasHeapObjectTag(obj)) return false; |
| 6009 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 6010 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 6011 | } |
| 6012 | |
| 6013 | |
| 6014 | bool Value::IsNull() const { |
| 6015 | #ifdef V8_ENABLE_CHECKS |
| 6016 | return FullIsNull(); |
| 6017 | #else |
| 6018 | return QuickIsNull(); |
| 6019 | #endif |
| 6020 | } |
| 6021 | |
| 6022 | bool Value::QuickIsNull() const { |
| 6023 | typedef internal::Object O; |
| 6024 | typedef internal::Internals I; |
| 6025 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6026 | if (!I::HasHeapObjectTag(obj)) return false; |
| 6027 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 6028 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 6029 | } |
| 6030 | |
| 6031 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6032 | bool Value::IsString() const { |
| 6033 | #ifdef V8_ENABLE_CHECKS |
| 6034 | return FullIsString(); |
| 6035 | #else |
| 6036 | return QuickIsString(); |
| 6037 | #endif |
| 6038 | } |
| 6039 | |
| 6040 | bool Value::QuickIsString() const { |
| 6041 | typedef internal::Object O; |
| 6042 | typedef internal::Internals I; |
| 6043 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6044 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6045 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6049 | Symbol* Symbol::Cast(v8::Value* value) { |
| 6050 | #ifdef V8_ENABLE_CHECKS |
| 6051 | CheckCast(value); |
| 6052 | #endif |
| 6053 | return static_cast<Symbol*>(value); |
| 6054 | } |
| 6055 | |
| 6056 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6057 | Number* Number::Cast(v8::Value* value) { |
| 6058 | #ifdef V8_ENABLE_CHECKS |
| 6059 | CheckCast(value); |
| 6060 | #endif |
| 6061 | return static_cast<Number*>(value); |
| 6062 | } |
| 6063 | |
| 6064 | |
| 6065 | Integer* Integer::Cast(v8::Value* value) { |
| 6066 | #ifdef V8_ENABLE_CHECKS |
| 6067 | CheckCast(value); |
| 6068 | #endif |
| 6069 | return static_cast<Integer*>(value); |
| 6070 | } |
| 6071 | |
| 6072 | |
| 6073 | Date* Date::Cast(v8::Value* value) { |
| 6074 | #ifdef V8_ENABLE_CHECKS |
| 6075 | CheckCast(value); |
| 6076 | #endif |
| 6077 | return static_cast<Date*>(value); |
| 6078 | } |
| 6079 | |
| 6080 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6081 | StringObject* StringObject::Cast(v8::Value* value) { |
| 6082 | #ifdef V8_ENABLE_CHECKS |
| 6083 | CheckCast(value); |
| 6084 | #endif |
| 6085 | return static_cast<StringObject*>(value); |
| 6086 | } |
| 6087 | |
| 6088 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6089 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 6090 | #ifdef V8_ENABLE_CHECKS |
| 6091 | CheckCast(value); |
| 6092 | #endif |
| 6093 | return static_cast<SymbolObject*>(value); |
| 6094 | } |
| 6095 | |
| 6096 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6097 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 6098 | #ifdef V8_ENABLE_CHECKS |
| 6099 | CheckCast(value); |
| 6100 | #endif |
| 6101 | return static_cast<NumberObject*>(value); |
| 6102 | } |
| 6103 | |
| 6104 | |
| 6105 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 6106 | #ifdef V8_ENABLE_CHECKS |
| 6107 | CheckCast(value); |
| 6108 | #endif |
| 6109 | return static_cast<BooleanObject*>(value); |
| 6110 | } |
| 6111 | |
| 6112 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 6113 | RegExp* RegExp::Cast(v8::Value* value) { |
| 6114 | #ifdef V8_ENABLE_CHECKS |
| 6115 | CheckCast(value); |
| 6116 | #endif |
| 6117 | return static_cast<RegExp*>(value); |
| 6118 | } |
| 6119 | |
| 6120 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6121 | Object* Object::Cast(v8::Value* value) { |
| 6122 | #ifdef V8_ENABLE_CHECKS |
| 6123 | CheckCast(value); |
| 6124 | #endif |
| 6125 | return static_cast<Object*>(value); |
| 6126 | } |
| 6127 | |
| 6128 | |
| 6129 | Array* Array::Cast(v8::Value* value) { |
| 6130 | #ifdef V8_ENABLE_CHECKS |
| 6131 | CheckCast(value); |
| 6132 | #endif |
| 6133 | return static_cast<Array*>(value); |
| 6134 | } |
| 6135 | |
| 6136 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6137 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 6138 | #ifdef V8_ENABLE_CHECKS |
| 6139 | CheckCast(value); |
| 6140 | #endif |
| 6141 | return static_cast<ArrayBuffer*>(value); |
| 6142 | } |
| 6143 | |
| 6144 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6145 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 6146 | #ifdef V8_ENABLE_CHECKS |
| 6147 | CheckCast(value); |
| 6148 | #endif |
| 6149 | return static_cast<TypedArray*>(value); |
| 6150 | } |
| 6151 | |
| 6152 | |
| 6153 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 6154 | #ifdef V8_ENABLE_CHECKS |
| 6155 | CheckCast(value); |
| 6156 | #endif |
| 6157 | return static_cast<Uint8Array*>(value); |
| 6158 | } |
| 6159 | |
| 6160 | |
| 6161 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 6162 | #ifdef V8_ENABLE_CHECKS |
| 6163 | CheckCast(value); |
| 6164 | #endif |
| 6165 | return static_cast<Int8Array*>(value); |
| 6166 | } |
| 6167 | |
| 6168 | |
| 6169 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 6170 | #ifdef V8_ENABLE_CHECKS |
| 6171 | CheckCast(value); |
| 6172 | #endif |
| 6173 | return static_cast<Uint16Array*>(value); |
| 6174 | } |
| 6175 | |
| 6176 | |
| 6177 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 6178 | #ifdef V8_ENABLE_CHECKS |
| 6179 | CheckCast(value); |
| 6180 | #endif |
| 6181 | return static_cast<Int16Array*>(value); |
| 6182 | } |
| 6183 | |
| 6184 | |
| 6185 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 6186 | #ifdef V8_ENABLE_CHECKS |
| 6187 | CheckCast(value); |
| 6188 | #endif |
| 6189 | return static_cast<Uint32Array*>(value); |
| 6190 | } |
| 6191 | |
| 6192 | |
| 6193 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 6194 | #ifdef V8_ENABLE_CHECKS |
| 6195 | CheckCast(value); |
| 6196 | #endif |
| 6197 | return static_cast<Int32Array*>(value); |
| 6198 | } |
| 6199 | |
| 6200 | |
| 6201 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 6202 | #ifdef V8_ENABLE_CHECKS |
| 6203 | CheckCast(value); |
| 6204 | #endif |
| 6205 | return static_cast<Float32Array*>(value); |
| 6206 | } |
| 6207 | |
| 6208 | |
| 6209 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 6210 | #ifdef V8_ENABLE_CHECKS |
| 6211 | CheckCast(value); |
| 6212 | #endif |
| 6213 | return static_cast<Float64Array*>(value); |
| 6214 | } |
| 6215 | |
| 6216 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6217 | Function* Function::Cast(v8::Value* value) { |
| 6218 | #ifdef V8_ENABLE_CHECKS |
| 6219 | CheckCast(value); |
| 6220 | #endif |
| 6221 | return static_cast<Function*>(value); |
| 6222 | } |
| 6223 | |
| 6224 | |
| 6225 | External* External::Cast(v8::Value* value) { |
| 6226 | #ifdef V8_ENABLE_CHECKS |
| 6227 | CheckCast(value); |
| 6228 | #endif |
| 6229 | return static_cast<External*>(value); |
| 6230 | } |
| 6231 | |
| 6232 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6233 | template<typename T> |
| 6234 | Isolate* PropertyCallbackInfo<T>::GetIsolate() const { |
| 6235 | return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6239 | template<typename T> |
| 6240 | Local<Value> PropertyCallbackInfo<T>::Data() const { |
| 6241 | return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6245 | template<typename T> |
| 6246 | Local<Object> PropertyCallbackInfo<T>::This() const { |
| 6247 | return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6251 | template<typename T> |
| 6252 | Local<Object> PropertyCallbackInfo<T>::Holder() const { |
| 6253 | return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex])); |
| 6254 | } |
| 6255 | |
| 6256 | |
| 6257 | template<typename T> |
| 6258 | ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { |
| 6259 | return ReturnValue<T>(&args_[kReturnValueIndex]); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 6263 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 6264 | typedef internal::Object* S; |
| 6265 | typedef internal::Internals I; |
| 6266 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 6267 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 6268 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6269 | } |
| 6270 | |
| 6271 | |
| 6272 | Handle<Primitive> Null(Isolate* isolate) { |
| 6273 | typedef internal::Object* S; |
| 6274 | typedef internal::Internals I; |
| 6275 | if (!I::IsInitialized(isolate)) return Null(); |
| 6276 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 6277 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6278 | } |
| 6279 | |
| 6280 | |
| 6281 | Handle<Boolean> True(Isolate* isolate) { |
| 6282 | typedef internal::Object* S; |
| 6283 | typedef internal::Internals I; |
| 6284 | if (!I::IsInitialized(isolate)) return True(); |
| 6285 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 6286 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6287 | } |
| 6288 | |
| 6289 | |
| 6290 | Handle<Boolean> False(Isolate* isolate) { |
| 6291 | typedef internal::Object* S; |
| 6292 | typedef internal::Internals I; |
| 6293 | if (!I::IsInitialized(isolate)) return False(); |
| 6294 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 6295 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6296 | } |
| 6297 | |
| 6298 | |
| 6299 | void Isolate::SetData(void* data) { |
| 6300 | typedef internal::Internals I; |
| 6301 | I::SetEmbedderData(this, data); |
| 6302 | } |
| 6303 | |
| 6304 | |
| 6305 | void* Isolate::GetData() { |
| 6306 | typedef internal::Internals I; |
| 6307 | return I::GetEmbedderData(this); |
| 6308 | } |
| 6309 | |
| 6310 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 6311 | Local<Value> Context::GetEmbedderData(int index) { |
| 6312 | #ifndef V8_ENABLE_CHECKS |
| 6313 | typedef internal::Object O; |
| 6314 | typedef internal::Internals I; |
| 6315 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 6316 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 6317 | #else |
| 6318 | return SlowGetEmbedderData(index); |
| 6319 | #endif |
| 6320 | } |
| 6321 | |
| 6322 | |
| 6323 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 6324 | #ifndef V8_ENABLE_CHECKS |
| 6325 | typedef internal::Internals I; |
| 6326 | return I::ReadEmbedderData<void*>(this, index); |
| 6327 | #else |
| 6328 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 6329 | #endif |
| 6330 | } |
| 6331 | |
| 6332 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6333 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 6334 | * \example shell.cc |
| 6335 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6336 | * command-line and executes them. |
| 6337 | */ |
| 6338 | |
| 6339 | |
| 6340 | /** |
| 6341 | * \example process.cc |
| 6342 | */ |
| 6343 | |
| 6344 | |
| 6345 | } // namespace v8 |
| 6346 | |
| 6347 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6348 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6349 | #undef TYPE_CHECK |
| 6350 | |
| 6351 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6352 | #endif // V8_H_ |