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 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 217 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 218 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 219 | #define TYPE_CHECK(T, S) \ |
| 220 | while (false) { \ |
| 221 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | } |
| 223 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 224 | |
| 225 | #define V8_USE_UNSAFE_HANDLES |
| 226 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | /** |
| 228 | * An object reference managed by the v8 garbage collector. |
| 229 | * |
| 230 | * All objects returned from v8 have to be tracked by the garbage |
| 231 | * collector so that it knows that the objects are still alive. Also, |
| 232 | * because the garbage collector may move objects, it is unsafe to |
| 233 | * point directly to an object. Instead, all objects are stored in |
| 234 | * handles which are known by the garbage collector and updated |
| 235 | * whenever an object moves. Handles should always be passed by value |
| 236 | * (except in cases like out-parameters) and they should never be |
| 237 | * allocated on the heap. |
| 238 | * |
| 239 | * There are two types of handles: local and persistent handles. |
| 240 | * Local handles are light-weight and transient and typically used in |
| 241 | * local operations. They are managed by HandleScopes. Persistent |
| 242 | * handles can be used when storing objects across several independent |
| 243 | * operations and have to be explicitly deallocated when they're no |
| 244 | * longer used. |
| 245 | * |
| 246 | * It is safe to extract the object stored in the handle by |
| 247 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 248 | * 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] | 249 | * behind the scenes and the same rules apply to these values as to |
| 250 | * their handles. |
| 251 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 252 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | /** |
| 255 | * Creates an empty handle. |
| 256 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 257 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 259 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | /** |
| 261 | * Creates a new handle for the specified value. |
| 262 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 263 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 264 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | |
| 266 | /** |
| 267 | * Creates a handle for the contents of the specified handle. This |
| 268 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 269 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 271 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 272 | * between compatible handles, for instance assigning a |
| 273 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 274 | * because String is a subclass of Value. |
| 275 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 276 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | : val_(reinterpret_cast<T*>(*that)) { |
| 278 | /** |
| 279 | * This check fails when trying to convert between incompatible |
| 280 | * handles. For example, converting from a Handle<String> to a |
| 281 | * Handle<Number>. |
| 282 | */ |
| 283 | TYPE_CHECK(T, S); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Returns true if the handle is empty. |
| 288 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 289 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 290 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 291 | /** |
| 292 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 293 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 294 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 295 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 296 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 297 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 298 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Checks whether two handles are the same. |
| 302 | * Returns true if both are empty, or if the objects |
| 303 | * to which they refer are identical. |
| 304 | * The handles' references are not checked. |
| 305 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 306 | 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] | 307 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 308 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | if (a == 0) return b == 0; |
| 310 | if (b == 0) return false; |
| 311 | return *a == *b; |
| 312 | } |
| 313 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 314 | #ifndef V8_USE_UNSAFE_HANDLES |
| 315 | template <class S> V8_INLINE( |
| 316 | bool operator==(const Persistent<S>& that) const) { |
| 317 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 318 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 319 | if (a == 0) return b == 0; |
| 320 | if (b == 0) return false; |
| 321 | return *a == *b; |
| 322 | } |
| 323 | #endif |
| 324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | /** |
| 326 | * Checks whether two handles are different. |
| 327 | * Returns true if only one of the handles is empty, or if |
| 328 | * the objects to which they refer are different. |
| 329 | * The handles' references are not checked. |
| 330 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 331 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | return !operator==(that); |
| 333 | } |
| 334 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 335 | 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] | 336 | #ifdef V8_ENABLE_CHECKS |
| 337 | // If we're going to perform the type check then we have to check |
| 338 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 339 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 340 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 341 | return Handle<T>(T::Cast(*that)); |
| 342 | } |
| 343 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 344 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 345 | return Handle<S>::Cast(*this); |
| 346 | } |
| 347 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 348 | #ifndef V8_USE_UNSAFE_HANDLES |
| 349 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 350 | return New(isolate, that.val_); |
| 351 | } |
| 352 | // TODO(dcarney): remove before cutover |
| 353 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 354 | return New(isolate, that.val_); |
| 355 | } |
| 356 | |
| 357 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 360 | #endif |
| 361 | /** |
| 362 | * Creates a new handle for the specified value. |
| 363 | */ |
| 364 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 365 | #endif |
| 366 | |
| 367 | private: |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 368 | template<class F> friend class Persistent; |
| 369 | template<class F> friend class Local; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 370 | friend class Arguments; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 371 | template<class F> friend class FunctionCallbackInfo; |
| 372 | template<class F> friend class PropertyCallbackInfo; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 373 | friend class String; |
| 374 | friend class Object; |
| 375 | friend class AccessorInfo; |
| 376 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 377 | friend Handle<Primitive> Null(Isolate* isolate); |
| 378 | friend Handle<Boolean> True(Isolate* isolate); |
| 379 | friend Handle<Boolean> False(Isolate* isolate); |
| 380 | friend class Context; |
| 381 | friend class InternalHandleHelper; |
| 382 | friend class LocalContext; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 383 | friend class HandleScope; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 384 | |
| 385 | #ifndef V8_USE_UNSAFE_HANDLES |
| 386 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 387 | #endif |
| 388 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | T* val_; |
| 390 | }; |
| 391 | |
| 392 | |
| 393 | /** |
| 394 | * A light-weight stack-allocated object handle. All operations |
| 395 | * that return objects from within v8 return them in local handles. They |
| 396 | * are created within HandleScopes, and all local handles allocated within a |
| 397 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 398 | * is not necessary to explicitly deallocate local handles. |
| 399 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 400 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 401 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 402 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 403 | V8_INLINE(Local()); |
| 404 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 406 | /** |
| 407 | * This check fails when trying to convert between incompatible |
| 408 | * handles. For example, converting from a Handle<String> to a |
| 409 | * Handle<Number>. |
| 410 | */ |
| 411 | TYPE_CHECK(T, S); |
| 412 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 413 | |
| 414 | |
| 415 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 416 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 417 | #endif |
| 418 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 419 | 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] | 420 | #ifdef V8_ENABLE_CHECKS |
| 421 | // If we're going to perform the type check then we have to check |
| 422 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 423 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 424 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | return Local<T>(T::Cast(*that)); |
| 426 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 427 | #ifndef V8_USE_UNSAFE_HANDLES |
| 428 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 429 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 430 | TYPE_CHECK(T, S); |
| 431 | } |
| 432 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 434 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 435 | return Local<S>::Cast(*this); |
| 436 | } |
| 437 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 438 | /** |
| 439 | * Create a local handle for the content of another handle. |
| 440 | * The referee is kept alive by the local handle even when |
| 441 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 442 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 443 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 444 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 445 | #ifndef V8_USE_UNSAFE_HANDLES |
| 446 | // TODO(dcarney): remove before cutover |
| 447 | 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] | 448 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 449 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 450 | |
| 451 | private: |
| 452 | #endif |
| 453 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 454 | #endif |
| 455 | |
| 456 | private: |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 457 | template<class F> friend class Persistent; |
| 458 | template<class F> friend class Handle; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 459 | friend class Arguments; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 460 | template<class F> friend class FunctionCallbackInfo; |
| 461 | template<class F> friend class PropertyCallbackInfo; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 462 | friend class String; |
| 463 | friend class Object; |
| 464 | friend class AccessorInfo; |
| 465 | friend class Context; |
| 466 | friend class InternalHandleHelper; |
| 467 | friend class LocalContext; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 468 | friend class HandleScope; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 469 | |
| 470 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 471 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 475 | * 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] | 476 | * allocated, a Persistent handle remains valid until it is explicitly |
| 477 | * disposed. |
| 478 | * |
| 479 | * A persistent handle contains a reference to a storage cell within |
| 480 | * the v8 engine which holds an object value and which is updated by |
| 481 | * the garbage collector whenever the object is moved. A new storage |
| 482 | * cell can be created using Persistent::New and existing handles can |
| 483 | * be disposed using Persistent::Dispose. Since persistent handles |
| 484 | * are passed by value you may have many persistent handle objects |
| 485 | * that point to the same storage cell. For instance, if you pass a |
| 486 | * persistent handle as an argument to a function you will not get two |
| 487 | * different storage cells but rather two references to the same |
| 488 | * storage cell. |
| 489 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 490 | template <class T> class Persistent // NOLINT |
| 491 | #ifdef V8_USE_UNSAFE_HANDLES |
| 492 | : public Handle<T> { |
| 493 | #else |
| 494 | { // NOLINT |
| 495 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 497 | #ifndef V8_USE_UNSAFE_HANDLES |
| 498 | V8_INLINE(Persistent()) : val_(0) { } |
| 499 | V8_INLINE(~Persistent()) { |
| 500 | // TODO(dcarney): add this back before cutover. |
| 501 | // Dispose(); |
| 502 | } |
| 503 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 504 | // TODO(dcarney): remove somehow before cutover |
| 505 | // The handle should either be 0, or a pointer to a live cell. |
| 506 | V8_INLINE(void Clear()) { val_ = 0; } |
| 507 | |
| 508 | /** |
| 509 | * A constructor that creates a new global cell pointing to that. In contrast |
| 510 | * to the copy constructor, this creates a new persistent handle which needs |
| 511 | * to be separately disposed. |
| 512 | */ |
| 513 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 514 | : val_(*New(isolate, that)) { } |
| 515 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 516 | template <class S> V8_INLINE(Persistent(Isolate* isolate, |
| 517 | Persistent<S>& that)) // NOLINT |
| 518 | : val_(*New(isolate, that)) { } |
| 519 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 520 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | /** |
| 522 | * Creates an empty persistent handle that doesn't point to any |
| 523 | * storage cell. |
| 524 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 525 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | |
| 527 | /** |
| 528 | * Creates a persistent handle for the same storage cell as the |
| 529 | * specified handle. This constructor allows you to pass persistent |
| 530 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 531 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 533 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | * between compatible persistent handles, for instance assigning a |
| 535 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 536 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 538 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 540 | /** |
| 541 | * This check fails when trying to convert between incompatible |
| 542 | * handles. For example, converting from a Handle<String> to a |
| 543 | * Handle<Number>. |
| 544 | */ |
| 545 | TYPE_CHECK(T, S); |
| 546 | } |
| 547 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 548 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 550 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 551 | * A constructor that creates a new global cell pointing to that. In contrast |
| 552 | * to the copy constructor, this creates a new persistent handle which needs |
| 553 | * to be separately disposed. |
| 554 | */ |
| 555 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 556 | : Handle<T>(New(isolate, that)) { } |
| 557 | |
| 558 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 559 | * "Casts" a plain handle which is known to be a persistent handle |
| 560 | * to a persistent handle. |
| 561 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 562 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | : Handle<T>(*that) { } |
| 564 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 565 | #endif |
| 566 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 567 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 568 | 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] | 569 | #ifdef V8_ENABLE_CHECKS |
| 570 | // If we're going to perform the type check then we have to check |
| 571 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 573 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | return Persistent<T>(T::Cast(*that)); |
| 575 | } |
| 576 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 577 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 578 | return Persistent<S>::Cast(*this); |
| 579 | } |
| 580 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 581 | #else |
| 582 | template <class S> |
| 583 | V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT |
| 584 | #ifdef V8_ENABLE_CHECKS |
| 585 | // If we're going to perform the type check then we have to check |
| 586 | // that the handle isn't empty before doing the checked cast. |
| 587 | if (!that.IsEmpty()) T::Cast(*that); |
| 588 | #endif |
| 589 | return reinterpret_cast<Persistent<T>&>(that); |
| 590 | } |
| 591 | |
| 592 | template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| 593 | return Persistent<S>::Cast(*this); |
| 594 | } |
| 595 | #endif |
| 596 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 597 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 598 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 600 | * 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] | 601 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 602 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 603 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 604 | #ifndef V8_USE_UNSAFE_HANDLES |
| 605 | // TODO(dcarney): remove before cutover |
| 606 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 607 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 608 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 609 | #ifndef V8_USE_UNSAFE_HANDLES |
| 610 | template <class S> V8_INLINE( |
| 611 | bool operator==(const Persistent<S>& that) const) { |
| 612 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 613 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 614 | if (a == 0) return b == 0; |
| 615 | if (b == 0) return false; |
| 616 | return *a == *b; |
| 617 | } |
| 618 | |
| 619 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 620 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 621 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 622 | if (a == 0) return b == 0; |
| 623 | if (b == 0) return false; |
| 624 | return *a == *b; |
| 625 | } |
| 626 | #endif |
| 627 | |
| 628 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 629 | |
| 630 | /** |
| 631 | * Releases the storage cell referenced by this persistent handle. |
| 632 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 633 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | * cell remain and IsEmpty will still return false. |
| 635 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 636 | // TODO(dcarney): deprecate |
| 637 | V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 638 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 639 | /** |
| 640 | * Make the reference to this object weak. When only weak handles |
| 641 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 642 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | * it the object reference and the given parameters. |
| 644 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 645 | template<typename S, typename P> |
| 646 | V8_INLINE(void MakeWeak( |
| 647 | P* parameters, |
| 648 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 649 | |
| 650 | template<typename P> |
| 651 | V8_INLINE(void MakeWeak( |
| 652 | P* parameters, |
| 653 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| 654 | |
| 655 | // TODO(dcarney): deprecate |
| 656 | template<typename S, typename P> |
| 657 | V8_INLINE(void MakeWeak( |
| 658 | Isolate* isolate, |
| 659 | P* parameters, |
| 660 | typename WeakReferenceCallbacks<S, P>::Revivable callback)) { |
| 661 | MakeWeak<S, P>(parameters, callback); |
| 662 | } |
| 663 | |
| 664 | // TODO(dcarney): deprecate |
| 665 | template<typename P> |
| 666 | V8_INLINE(void MakeWeak( |
| 667 | Isolate* isolate, |
| 668 | P* parameters, |
| 669 | typename WeakReferenceCallbacks<T, P>::Revivable callback)) { |
| 670 | MakeWeak<P>(parameters, callback); |
| 671 | } |
| 672 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 673 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 675 | // TODO(dcarney): deprecate |
| 676 | V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | |
| 678 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 679 | * Marks the reference to this object independent. Garbage collector is free |
| 680 | * to ignore any object groups containing this object. Weak callback for an |
| 681 | * independent handle should not assume that it will be preceded by a global |
| 682 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 683 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 684 | V8_INLINE(void MarkIndependent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 685 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 686 | // TODO(dcarney): deprecate |
| 687 | V8_INLINE(void MarkIndependent(Isolate* isolate)) { MarkIndependent(); } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 688 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 689 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 690 | * Marks the reference to this object partially dependent. Partially dependent |
| 691 | * handles only depend on other partially dependent handles and these |
| 692 | * dependencies are provided through object groups. It provides a way to build |
| 693 | * smaller object groups for young objects that represent only a subset of all |
| 694 | * external dependencies. This mark is automatically cleared after each |
| 695 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 696 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 697 | V8_INLINE(void MarkPartiallyDependent()); |
| 698 | |
| 699 | // TODO(dcarney): deprecate |
| 700 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)) { |
| 701 | MarkPartiallyDependent(); |
| 702 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 703 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 704 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 705 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 706 | // TODO(dcarney): deprecate |
| 707 | V8_INLINE(bool IsIndependent(Isolate* isolate) const) { |
| 708 | return IsIndependent(); |
| 709 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 710 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 711 | /** Checks if the handle holds the only reference to an object. */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 712 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 713 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 714 | // TODO(dcarney): deprecate |
| 715 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const) { return IsNearDeath(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 717 | /** Returns true if the handle's reference is weak. */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 718 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 720 | // TODO(dcarney): deprecate |
| 721 | V8_INLINE(bool IsWeak(Isolate* isolate) const) { return IsWeak(); } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 722 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 723 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 724 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 725 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 726 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 727 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 728 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 729 | // TODO(dcarney): deprecate |
| 730 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)) { |
| 731 | SetWrapperClassId(class_id); |
| 732 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 733 | |
| 734 | /** |
| 735 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 736 | * was previously assigned. |
| 737 | */ |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 738 | V8_INLINE(uint16_t WrapperClassId() const); |
| 739 | |
| 740 | // TODO(dcarney): deprecate |
| 741 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { |
| 742 | return WrapperClassId(); |
| 743 | } |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 744 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 745 | /** |
| 746 | * Disposes the current contents of the handle and replaces it. |
| 747 | */ |
| 748 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 749 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 750 | #ifndef V8_USE_UNSAFE_HANDLES |
| 751 | V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); |
| 752 | #endif |
| 753 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 754 | /** |
| 755 | * Returns the underlying raw pointer and clears the handle. The caller is |
| 756 | * responsible of eventually destroying the underlying object (by creating a |
| 757 | * Persistent handle which points to it and Disposing it). In the future, |
| 758 | * destructing a Persistent will also Dispose it. With this function, the |
| 759 | * embedder can let the Persistent go out of scope without it getting |
| 760 | * disposed. |
| 761 | */ |
| 762 | V8_INLINE(T* ClearAndLeak()); |
| 763 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 764 | #ifndef V8_USE_UNSAFE_HANDLES |
| 765 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 767 | // TODO(dcarney): make unlinkable before cutover |
| 768 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 769 | // TODO(dcarney): make unlinkable before cutover |
| 770 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 771 | this->val_ = that.val_; |
| 772 | return *this; |
| 773 | } |
| 774 | |
| 775 | public: |
| 776 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 777 | |
| 778 | private: |
| 779 | #endif |
| 780 | // TODO(dcarney): remove before cutover |
| 781 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 782 | // TODO(dcarney): remove before cutover |
| 783 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 784 | : val_(*that) { |
| 785 | TYPE_CHECK(T, S); |
| 786 | } |
| 787 | // TODO(dcarney): remove before cutover |
| 788 | V8_INLINE(T* operator*() const) { return val_; } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 789 | |
| 790 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 791 | // TODO(dcarney): remove before cutover |
| 792 | V8_INLINE(T* operator->() const) { return val_; } |
| 793 | public: |
| 794 | #endif |
| 795 | |
| 796 | private: |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 797 | template<class F> friend class Handle; |
| 798 | template<class F> friend class Local; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 799 | template<class F> friend class ReturnValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | friend class ImplementationUtilities; |
| 801 | friend class ObjectTemplate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 802 | friend class Context; |
| 803 | friend class InternalHandleHelper; |
| 804 | friend class LocalContext; |
| 805 | |
| 806 | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 807 | |
| 808 | #ifndef V8_USE_UNSAFE_HANDLES |
| 809 | T* val_; |
| 810 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 811 | }; |
| 812 | |
| 813 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 814 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | * A stack-allocated class that governs a number of local handles. |
| 816 | * After a handle scope has been created, all local handles will be |
| 817 | * allocated within that handle scope until either the handle scope is |
| 818 | * deleted or another handle scope is created. If there is already a |
| 819 | * 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] | 820 | * 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] | 821 | * new handles will again be allocated in the original handle scope. |
| 822 | * |
| 823 | * After the handle scope of a local handle has been deleted the |
| 824 | * garbage collector will no longer track the object stored in the |
| 825 | * handle and may deallocate it. The behavior of accessing a handle |
| 826 | * for which the handle scope has been deleted is undefined. |
| 827 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 828 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 829 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 830 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 831 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 833 | HandleScope(Isolate* isolate); |
| 834 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 835 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 836 | |
| 837 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 838 | * Closes the handle scope and returns the value as a handle in the |
| 839 | * previous scope, which is the new current scope after the call. |
| 840 | */ |
| 841 | template <class T> Local<T> Close(Handle<T> value); |
| 842 | |
| 843 | /** |
| 844 | * Counts the number of allocated handles. |
| 845 | */ |
| 846 | static int NumberOfHandles(); |
| 847 | |
| 848 | /** |
| 849 | * Creates a new handle with the given value. |
| 850 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 851 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 852 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 853 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 854 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 855 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | |
| 857 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 858 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 859 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | HandleScope(const HandleScope&); |
| 861 | void operator=(const HandleScope&); |
| 862 | void* operator new(size_t size); |
| 863 | void operator delete(void*, size_t); |
| 864 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 865 | // This Data class is accessible internally as HandleScopeData through a |
| 866 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 867 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 869 | internal::Object** next; |
| 870 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 871 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 872 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 874 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 875 | } |
| 876 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 877 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 878 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 879 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 880 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 881 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 882 | internal::Object** prev_next_; |
| 883 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 885 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 886 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 888 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 890 | friend class ImplementationUtilities; |
| 891 | }; |
| 892 | |
| 893 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 894 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 895 | |
| 896 | |
| 897 | /** |
| 898 | * The superclass of values and API object templates. |
| 899 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 900 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 901 | private: |
| 902 | Data(); |
| 903 | }; |
| 904 | |
| 905 | |
| 906 | /** |
| 907 | * Pre-compilation data that can be associated with a script. This |
| 908 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 909 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 910 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 912 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | public: |
| 914 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 915 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 916 | /** |
| 917 | * Pre-compiles the specified script (context-independent). |
| 918 | * |
| 919 | * \param input Pointer to UTF-8 script source code. |
| 920 | * \param length Length of UTF-8 script source code. |
| 921 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 922 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 923 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 924 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 925 | * Pre-compiles the specified script (context-independent). |
| 926 | * |
| 927 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 928 | * without using Lockers. |
| 929 | * |
| 930 | * \param source Script source code. |
| 931 | */ |
| 932 | static ScriptData* PreCompile(Handle<String> source); |
| 933 | |
| 934 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 935 | * Load previous pre-compilation data. |
| 936 | * |
| 937 | * \param data Pointer to data returned by a call to Data() of a previous |
| 938 | * ScriptData. Ownership is not transferred. |
| 939 | * \param length Length of data. |
| 940 | */ |
| 941 | static ScriptData* New(const char* data, int length); |
| 942 | |
| 943 | /** |
| 944 | * Returns the length of Data(). |
| 945 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 946 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 947 | |
| 948 | /** |
| 949 | * Returns a serialized representation of this ScriptData that can later be |
| 950 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 951 | */ |
| 952 | virtual const char* Data() = 0; |
| 953 | |
| 954 | /** |
| 955 | * Returns true if the source code could not be parsed. |
| 956 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 957 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 958 | }; |
| 959 | |
| 960 | |
| 961 | /** |
| 962 | * The origin, within a file, of a script. |
| 963 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 964 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 966 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 967 | Handle<Value> resource_name, |
| 968 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 969 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | : resource_name_(resource_name), |
| 971 | resource_line_offset_(resource_line_offset), |
| 972 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 973 | V8_INLINE(Handle<Value> ResourceName() const); |
| 974 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 975 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 977 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 978 | Handle<Integer> resource_line_offset_; |
| 979 | Handle<Integer> resource_column_offset_; |
| 980 | }; |
| 981 | |
| 982 | |
| 983 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 984 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 985 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 986 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 989 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 990 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 991 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 992 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 993 | * when New() returns |
| 994 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 995 | * using pre_data speeds compilation if it's done multiple times. |
| 996 | * Owned by caller, no references are kept when New() returns. |
| 997 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 998 | * 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] | 999 | * available to compile event handlers. |
| 1000 | * \return Compiled script object (context independent; when run it |
| 1001 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1003 | static Local<Script> New(Handle<String> source, |
| 1004 | ScriptOrigin* origin = NULL, |
| 1005 | ScriptData* pre_data = NULL, |
| 1006 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1007 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1008 | /** |
| 1009 | * Compiles the specified script using the specified file name |
| 1010 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1011 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1012 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1013 | * \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] | 1014 | * as the script's origin. |
| 1015 | * \return Compiled script object (context independent; when run it |
| 1016 | * will use the currently entered context). |
| 1017 | */ |
| 1018 | static Local<Script> New(Handle<String> source, |
| 1019 | Handle<Value> file_name); |
| 1020 | |
| 1021 | /** |
| 1022 | * Compiles the specified script (bound to current context). |
| 1023 | * |
| 1024 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1025 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1026 | * when Compile() returns |
| 1027 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 1028 | * using pre_data speeds compilation if it's done multiple times. |
| 1029 | * Owned by caller, no references are kept when Compile() returns. |
| 1030 | * \param script_data Arbitrary data associated with script. Using |
| 1031 | * this has same effect as calling SetData(), but makes data available |
| 1032 | * earlier (i.e. to compile event handlers). |
| 1033 | * \return Compiled script object, bound to the context that was active |
| 1034 | * when this function was called. When run it will always use this |
| 1035 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1036 | */ |
| 1037 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1038 | ScriptOrigin* origin = NULL, |
| 1039 | ScriptData* pre_data = NULL, |
| 1040 | Handle<String> script_data = Handle<String>()); |
| 1041 | |
| 1042 | /** |
| 1043 | * Compiles the specified script using the specified file name |
| 1044 | * object (typically a string) as the script's origin. |
| 1045 | * |
| 1046 | * \param source Script source code. |
| 1047 | * \param file_name File name to use as script's origin |
| 1048 | * \param script_data Arbitrary data associated with script. Using |
| 1049 | * this has same effect as calling SetData(), but makes data available |
| 1050 | * earlier (i.e. to compile event handlers). |
| 1051 | * \return Compiled script object, bound to the context that was active |
| 1052 | * when this function was called. When run it will always use this |
| 1053 | * context. |
| 1054 | */ |
| 1055 | static Local<Script> Compile(Handle<String> source, |
| 1056 | Handle<Value> file_name, |
| 1057 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1058 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1059 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1060 | * Runs the script returning the resulting value. If the script is |
| 1061 | * context independent (created using ::New) it will be run in the |
| 1062 | * currently entered context. If it is context specific (created |
| 1063 | * using ::Compile) it will be run in the context in which it was |
| 1064 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1065 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1067 | |
| 1068 | /** |
| 1069 | * Returns the script id value. |
| 1070 | */ |
| 1071 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1072 | |
| 1073 | /** |
| 1074 | * Associate an additional data object with the script. This is mainly used |
| 1075 | * with the debugger as this data object is only available through the |
| 1076 | * debugger API. |
| 1077 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1078 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1079 | |
| 1080 | /** |
| 1081 | * Returns the name value of one Script. |
| 1082 | */ |
| 1083 | Handle<Value> GetScriptName(); |
| 1084 | |
| 1085 | /** |
| 1086 | * Returns zero based line number of the code_pos location in the script. |
| 1087 | * -1 will be returned if no information available. |
| 1088 | */ |
| 1089 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | }; |
| 1091 | |
| 1092 | |
| 1093 | /** |
| 1094 | * An error message. |
| 1095 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1096 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1097 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1098 | Local<String> Get() const; |
| 1099 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1100 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1101 | /** |
| 1102 | * Returns the resource name for the script from where the function causing |
| 1103 | * the error originates. |
| 1104 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1105 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1106 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1107 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1108 | * Returns the resource data for the script from where the function causing |
| 1109 | * the error originates. |
| 1110 | */ |
| 1111 | Handle<Value> GetScriptData() const; |
| 1112 | |
| 1113 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1114 | * Exception stack trace. By default stack traces are not captured for |
| 1115 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1116 | * to change this option. |
| 1117 | */ |
| 1118 | Handle<StackTrace> GetStackTrace() const; |
| 1119 | |
| 1120 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1121 | * Returns the number, 1-based, of the line where the error occurred. |
| 1122 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1123 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1124 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1125 | /** |
| 1126 | * Returns the index within the script of the first character where |
| 1127 | * the error occurred. |
| 1128 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1129 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1130 | |
| 1131 | /** |
| 1132 | * Returns the index within the script of the last character where |
| 1133 | * the error occurred. |
| 1134 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1135 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1136 | |
| 1137 | /** |
| 1138 | * Returns the index within the line of the first character where |
| 1139 | * the error occurred. |
| 1140 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1141 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1142 | |
| 1143 | /** |
| 1144 | * Returns the index within the line of the last character where |
| 1145 | * the error occurred. |
| 1146 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1147 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1148 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1150 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1151 | |
| 1152 | static const int kNoLineNumberInfo = 0; |
| 1153 | static const int kNoColumnInfo = 0; |
| 1154 | }; |
| 1155 | |
| 1156 | |
| 1157 | /** |
| 1158 | * Representation of a JavaScript stack trace. The information collected is a |
| 1159 | * snapshot of the execution stack and the information remains valid after |
| 1160 | * execution continues. |
| 1161 | */ |
| 1162 | class V8EXPORT StackTrace { |
| 1163 | public: |
| 1164 | /** |
| 1165 | * Flags that determine what information is placed captured for each |
| 1166 | * StackFrame when grabbing the current stack trace. |
| 1167 | */ |
| 1168 | enum StackTraceOptions { |
| 1169 | kLineNumber = 1, |
| 1170 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1171 | kScriptName = 1 << 2, |
| 1172 | kFunctionName = 1 << 3, |
| 1173 | kIsEval = 1 << 4, |
| 1174 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1175 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1176 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1177 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1178 | }; |
| 1179 | |
| 1180 | /** |
| 1181 | * Returns a StackFrame at a particular index. |
| 1182 | */ |
| 1183 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1184 | |
| 1185 | /** |
| 1186 | * Returns the number of StackFrames. |
| 1187 | */ |
| 1188 | int GetFrameCount() const; |
| 1189 | |
| 1190 | /** |
| 1191 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1192 | */ |
| 1193 | Local<Array> AsArray(); |
| 1194 | |
| 1195 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1196 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1197 | * |
| 1198 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1199 | * \param options Enumerates the set of things we will capture for each |
| 1200 | * StackFrame. |
| 1201 | */ |
| 1202 | static Local<StackTrace> CurrentStackTrace( |
| 1203 | int frame_limit, |
| 1204 | StackTraceOptions options = kOverview); |
| 1205 | }; |
| 1206 | |
| 1207 | |
| 1208 | /** |
| 1209 | * A single JavaScript stack frame. |
| 1210 | */ |
| 1211 | class V8EXPORT StackFrame { |
| 1212 | public: |
| 1213 | /** |
| 1214 | * Returns the number, 1-based, of the line for the associate function call. |
| 1215 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1216 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1217 | * when capturing the StackTrace. |
| 1218 | */ |
| 1219 | int GetLineNumber() const; |
| 1220 | |
| 1221 | /** |
| 1222 | * Returns the 1-based column offset on the line for the associated function |
| 1223 | * call. |
| 1224 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1225 | * the column number, or if kColumnOffset was not passed as an option when |
| 1226 | * capturing the StackTrace. |
| 1227 | */ |
| 1228 | int GetColumn() const; |
| 1229 | |
| 1230 | /** |
| 1231 | * Returns the name of the resource that contains the script for the |
| 1232 | * function for this StackFrame. |
| 1233 | */ |
| 1234 | Local<String> GetScriptName() const; |
| 1235 | |
| 1236 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1237 | * Returns the name of the resource that contains the script for the |
| 1238 | * function for this StackFrame or sourceURL value if the script name |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1239 | * is undefined and its source ends with //# sourceURL=... string or |
| 1240 | * deprecated //@ sourceURL=... string. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1241 | */ |
| 1242 | Local<String> GetScriptNameOrSourceURL() const; |
| 1243 | |
| 1244 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1245 | * Returns the name of the function associated with this stack frame. |
| 1246 | */ |
| 1247 | Local<String> GetFunctionName() const; |
| 1248 | |
| 1249 | /** |
| 1250 | * Returns whether or not the associated function is compiled via a call to |
| 1251 | * eval(). |
| 1252 | */ |
| 1253 | bool IsEval() const; |
| 1254 | |
| 1255 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1256 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1257 | * constructor via "new". |
| 1258 | */ |
| 1259 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1260 | }; |
| 1261 | |
| 1262 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1263 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | |
| 1265 | |
| 1266 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1267 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1268 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1269 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1270 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | /** |
| 1272 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1273 | * 4.3.10. |
| 1274 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1275 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | |
| 1277 | /** |
| 1278 | * Returns true if this value is the null value. See ECMA-262 |
| 1279 | * 4.3.11. |
| 1280 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1281 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | |
| 1283 | /** |
| 1284 | * Returns true if this value is true. |
| 1285 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1286 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1287 | |
| 1288 | /** |
| 1289 | * Returns true if this value is false. |
| 1290 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1291 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1292 | |
| 1293 | /** |
| 1294 | * Returns true if this value is an instance of the String type. |
| 1295 | * See ECMA-262 8.4. |
| 1296 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1297 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | |
| 1299 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1300 | * Returns true if this value is a symbol. |
| 1301 | * This is an experimental feature. |
| 1302 | */ |
| 1303 | bool IsSymbol() const; |
| 1304 | |
| 1305 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | * Returns true if this value is a function. |
| 1307 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1308 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * Returns true if this value is an array. |
| 1312 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1313 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1315 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | * Returns true if this value is an object. |
| 1317 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1318 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1320 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1321 | * Returns true if this value is boolean. |
| 1322 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1323 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1324 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1325 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | * Returns true if this value is a number. |
| 1327 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1328 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1329 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1330 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | * Returns true if this value is external. |
| 1332 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1333 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1335 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1336 | * Returns true if this value is a 32-bit signed integer. |
| 1337 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1338 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1340 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1341 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1342 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1343 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1344 | |
| 1345 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1346 | * Returns true if this value is a Date. |
| 1347 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1348 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1349 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1350 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1351 | * Returns true if this value is a Boolean object. |
| 1352 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1353 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1354 | |
| 1355 | /** |
| 1356 | * Returns true if this value is a Number object. |
| 1357 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1358 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1359 | |
| 1360 | /** |
| 1361 | * Returns true if this value is a String object. |
| 1362 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1363 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1364 | |
| 1365 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1366 | * Returns true if this value is a Symbol object. |
| 1367 | * This is an experimental feature. |
| 1368 | */ |
| 1369 | bool IsSymbolObject() const; |
| 1370 | |
| 1371 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1372 | * Returns true if this value is a NativeError. |
| 1373 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1374 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1375 | |
| 1376 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1377 | * Returns true if this value is a RegExp. |
| 1378 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1379 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1380 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1381 | |
| 1382 | /** |
| 1383 | * Returns true if this value is an ArrayBuffer. |
| 1384 | * This is an experimental feature. |
| 1385 | */ |
| 1386 | bool IsArrayBuffer() const; |
| 1387 | |
| 1388 | /** |
| 1389 | * Returns true if this value is one of TypedArrays. |
| 1390 | * This is an experimental feature. |
| 1391 | */ |
| 1392 | bool IsTypedArray() const; |
| 1393 | |
| 1394 | /** |
| 1395 | * Returns true if this value is an Uint8Array. |
| 1396 | * This is an experimental feature. |
| 1397 | */ |
| 1398 | bool IsUint8Array() const; |
| 1399 | |
| 1400 | /** |
| 1401 | * Returns true if this value is an Uint8ClampedArray. |
| 1402 | * This is an experimental feature. |
| 1403 | */ |
| 1404 | bool IsUint8ClampedArray() const; |
| 1405 | |
| 1406 | /** |
| 1407 | * Returns true if this value is an Int8Array. |
| 1408 | * This is an experimental feature. |
| 1409 | */ |
| 1410 | bool IsInt8Array() const; |
| 1411 | |
| 1412 | /** |
| 1413 | * Returns true if this value is an Uint16Array. |
| 1414 | * This is an experimental feature. |
| 1415 | */ |
| 1416 | bool IsUint16Array() const; |
| 1417 | |
| 1418 | /** |
| 1419 | * Returns true if this value is an Int16Array. |
| 1420 | * This is an experimental feature. |
| 1421 | */ |
| 1422 | bool IsInt16Array() const; |
| 1423 | |
| 1424 | /** |
| 1425 | * Returns true if this value is an Uint32Array. |
| 1426 | * This is an experimental feature. |
| 1427 | */ |
| 1428 | bool IsUint32Array() const; |
| 1429 | |
| 1430 | /** |
| 1431 | * Returns true if this value is an Int32Array. |
| 1432 | * This is an experimental feature. |
| 1433 | */ |
| 1434 | bool IsInt32Array() const; |
| 1435 | |
| 1436 | /** |
| 1437 | * Returns true if this value is a Float32Array. |
| 1438 | * This is an experimental feature. |
| 1439 | */ |
| 1440 | bool IsFloat32Array() const; |
| 1441 | |
| 1442 | /** |
| 1443 | * Returns true if this value is a Float64Array. |
| 1444 | * This is an experimental feature. |
| 1445 | */ |
| 1446 | bool IsFloat64Array() const; |
| 1447 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1448 | Local<Boolean> ToBoolean() const; |
| 1449 | Local<Number> ToNumber() const; |
| 1450 | Local<String> ToString() const; |
| 1451 | Local<String> ToDetailString() const; |
| 1452 | Local<Object> ToObject() const; |
| 1453 | Local<Integer> ToInteger() const; |
| 1454 | Local<Uint32> ToUint32() const; |
| 1455 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | |
| 1457 | /** |
| 1458 | * Attempts to convert a string to an array index. |
| 1459 | * Returns an empty handle if the conversion fails. |
| 1460 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1461 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1463 | bool BooleanValue() const; |
| 1464 | double NumberValue() const; |
| 1465 | int64_t IntegerValue() const; |
| 1466 | uint32_t Uint32Value() const; |
| 1467 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | |
| 1469 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1470 | bool Equals(Handle<Value> that) const; |
| 1471 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1472 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1473 | template <class T> V8_INLINE(static Value* Cast(T* value)); |
| 1474 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1475 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1476 | V8_INLINE(bool QuickIsUndefined() const); |
| 1477 | V8_INLINE(bool QuickIsNull() const); |
| 1478 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1479 | bool FullIsUndefined() const; |
| 1480 | bool FullIsNull() const; |
| 1481 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1482 | }; |
| 1483 | |
| 1484 | |
| 1485 | /** |
| 1486 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1487 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1488 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1489 | |
| 1490 | |
| 1491 | /** |
| 1492 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1493 | * or false value. |
| 1494 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1495 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1497 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1498 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1499 | }; |
| 1500 | |
| 1501 | |
| 1502 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1503 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1504 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1505 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1507 | enum Encoding { |
| 1508 | UNKNOWN_ENCODING = 0x1, |
| 1509 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1510 | ASCII_ENCODING = 0x4, |
| 1511 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1512 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1513 | /** |
| 1514 | * Returns the number of characters in this string. |
| 1515 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1516 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1517 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1518 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1519 | * Returns the number of bytes in the UTF-8 encoded |
| 1520 | * representation of this string. |
| 1521 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1522 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1523 | |
| 1524 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1525 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1526 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1527 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1528 | |
| 1529 | /** |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 1530 | * Returns whether this string is known to contain only one byte data. |
| 1531 | * Does not read the string. |
| 1532 | * False negatives are possible. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1533 | */ |
| 1534 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1535 | |
| 1536 | /** |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 1537 | * Returns whether this string contain only one byte data. |
| 1538 | * Will read the entire string in some cases. |
| 1539 | */ |
| 1540 | bool ContainsOnlyOneByte() const; |
| 1541 | |
| 1542 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1543 | * Write the contents of the string to an external buffer. |
| 1544 | * If no arguments are given, expects the buffer to be large |
| 1545 | * enough to hold the entire string and NULL terminator. Copies |
| 1546 | * the contents of the string and the NULL terminator into the |
| 1547 | * buffer. |
| 1548 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1549 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1550 | * before the end of the buffer. |
| 1551 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1552 | * Copies up to length characters into the output buffer. |
| 1553 | * Only null-terminates if there is enough space in the buffer. |
| 1554 | * |
| 1555 | * \param buffer The buffer into which the string will be copied. |
| 1556 | * \param start The starting position within the string at which |
| 1557 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1558 | * \param length The number of characters to copy from the string. For |
| 1559 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1560 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1561 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1562 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1563 | * \return The number of characters copied to the buffer excluding the null |
| 1564 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1565 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1566 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1567 | enum WriteOptions { |
| 1568 | NO_OPTIONS = 0, |
| 1569 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1570 | NO_NULL_TERMINATION = 2, |
| 1571 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1572 | }; |
| 1573 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1574 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1575 | int Write(uint16_t* buffer, |
| 1576 | int start = 0, |
| 1577 | int length = -1, |
| 1578 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1579 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1580 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1581 | int start = 0, |
| 1582 | int length = -1, |
| 1583 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1584 | // One byte characters. |
| 1585 | int WriteOneByte(uint8_t* buffer, |
| 1586 | int start = 0, |
| 1587 | int length = -1, |
| 1588 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1589 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1590 | int WriteUtf8(char* buffer, |
| 1591 | int length = -1, |
| 1592 | int* nchars_ref = NULL, |
| 1593 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1594 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1595 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1596 | * A zero length string. |
| 1597 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1598 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1599 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1600 | |
| 1601 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1602 | * Returns true if the string is external |
| 1603 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1604 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1605 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1606 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1607 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1608 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1609 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1610 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1611 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1612 | public: |
| 1613 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1614 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1615 | protected: |
| 1616 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1617 | |
| 1618 | /** |
| 1619 | * Internally V8 will call this Dispose method when the external string |
| 1620 | * resource is no longer needed. The default implementation will use the |
| 1621 | * delete operator. This method can be overridden in subclasses to |
| 1622 | * control how allocated external string resources are disposed. |
| 1623 | */ |
| 1624 | virtual void Dispose() { delete this; } |
| 1625 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1626 | private: |
| 1627 | // Disallow copying and assigning. |
| 1628 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1629 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1630 | |
| 1631 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1632 | }; |
| 1633 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1634 | /** |
| 1635 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1636 | * buffer that resides outside V8's heap. Implement an |
| 1637 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1638 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1639 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1640 | class V8EXPORT ExternalStringResource |
| 1641 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1642 | public: |
| 1643 | /** |
| 1644 | * Override the destructor to manage the life cycle of the underlying |
| 1645 | * buffer. |
| 1646 | */ |
| 1647 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1648 | |
| 1649 | /** |
| 1650 | * The string data from the underlying buffer. |
| 1651 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1652 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1653 | |
| 1654 | /** |
| 1655 | * The length of the string. That is, the number of two-byte characters. |
| 1656 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1658 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1659 | protected: |
| 1660 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | }; |
| 1662 | |
| 1663 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1664 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1665 | * string buffer that resides outside V8's heap. Implement an |
| 1666 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1667 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1668 | * 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] | 1669 | * UTF-8, which would require special treatment internally in the |
| 1670 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1671 | * 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] | 1672 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1673 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1674 | class V8EXPORT ExternalAsciiStringResource |
| 1675 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1676 | public: |
| 1677 | /** |
| 1678 | * Override the destructor to manage the life cycle of the underlying |
| 1679 | * buffer. |
| 1680 | */ |
| 1681 | virtual ~ExternalAsciiStringResource() {} |
| 1682 | /** The string data from the underlying buffer.*/ |
| 1683 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1684 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1685 | virtual size_t length() const = 0; |
| 1686 | protected: |
| 1687 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | }; |
| 1689 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1690 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1691 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1693 | * If the string is an external string, return the ExternalStringResourceBase |
| 1694 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1695 | * string is returned in encoding_out. |
| 1696 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1697 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1698 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1699 | |
| 1700 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1701 | * Get the ExternalStringResource for an external string. Returns |
| 1702 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1703 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1704 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | |
| 1706 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1707 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1708 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1709 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1710 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1711 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1712 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1713 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1714 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1715 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1716 | * 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] | 1717 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1718 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1719 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1720 | 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] | 1721 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1722 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1723 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1724 | 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] | 1725 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1726 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1727 | /** |
| 1728 | * Creates an internalized string (historically called a "symbol", |
| 1729 | * 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] | 1730 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1731 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1732 | |
| 1733 | enum NewStringType { |
| 1734 | kNormalString, kInternalizedString, kUndetectableString |
| 1735 | }; |
| 1736 | |
| 1737 | /** Allocates a new string from UTF-8 data.*/ |
| 1738 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1739 | const char* data, |
| 1740 | NewStringType type = kNormalString, |
| 1741 | int length = -1); |
| 1742 | |
| 1743 | /** Allocates a new string from Latin-1 data.*/ |
| 1744 | static Local<String> NewFromOneByte( |
| 1745 | Isolate* isolate, |
| 1746 | const uint8_t* data, |
| 1747 | NewStringType type = kNormalString, |
| 1748 | int length = -1); |
| 1749 | |
| 1750 | /** Allocates a new string from UTF-16 data.*/ |
| 1751 | static Local<String> NewFromTwoByte( |
| 1752 | Isolate* isolate, |
| 1753 | const uint16_t* data, |
| 1754 | NewStringType type = kNormalString, |
| 1755 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1756 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1757 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1758 | * Creates a new string by concatenating the left and the right strings |
| 1759 | * passed in as parameters. |
| 1760 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1761 | 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] | 1762 | |
| 1763 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1764 | * 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] | 1765 | * 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] | 1766 | * resource will be disposed by calling its Dispose method. The caller of |
| 1767 | * this function should not otherwise delete or modify the resource. Neither |
| 1768 | * should the underlying buffer be deallocated or modified except through the |
| 1769 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1770 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1771 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1772 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1773 | /** |
| 1774 | * Associate an external string resource with this string by transforming it |
| 1775 | * in place so that existing references to this string in the JavaScript heap |
| 1776 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1777 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1778 | * 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] | 1779 | * The string is not modified if the operation fails. See NewExternal for |
| 1780 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1781 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1782 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1784 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1785 | * 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] | 1786 | * 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] | 1787 | * resource will be disposed by calling its Dispose method. The caller of |
| 1788 | * this function should not otherwise delete or modify the resource. Neither |
| 1789 | * should the underlying buffer be deallocated or modified except through the |
| 1790 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1791 | */ |
| 1792 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1793 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1794 | /** |
| 1795 | * Associate an external string resource with this string by transforming it |
| 1796 | * in place so that existing references to this string in the JavaScript heap |
| 1797 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1798 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1799 | * 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] | 1800 | * The string is not modified if the operation fails. See NewExternal for |
| 1801 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1802 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1803 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1805 | /** |
| 1806 | * Returns true if this string can be made external. |
| 1807 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1808 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1809 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1810 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1811 | /** 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] | 1812 | V8_INLINE( |
| 1813 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1814 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1815 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1816 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1817 | V8_INLINE(static Local<String> NewUndetectable( |
| 1818 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | |
| 1820 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1821 | * 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] | 1822 | * 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] | 1823 | * (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] | 1824 | * then the length() method returns 0 and the * operator returns |
| 1825 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1826 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1827 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1828 | public: |
| 1829 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1830 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1831 | char* operator*() { return str_; } |
| 1832 | const char* operator*() const { return str_; } |
| 1833 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1834 | private: |
| 1835 | char* str_; |
| 1836 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1837 | |
| 1838 | // Disallow copying and assigning. |
| 1839 | Utf8Value(const Utf8Value&); |
| 1840 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1841 | }; |
| 1842 | |
| 1843 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1844 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1846 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1847 | * method of the object) then the length() method returns 0 and the * operator |
| 1848 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1850 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1851 | public: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1852 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1853 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1854 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1855 | char* operator*() { return str_; } |
| 1856 | const char* operator*() const { return str_; } |
| 1857 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1858 | private: |
| 1859 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1860 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1861 | |
| 1862 | // Disallow copying and assigning. |
| 1863 | AsciiValue(const AsciiValue&); |
| 1864 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1865 | }; |
| 1866 | |
| 1867 | /** |
| 1868 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1869 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1870 | * method of the object) then the length() method returns 0 and the * operator |
| 1871 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1872 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1873 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1874 | public: |
| 1875 | explicit Value(Handle<v8::Value> obj); |
| 1876 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1877 | uint16_t* operator*() { return str_; } |
| 1878 | const uint16_t* operator*() const { return str_; } |
| 1879 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | private: |
| 1881 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1882 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1883 | |
| 1884 | // Disallow copying and assigning. |
| 1885 | Value(const Value&); |
| 1886 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1888 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1889 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1890 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1891 | Encoding encoding) const; |
| 1892 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1893 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | }; |
| 1895 | |
| 1896 | |
| 1897 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1898 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1899 | * |
| 1900 | * This is an experimental feature. Use at your own risk. |
| 1901 | */ |
| 1902 | class V8EXPORT Symbol : public Primitive { |
| 1903 | public: |
| 1904 | // Returns the print name string of the symbol, or undefined if none. |
| 1905 | Local<Value> Name() const; |
| 1906 | |
| 1907 | // Create a symbol without a print name. |
| 1908 | static Local<Symbol> New(Isolate* isolate); |
| 1909 | |
| 1910 | // Create a symbol with a print name. |
| 1911 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1912 | |
| 1913 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1914 | private: |
| 1915 | Symbol(); |
| 1916 | static void CheckCast(v8::Value* obj); |
| 1917 | }; |
| 1918 | |
| 1919 | |
| 1920 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1921 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1922 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1923 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1925 | double Value() const; |
| 1926 | static Local<Number> New(double value); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1927 | static Local<Number> New(Isolate* isolate, double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1928 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1930 | Number(); |
| 1931 | static void CheckCast(v8::Value* obj); |
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 signed 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 Integer : public Number { |
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 | static Local<Integer> New(int32_t value); |
| 1941 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1942 | static Local<Integer> New(int32_t value, Isolate*); |
| 1943 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1944 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1945 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1946 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1947 | Integer(); |
| 1948 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1949 | }; |
| 1950 | |
| 1951 | |
| 1952 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1953 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1954 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1955 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1956 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1957 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1958 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1959 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1960 | }; |
| 1961 | |
| 1962 | |
| 1963 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1964 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1965 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1966 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1967 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1968 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1970 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1971 | }; |
| 1972 | |
| 1973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1974 | enum PropertyAttribute { |
| 1975 | None = 0, |
| 1976 | ReadOnly = 1 << 0, |
| 1977 | DontEnum = 1 << 1, |
| 1978 | DontDelete = 1 << 2 |
| 1979 | }; |
| 1980 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1981 | enum ExternalArrayType { |
| 1982 | kExternalByteArray = 1, |
| 1983 | kExternalUnsignedByteArray, |
| 1984 | kExternalShortArray, |
| 1985 | kExternalUnsignedShortArray, |
| 1986 | kExternalIntArray, |
| 1987 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1988 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1989 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1990 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1991 | }; |
| 1992 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1993 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1994 | * Accessor[Getter|Setter] are used as callback functions when |
| 1995 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1996 | * method SetAccessor. |
| 1997 | */ |
| 1998 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1999 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2000 | typedef void (*AccessorGetterCallback)( |
| 2001 | Local<String> property, |
| 2002 | const PropertyCallbackInfo<Value>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2003 | |
| 2004 | |
| 2005 | typedef void (*AccessorSetter)(Local<String> property, |
| 2006 | Local<Value> value, |
| 2007 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2008 | typedef void (*AccessorSetterCallback)( |
| 2009 | Local<String> property, |
| 2010 | Local<Value> value, |
| 2011 | const PropertyCallbackInfo<void>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2012 | |
| 2013 | |
| 2014 | /** |
| 2015 | * Access control specifications. |
| 2016 | * |
| 2017 | * Some accessors should be accessible across contexts. These |
| 2018 | * accessors have an explicit access control parameter which specifies |
| 2019 | * the kind of cross-context access that should be allowed. |
| 2020 | * |
| 2021 | * Additionally, for security, accessors can prohibit overwriting by |
| 2022 | * accessors defined in JavaScript. For objects that have such |
| 2023 | * accessors either locally or in their prototype chain it is not |
| 2024 | * possible to overwrite the accessor by using __defineGetter__ or |
| 2025 | * __defineSetter__ from JavaScript code. |
| 2026 | */ |
| 2027 | enum AccessControl { |
| 2028 | DEFAULT = 0, |
| 2029 | ALL_CAN_READ = 1, |
| 2030 | ALL_CAN_WRITE = 1 << 1, |
| 2031 | PROHIBITS_OVERWRITING = 1 << 2 |
| 2032 | }; |
| 2033 | |
| 2034 | |
| 2035 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2036 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2037 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2038 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2039 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2040 | bool Set(Handle<Value> key, |
| 2041 | Handle<Value> value, |
| 2042 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2043 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2044 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2045 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2046 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2047 | // overriding accessors or read-only properties. |
| 2048 | // |
| 2049 | // Note that if the object has an interceptor the property will be set |
| 2050 | // locally, but since the interceptor takes precedence the local property |
| 2051 | // will only be returned if the interceptor doesn't return a value. |
| 2052 | // |
| 2053 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2054 | bool ForceSet(Handle<Value> key, |
| 2055 | Handle<Value> value, |
| 2056 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2057 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2058 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2059 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2060 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2061 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2062 | /** |
| 2063 | * Gets the property attributes of a property which can be None or |
| 2064 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 2065 | * None when the property doesn't exist. |
| 2066 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2067 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2068 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2069 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2070 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2071 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2072 | |
| 2073 | // Delete a property on this object bypassing interceptors and |
| 2074 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2075 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2076 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2077 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2078 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2079 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2080 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2081 | // TODO(dcarney): deprecate |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2082 | bool SetAccessor(Handle<String> name, |
| 2083 | AccessorGetter getter, |
| 2084 | AccessorSetter setter = 0, |
| 2085 | Handle<Value> data = Handle<Value>(), |
| 2086 | AccessControl settings = DEFAULT, |
| 2087 | PropertyAttribute attribute = None); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2088 | bool SetAccessor(Handle<String> name, |
| 2089 | AccessorGetterCallback getter, |
| 2090 | AccessorSetterCallback setter = 0, |
| 2091 | Handle<Value> data = Handle<Value>(), |
| 2092 | AccessControl settings = DEFAULT, |
| 2093 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2094 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2095 | // This function is not yet stable and should not be used at this time. |
| 2096 | bool SetAccessor(Handle<String> name, |
| 2097 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2098 | AccessControl settings = DEFAULT, |
| 2099 | PropertyAttribute attribute = None); |
| 2100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2101 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2102 | * Returns an array containing the names of the enumerable properties |
| 2103 | * of this object, including properties from prototype objects. The |
| 2104 | * array returned by this method contains the same values as would |
| 2105 | * be enumerated by a for-in statement over this object. |
| 2106 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2107 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2108 | |
| 2109 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2110 | * This function has the same functionality as GetPropertyNames but |
| 2111 | * the returned array doesn't contain the names of properties from |
| 2112 | * prototype objects. |
| 2113 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2114 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2115 | |
| 2116 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2117 | * Get the prototype object. This does not skip objects marked to |
| 2118 | * be skipped by __proto__ and it does not consult the security |
| 2119 | * handler. |
| 2120 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2121 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2122 | |
| 2123 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2124 | * Set the prototype object. This does not skip objects marked to |
| 2125 | * be skipped by __proto__ and it does not consult the security |
| 2126 | * handler. |
| 2127 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2128 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2129 | |
| 2130 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2131 | * Finds an instance of the given function template in the prototype |
| 2132 | * chain. |
| 2133 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2134 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2135 | |
| 2136 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2137 | * Call builtin Object.prototype.toString on this object. |
| 2138 | * This is different from Value::ToString() that may call |
| 2139 | * user-defined toString function. This one does not. |
| 2140 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2141 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2142 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2143 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2144 | * Returns the function invoked as a constructor for this object. |
| 2145 | * May be the null value. |
| 2146 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2147 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2148 | |
| 2149 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2150 | * Returns the name of the function invoked as a constructor for this object. |
| 2151 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2152 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2153 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2154 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2155 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2156 | |
| 2157 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2158 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2159 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2160 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2161 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2162 | |
| 2163 | /** |
| 2164 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2165 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2166 | * leads to undefined behavior. |
| 2167 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2168 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2169 | |
| 2170 | /** |
| 2171 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2172 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2173 | * leads to undefined behavior. |
| 2174 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2175 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2176 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2177 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2178 | bool HasOwnProperty(Handle<String> key); |
| 2179 | bool HasRealNamedProperty(Handle<String> key); |
| 2180 | bool HasRealIndexedProperty(uint32_t index); |
| 2181 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2182 | |
| 2183 | /** |
| 2184 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2185 | * This means interceptors in the prototype chain are not called. |
| 2186 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2187 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2188 | |
| 2189 | /** |
| 2190 | * If result.IsEmpty() no real property was located on the object or |
| 2191 | * in the prototype chain. |
| 2192 | * This means interceptors in the prototype chain are not called. |
| 2193 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2194 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2195 | |
| 2196 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2197 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2198 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2199 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2200 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2201 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2202 | /** |
| 2203 | * Turns on access check on the object if the object is an instance of |
| 2204 | * a template that has access check callbacks. If an object has no |
| 2205 | * access check info, the object cannot be accessed by anyone. |
| 2206 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2207 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2208 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2209 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2210 | * Returns the identity hash for this object. The current implementation |
| 2211 | * 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] | 2212 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2213 | * 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] | 2214 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2215 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2216 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2217 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2218 | /** |
| 2219 | * Access hidden properties on JavaScript objects. These properties are |
| 2220 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2221 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2222 | * identity hash) are prefixed with "v8::". |
| 2223 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2224 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2225 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2226 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2227 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2228 | /** |
| 2229 | * Returns true if this is an instance of an api function (one |
| 2230 | * created from a function created from a function template) and has |
| 2231 | * been modified since it was created. Note that this method is |
| 2232 | * conservative and may return true for objects that haven't actually |
| 2233 | * been modified. |
| 2234 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2235 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2236 | |
| 2237 | /** |
| 2238 | * Clone this object with a fast but shallow copy. Values will point |
| 2239 | * to the same values as the original object. |
| 2240 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2241 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2242 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2243 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2244 | * Returns the context in which the object was created. |
| 2245 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2246 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2247 | |
| 2248 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2249 | * Set the backing store of the indexed properties to be managed by the |
| 2250 | * embedding layer. Access to the indexed properties will follow the rules |
| 2251 | * spelled out in CanvasPixelArray. |
| 2252 | * Note: The embedding program still owns the data and needs to ensure that |
| 2253 | * the backing store is preserved while V8 has a reference. |
| 2254 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2255 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2256 | bool HasIndexedPropertiesInPixelData(); |
| 2257 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2258 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2259 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2260 | /** |
| 2261 | * Set the backing store of the indexed properties to be managed by the |
| 2262 | * embedding layer. Access to the indexed properties will follow the rules |
| 2263 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2264 | * Note: The embedding program still owns the data and needs to ensure that |
| 2265 | * the backing store is preserved while V8 has a reference. |
| 2266 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2267 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2268 | ExternalArrayType array_type, |
| 2269 | int number_of_elements); |
| 2270 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2271 | void* GetIndexedPropertiesExternalArrayData(); |
| 2272 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2273 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2274 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2275 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2276 | * Checks whether a callback is set by the |
| 2277 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2278 | * When an Object is callable this method returns true. |
| 2279 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2280 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2281 | |
| 2282 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2283 | * 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] | 2284 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2285 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2286 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2287 | int argc, |
| 2288 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2289 | |
| 2290 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2291 | * 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] | 2292 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2293 | * Note: This method behaves like the Function::NewInstance method. |
| 2294 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2295 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2296 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2297 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2298 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2299 | |
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 | Object(); |
| 2302 | static void CheckCast(Value* obj); |
| 2303 | Local<Value> SlowGetInternalField(int index); |
| 2304 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2305 | }; |
| 2306 | |
| 2307 | |
| 2308 | /** |
| 2309 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2310 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2311 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2312 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2313 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2314 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2315 | /** |
| 2316 | * Clones an element at index |index|. Returns an empty |
| 2317 | * handle if cloning fails (for any reason). |
| 2318 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2319 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2320 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2321 | /** |
| 2322 | * Creates a JavaScript array with the given length. If the length |
| 2323 | * is negative the returned array will have length 0. |
| 2324 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2325 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2326 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2327 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2328 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2329 | Array(); |
| 2330 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2331 | }; |
| 2332 | |
| 2333 | |
| 2334 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2335 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2337 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2338 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2339 | Local<Object> NewInstance() const; |
| 2340 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2341 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2342 | void SetName(Handle<String> name); |
| 2343 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2344 | |
| 2345 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2346 | * Name inferred from variable or property assignment of this function. |
| 2347 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2348 | * in an OO style, where many functions are anonymous but are assigned |
| 2349 | * to object properties. |
| 2350 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2351 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2352 | |
| 2353 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2354 | * Returns zero based line number of function body and |
| 2355 | * kLineOffsetNotFound if no information available. |
| 2356 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2357 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2358 | /** |
| 2359 | * Returns zero based column number of function body and |
| 2360 | * kLineOffsetNotFound if no information available. |
| 2361 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2362 | int GetScriptColumnNumber() const; |
| 2363 | Handle<Value> GetScriptId() const; |
| 2364 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2365 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2366 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2368 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2369 | Function(); |
| 2370 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2371 | }; |
| 2372 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2373 | /** |
| 2374 | * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 2375 | * populates an instance of this class with a pointer to data and byte length. |
| 2376 | * |
| 2377 | * |ArrayBufferContents| is the owner of its data. When an instance of |
| 2378 | * this class is destructed, the |Data| is freed. |
| 2379 | * |
| 2380 | * This API is experimental and may change significantly. |
| 2381 | */ |
| 2382 | class V8EXPORT ArrayBufferContents { |
| 2383 | public: |
| 2384 | ArrayBufferContents() : data_(NULL), byte_length_(0) {} |
| 2385 | ~ArrayBufferContents(); |
| 2386 | |
| 2387 | void* Data() const { return data_; } |
| 2388 | size_t ByteLength() const { return byte_length_; } |
| 2389 | |
| 2390 | private: |
| 2391 | void* data_; |
| 2392 | size_t byte_length_; |
| 2393 | |
| 2394 | friend class ArrayBuffer; |
| 2395 | }; |
| 2396 | |
| 2397 | #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 2398 | #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
| 2399 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2400 | |
| 2401 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2402 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2403 | * This API is experimental and may change significantly. |
| 2404 | */ |
| 2405 | class V8EXPORT ArrayBuffer : public Object { |
| 2406 | public: |
| 2407 | /** |
| 2408 | * Data length in bytes. |
| 2409 | */ |
| 2410 | size_t ByteLength() const; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2411 | |
| 2412 | /** |
| 2413 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2414 | * Allocated memory will be owned by a created ArrayBuffer and |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2415 | * will be deallocated when it is garbage-collected, |
| 2416 | * unless the object is externalized. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2417 | */ |
| 2418 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2419 | |
| 2420 | /** |
| 2421 | * Create a new ArrayBuffer over an existing memory block. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2422 | * The created array buffer is immediately in externalized state. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2423 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2424 | * is garbage-collected. |
| 2425 | */ |
| 2426 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2427 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2428 | /** |
| 2429 | * Returns true if ArrayBuffer is extrenalized, that is, does not |
| 2430 | * own its memory block. |
| 2431 | */ |
| 2432 | bool IsExternal() const; |
| 2433 | |
| 2434 | /** |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 2435 | * Neuters this ArrayBuffer and all its views (typed arrays). |
| 2436 | * Neutering sets the byte length of the buffer and all typed arrays to zero, |
| 2437 | * preventing JavaScript from ever accessing underlying backing store. |
| 2438 | * ArrayBuffer should have been externalized. |
| 2439 | */ |
| 2440 | void Neuter(); |
| 2441 | |
| 2442 | /** |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2443 | * Pass the ownership of this ArrayBuffer's backing store to |
| 2444 | * a given ArrayBufferContents. |
| 2445 | */ |
| 2446 | void Externalize(ArrayBufferContents* contents); |
| 2447 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2448 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2449 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2450 | |
| 2451 | static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
| 2452 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2453 | private: |
| 2454 | ArrayBuffer(); |
| 2455 | static void CheckCast(Value* obj); |
| 2456 | }; |
| 2457 | |
| 2458 | |
| 2459 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2460 | * A base class for an instance of TypedArray series of constructors |
| 2461 | * (ES6 draft 15.13.6). |
| 2462 | * This API is experimental and may change significantly. |
| 2463 | */ |
| 2464 | class V8EXPORT TypedArray : public Object { |
| 2465 | public: |
| 2466 | /** |
| 2467 | * Returns underlying ArrayBuffer. |
| 2468 | */ |
| 2469 | Local<ArrayBuffer> Buffer(); |
| 2470 | /** |
| 2471 | * Byte offset in |Buffer| |
| 2472 | */ |
| 2473 | size_t ByteOffset(); |
| 2474 | /** |
| 2475 | * Numbe of elements in this typed array. |
| 2476 | */ |
| 2477 | size_t Length(); |
| 2478 | /** |
| 2479 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2480 | */ |
| 2481 | size_t ByteLength(); |
| 2482 | /** |
| 2483 | * Base address of typed array. |
| 2484 | */ |
| 2485 | void* BaseAddress(); |
| 2486 | |
| 2487 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2488 | |
| 2489 | private: |
| 2490 | TypedArray(); |
| 2491 | static void CheckCast(Value* obj); |
| 2492 | }; |
| 2493 | |
| 2494 | |
| 2495 | /** |
| 2496 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2497 | * This API is experimental and may change significantly. |
| 2498 | */ |
| 2499 | class V8EXPORT Uint8Array : public TypedArray { |
| 2500 | public: |
| 2501 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2502 | size_t byte_offset, size_t length); |
| 2503 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2504 | |
| 2505 | private: |
| 2506 | Uint8Array(); |
| 2507 | static void CheckCast(Value* obj); |
| 2508 | }; |
| 2509 | |
| 2510 | |
| 2511 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2512 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2513 | * This API is experimental and may change significantly. |
| 2514 | */ |
| 2515 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2516 | public: |
| 2517 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2518 | size_t byte_offset, size_t length); |
| 2519 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2520 | |
| 2521 | private: |
| 2522 | Uint8ClampedArray(); |
| 2523 | static void CheckCast(Value* obj); |
| 2524 | }; |
| 2525 | |
| 2526 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2527 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2528 | * This API is experimental and may change significantly. |
| 2529 | */ |
| 2530 | class V8EXPORT Int8Array : public TypedArray { |
| 2531 | public: |
| 2532 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2533 | size_t byte_offset, size_t length); |
| 2534 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2535 | |
| 2536 | private: |
| 2537 | Int8Array(); |
| 2538 | static void CheckCast(Value* obj); |
| 2539 | }; |
| 2540 | |
| 2541 | |
| 2542 | /** |
| 2543 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2544 | * This API is experimental and may change significantly. |
| 2545 | */ |
| 2546 | class V8EXPORT Uint16Array : public TypedArray { |
| 2547 | public: |
| 2548 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2549 | size_t byte_offset, size_t length); |
| 2550 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2551 | |
| 2552 | private: |
| 2553 | Uint16Array(); |
| 2554 | static void CheckCast(Value* obj); |
| 2555 | }; |
| 2556 | |
| 2557 | |
| 2558 | /** |
| 2559 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2560 | * This API is experimental and may change significantly. |
| 2561 | */ |
| 2562 | class V8EXPORT Int16Array : public TypedArray { |
| 2563 | public: |
| 2564 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2565 | size_t byte_offset, size_t length); |
| 2566 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2567 | |
| 2568 | private: |
| 2569 | Int16Array(); |
| 2570 | static void CheckCast(Value* obj); |
| 2571 | }; |
| 2572 | |
| 2573 | |
| 2574 | /** |
| 2575 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2576 | * This API is experimental and may change significantly. |
| 2577 | */ |
| 2578 | class V8EXPORT Uint32Array : public TypedArray { |
| 2579 | public: |
| 2580 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2581 | size_t byte_offset, size_t length); |
| 2582 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2583 | |
| 2584 | private: |
| 2585 | Uint32Array(); |
| 2586 | static void CheckCast(Value* obj); |
| 2587 | }; |
| 2588 | |
| 2589 | |
| 2590 | /** |
| 2591 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2592 | * This API is experimental and may change significantly. |
| 2593 | */ |
| 2594 | class V8EXPORT Int32Array : public TypedArray { |
| 2595 | public: |
| 2596 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2597 | size_t byte_offset, size_t length); |
| 2598 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2599 | |
| 2600 | private: |
| 2601 | Int32Array(); |
| 2602 | static void CheckCast(Value* obj); |
| 2603 | }; |
| 2604 | |
| 2605 | |
| 2606 | /** |
| 2607 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2608 | * This API is experimental and may change significantly. |
| 2609 | */ |
| 2610 | class V8EXPORT Float32Array : public TypedArray { |
| 2611 | public: |
| 2612 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2613 | size_t byte_offset, size_t length); |
| 2614 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2615 | |
| 2616 | private: |
| 2617 | Float32Array(); |
| 2618 | static void CheckCast(Value* obj); |
| 2619 | }; |
| 2620 | |
| 2621 | |
| 2622 | /** |
| 2623 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2624 | * This API is experimental and may change significantly. |
| 2625 | */ |
| 2626 | class V8EXPORT Float64Array : public TypedArray { |
| 2627 | public: |
| 2628 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2629 | size_t byte_offset, size_t length); |
| 2630 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2631 | |
| 2632 | private: |
| 2633 | Float64Array(); |
| 2634 | static void CheckCast(Value* obj); |
| 2635 | }; |
| 2636 | |
| 2637 | |
| 2638 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2639 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2640 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2641 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2642 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2643 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2644 | |
| 2645 | /** |
| 2646 | * A specialization of Value::NumberValue that is more efficient |
| 2647 | * because we know the structure of this object. |
| 2648 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2649 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2650 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2651 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2652 | |
| 2653 | /** |
| 2654 | * Notification that the embedder has changed the time zone, |
| 2655 | * daylight savings time, or other date / time configuration |
| 2656 | * parameters. V8 keeps a cache of various values used for |
| 2657 | * date / time computation. This notification will reset |
| 2658 | * those cached values for the current context so that date / |
| 2659 | * time configuration changes would be reflected in the Date |
| 2660 | * object. |
| 2661 | * |
| 2662 | * This API should not be called more than needed as it will |
| 2663 | * negatively impact the performance of date operations. |
| 2664 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2665 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2666 | |
| 2667 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2668 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2669 | }; |
| 2670 | |
| 2671 | |
| 2672 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2673 | * A Number object (ECMA-262, 4.3.21). |
| 2674 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2675 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2676 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2677 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2678 | |
| 2679 | /** |
| 2680 | * Returns the Number held by the object. |
| 2681 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2682 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2683 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2684 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2685 | |
| 2686 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2687 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2688 | }; |
| 2689 | |
| 2690 | |
| 2691 | /** |
| 2692 | * A Boolean object (ECMA-262, 4.3.15). |
| 2693 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2694 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2695 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2696 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2697 | |
| 2698 | /** |
| 2699 | * Returns the Boolean held by the object. |
| 2700 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2701 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2702 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2703 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2704 | |
| 2705 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2706 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2707 | }; |
| 2708 | |
| 2709 | |
| 2710 | /** |
| 2711 | * A String object (ECMA-262, 4.3.18). |
| 2712 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2713 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2714 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2715 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2716 | |
| 2717 | /** |
| 2718 | * Returns the String held by the object. |
| 2719 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2720 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2721 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2722 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2723 | |
| 2724 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2725 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2726 | }; |
| 2727 | |
| 2728 | |
| 2729 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2730 | * A Symbol object (ECMA-262 edition 6). |
| 2731 | * |
| 2732 | * This is an experimental feature. Use at your own risk. |
| 2733 | */ |
| 2734 | class V8EXPORT SymbolObject : public Object { |
| 2735 | public: |
| 2736 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2737 | |
| 2738 | /** |
| 2739 | * Returns the Symbol held by the object. |
| 2740 | */ |
| 2741 | Local<Symbol> SymbolValue() const; |
| 2742 | |
| 2743 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2744 | |
| 2745 | private: |
| 2746 | static void CheckCast(v8::Value* obj); |
| 2747 | }; |
| 2748 | |
| 2749 | |
| 2750 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2751 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2752 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2753 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2754 | public: |
| 2755 | /** |
| 2756 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2757 | * of flags. |
| 2758 | */ |
| 2759 | enum Flags { |
| 2760 | kNone = 0, |
| 2761 | kGlobal = 1, |
| 2762 | kIgnoreCase = 2, |
| 2763 | kMultiline = 4 |
| 2764 | }; |
| 2765 | |
| 2766 | /** |
| 2767 | * Creates a regular expression from the given pattern string and |
| 2768 | * the flags bit field. May throw a JavaScript exception as |
| 2769 | * described in ECMA-262, 15.10.4.1. |
| 2770 | * |
| 2771 | * For example, |
| 2772 | * RegExp::New(v8::String::New("foo"), |
| 2773 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2774 | * is equivalent to evaluating "/foo/gm". |
| 2775 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2776 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2777 | |
| 2778 | /** |
| 2779 | * Returns the value of the source property: a string representing |
| 2780 | * the regular expression. |
| 2781 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2782 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2783 | |
| 2784 | /** |
| 2785 | * Returns the flags bit field. |
| 2786 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2787 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2788 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2789 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2790 | |
| 2791 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2792 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2793 | }; |
| 2794 | |
| 2795 | |
| 2796 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2797 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2798 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2799 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2800 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2801 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2802 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2803 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2804 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2805 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2806 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2807 | }; |
| 2808 | |
| 2809 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2810 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2811 | |
| 2812 | |
| 2813 | /** |
| 2814 | * The superclass of object and function templates. |
| 2815 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2816 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2817 | public: |
| 2818 | /** Adds a property to each instance created by this template.*/ |
| 2819 | void Set(Handle<String> name, Handle<Data> value, |
| 2820 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2821 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2822 | private: |
| 2823 | Template(); |
| 2824 | |
| 2825 | friend class ObjectTemplate; |
| 2826 | friend class FunctionTemplate; |
| 2827 | }; |
| 2828 | |
| 2829 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2830 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2831 | class ReturnValue { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2832 | public: |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2833 | template <class S> V8_INLINE(ReturnValue(const ReturnValue<S>& that)) |
| 2834 | : value_(that.value_) { |
| 2835 | TYPE_CHECK(T, S); |
| 2836 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2837 | // Handle setters |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2838 | template <typename S> V8_INLINE(void Set(const Persistent<S>& handle)); |
| 2839 | template <typename S> V8_INLINE(void Set(const Handle<S> handle)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2840 | // Fast primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2841 | V8_INLINE(void Set(bool value)); |
| 2842 | V8_INLINE(void Set(double i)); |
| 2843 | V8_INLINE(void Set(int32_t i)); |
| 2844 | V8_INLINE(void Set(uint32_t i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2845 | // Fast JS primitive setters |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2846 | V8_INLINE(void SetNull()); |
| 2847 | V8_INLINE(void SetUndefined()); |
| 2848 | // Convenience getter for Isolate |
| 2849 | V8_INLINE(Isolate* GetIsolate()); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2850 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2851 | private: |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2852 | template<class F> friend class ReturnValue; |
| 2853 | template<class F> friend class FunctionCallbackInfo; |
| 2854 | template<class F> friend class PropertyCallbackInfo; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 2855 | V8_INLINE(internal::Object* GetDefaultValue()); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2856 | V8_INLINE(explicit ReturnValue(internal::Object** slot)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2857 | internal::Object** value_; |
| 2858 | }; |
| 2859 | |
| 2860 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2861 | /** |
| 2862 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2863 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2864 | * including the receiver, the number and values of arguments, and |
| 2865 | * the holder of the function. |
| 2866 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2867 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2868 | class FunctionCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2869 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2870 | V8_INLINE(int Length() const); |
| 2871 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2872 | V8_INLINE(Local<Function> Callee() const); |
| 2873 | V8_INLINE(Local<Object> This() const); |
| 2874 | V8_INLINE(Local<Object> Holder() const); |
| 2875 | V8_INLINE(bool IsConstructCall() const); |
| 2876 | V8_INLINE(Local<Value> Data() const); |
| 2877 | V8_INLINE(Isolate* GetIsolate() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2878 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2879 | // This shouldn't be public, but the arm compiler needs it. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 2880 | static const int kArgsLength = 6; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2881 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2882 | protected: |
| 2883 | friend class internal::FunctionCallbackArguments; |
| 2884 | friend class internal::CustomArguments<FunctionCallbackInfo>; |
| 2885 | static const int kReturnValueIndex = 0; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 2886 | static const int kReturnValueDefaultValueIndex = -1; |
| 2887 | static const int kIsolateIndex = -2; |
| 2888 | static const int kDataIndex = -3; |
| 2889 | static const int kCalleeIndex = -4; |
| 2890 | static const int kHolderIndex = -5; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2891 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2892 | V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2893 | internal::Object** values, |
| 2894 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2895 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2896 | internal::Object** implicit_args_; |
| 2897 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2898 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2899 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | }; |
| 2901 | |
| 2902 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2903 | class V8EXPORT Arguments : public FunctionCallbackInfo<Value> { |
| 2904 | private: |
| 2905 | friend class internal::FunctionCallbackArguments; |
| 2906 | V8_INLINE(Arguments(internal::Object** implicit_args, |
| 2907 | internal::Object** values, |
| 2908 | int length, |
| 2909 | bool is_construct_call)); |
| 2910 | }; |
| 2911 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2912 | /** |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2913 | * The information passed to a property callback about the context |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2914 | * of the property access. |
| 2915 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2916 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2917 | class PropertyCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2918 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2919 | V8_INLINE(Isolate* GetIsolate() const); |
| 2920 | V8_INLINE(Local<Value> Data() const); |
| 2921 | V8_INLINE(Local<Object> This() const); |
| 2922 | V8_INLINE(Local<Object> Holder() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2923 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2924 | // This shouldn't be public, but the arm compiler needs it. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 2925 | static const int kArgsLength = 6; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2926 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2927 | protected: |
| 2928 | friend class MacroAssembler; |
| 2929 | friend class internal::PropertyCallbackArguments; |
| 2930 | friend class internal::CustomArguments<PropertyCallbackInfo>; |
| 2931 | static const int kThisIndex = 0; |
| 2932 | static const int kHolderIndex = -1; |
| 2933 | static const int kDataIndex = -2; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2934 | static const int kReturnValueIndex = -3; |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 2935 | static const int kReturnValueDefaultValueIndex = -4; |
| 2936 | static const int kIsolateIndex = -5; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2937 | |
| 2938 | V8_INLINE(PropertyCallbackInfo(internal::Object** args)) |
| 2939 | : args_(args) { } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2940 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2941 | }; |
| 2942 | |
| 2943 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2944 | class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> { |
| 2945 | private: |
| 2946 | friend class internal::PropertyCallbackArguments; |
| 2947 | V8_INLINE(AccessorInfo(internal::Object** args)) |
| 2948 | : PropertyCallbackInfo<Value>(args) { } |
| 2949 | }; |
| 2950 | |
| 2951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2952 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2953 | typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2954 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2956 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2957 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2958 | */ |
| 2959 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2960 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2961 | typedef void (*NamedPropertyGetterCallback)( |
| 2962 | Local<String> property, |
| 2963 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | |
| 2965 | |
| 2966 | /** |
| 2967 | * Returns the value if the setter intercepts the request. |
| 2968 | * Otherwise, returns an empty handle. |
| 2969 | */ |
| 2970 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2971 | Local<Value> value, |
| 2972 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2973 | typedef void (*NamedPropertySetterCallback)( |
| 2974 | Local<String> property, |
| 2975 | Local<Value> value, |
| 2976 | const PropertyCallbackInfo<Value>& info); |
| 2977 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2978 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | /** |
| 2980 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2981 | * The result is an integer encoding property attributes (like v8::None, |
| 2982 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2983 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2984 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2985 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2986 | typedef void (*NamedPropertyQueryCallback)( |
| 2987 | Local<String> property, |
| 2988 | const PropertyCallbackInfo<Integer>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2989 | |
| 2990 | |
| 2991 | /** |
| 2992 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2993 | * The return value is true if the property could be deleted and false |
| 2994 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2995 | */ |
| 2996 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2997 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2998 | typedef void (*NamedPropertyDeleterCallback)( |
| 2999 | Local<String> property, |
| 3000 | const PropertyCallbackInfo<Boolean>& info); |
| 3001 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3002 | |
| 3003 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3004 | * Returns an array containing the names of the properties the named |
| 3005 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3006 | */ |
| 3007 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3008 | typedef void (*NamedPropertyEnumeratorCallback)( |
| 3009 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3010 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3011 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3012 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3013 | * Returns the value of the property if the getter intercepts the |
| 3014 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3015 | */ |
| 3016 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 3017 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3018 | typedef void (*IndexedPropertyGetterCallback)( |
| 3019 | uint32_t index, |
| 3020 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3021 | |
| 3022 | |
| 3023 | /** |
| 3024 | * Returns the value if the setter intercepts the request. |
| 3025 | * Otherwise, returns an empty handle. |
| 3026 | */ |
| 3027 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 3028 | Local<Value> value, |
| 3029 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3030 | typedef void (*IndexedPropertySetterCallback)( |
| 3031 | uint32_t index, |
| 3032 | Local<Value> value, |
| 3033 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3034 | |
| 3035 | |
| 3036 | /** |
| 3037 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3038 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3039 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3040 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 3041 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3042 | typedef void (*IndexedPropertyQueryCallback)( |
| 3043 | uint32_t index, |
| 3044 | const PropertyCallbackInfo<Integer>& info); |
| 3045 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3046 | |
| 3047 | /** |
| 3048 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3049 | * The return value is true if the property could be deleted and false |
| 3050 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3051 | */ |
| 3052 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 3053 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3054 | typedef void (*IndexedPropertyDeleterCallback)( |
| 3055 | uint32_t index, |
| 3056 | const PropertyCallbackInfo<Boolean>& info); |
| 3057 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3058 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3059 | /** |
| 3060 | * Returns an array containing the indices of the properties the |
| 3061 | * indexed property getter intercepts. |
| 3062 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3063 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3064 | typedef void (*IndexedPropertyEnumeratorCallback)( |
| 3065 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3066 | |
| 3067 | |
| 3068 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3069 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3070 | */ |
| 3071 | enum AccessType { |
| 3072 | ACCESS_GET, |
| 3073 | ACCESS_SET, |
| 3074 | ACCESS_HAS, |
| 3075 | ACCESS_DELETE, |
| 3076 | ACCESS_KEYS |
| 3077 | }; |
| 3078 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3079 | |
| 3080 | /** |
| 3081 | * 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] | 3082 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3083 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3084 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3085 | Local<Value> key, |
| 3086 | AccessType type, |
| 3087 | Local<Value> data); |
| 3088 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3089 | |
| 3090 | /** |
| 3091 | * 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] | 3092 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3093 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3094 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3095 | uint32_t index, |
| 3096 | AccessType type, |
| 3097 | Local<Value> data); |
| 3098 | |
| 3099 | |
| 3100 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3101 | * A FunctionTemplate is used to create functions at runtime. There |
| 3102 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3103 | * context. The lifetime of the created function is equal to the |
| 3104 | * lifetime of the context. So in case the embedder needs to create |
| 3105 | * temporary functions that can be collected using Scripts is |
| 3106 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3107 | * |
| 3108 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3109 | * function object when it is created. |
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 | * A FunctionTemplate has a corresponding instance template which is |
| 3112 | * used to create object instances when the function is used as a |
| 3113 | * constructor. Properties added to the instance template are added to |
| 3114 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3115 | * |
| 3116 | * A FunctionTemplate can have a prototype template. The prototype template |
| 3117 | * is used to create the prototype object of the function. |
| 3118 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3119 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3120 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3121 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3122 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 3123 | * t->Set("func_property", v8::Number::New(1)); |
| 3124 | * |
| 3125 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 3126 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 3127 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 3128 | * |
| 3129 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 3130 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 3131 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 3132 | * instance_t->Set("instance_property", Number::New(3)); |
| 3133 | * |
| 3134 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 3135 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3136 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3137 | * |
| 3138 | * 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] | 3139 | * and "instance" for the instance object created above. The function |
| 3140 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3141 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3142 | * \code |
| 3143 | * func_property in function == true; |
| 3144 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3145 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3146 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 3147 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3148 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3149 | * instance instanceof function == true; |
| 3150 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 3151 | * instance.instance_property == 3; |
| 3152 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3153 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3154 | * A FunctionTemplate can inherit from another one by calling the |
| 3155 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 3156 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3157 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3158 | * \code |
| 3159 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 3160 | * ^ ^ |
| 3161 | * | Inherit(Parent) | .__proto__ |
| 3162 | * | | |
| 3163 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 3164 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3165 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3166 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 3167 | * object of the Child() function has __proto__ pointing to the |
| 3168 | * Parent() function's prototype object. An instance of the Child |
| 3169 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3170 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3171 | * Let Parent be the FunctionTemplate initialized in the previous |
| 3172 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3173 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3174 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3175 | * Local<FunctionTemplate> parent = t; |
| 3176 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 3177 | * child->Inherit(parent); |
| 3178 | * |
| 3179 | * Local<Function> child_function = child->GetFunction(); |
| 3180 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3181 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3182 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3183 | * The Child function and Child instance will have the following |
| 3184 | * properties: |
| 3185 | * |
| 3186 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3187 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3188 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3189 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3190 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3191 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3192 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3193 | public: |
| 3194 | /** Creates a function template.*/ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3195 | // TODO(dcarney): deprecate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3196 | static Local<FunctionTemplate> New( |
| 3197 | InvocationCallback callback = 0, |
| 3198 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3199 | Handle<Signature> signature = Handle<Signature>(), |
| 3200 | int length = 0); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3201 | static Local<FunctionTemplate> New( |
| 3202 | FunctionCallback callback, // TODO(dcarney): add back default param. |
| 3203 | Handle<Value> data = Handle<Value>(), |
| 3204 | Handle<Signature> signature = Handle<Signature>(), |
| 3205 | int length = 0); |
| 3206 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | /** Returns the unique function instance in the current execution context.*/ |
| 3208 | Local<Function> GetFunction(); |
| 3209 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3210 | /** |
| 3211 | * Set the call-handler callback for a FunctionTemplate. This |
| 3212 | * callback is called whenever the function created from this |
| 3213 | * FunctionTemplate is called. |
| 3214 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3215 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3216 | void SetCallHandler(InvocationCallback callback, |
| 3217 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3218 | void SetCallHandler(FunctionCallback callback, |
| 3219 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3220 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3221 | /** Set the predefined length property for the FunctionTemplate. */ |
| 3222 | void SetLength(int length); |
| 3223 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3224 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3225 | Local<ObjectTemplate> InstanceTemplate(); |
| 3226 | |
| 3227 | /** Causes the function template to inherit from a parent function template.*/ |
| 3228 | void Inherit(Handle<FunctionTemplate> parent); |
| 3229 | |
| 3230 | /** |
| 3231 | * A PrototypeTemplate is the template used to create the prototype object |
| 3232 | * of the function created by this template. |
| 3233 | */ |
| 3234 | Local<ObjectTemplate> PrototypeTemplate(); |
| 3235 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3236 | /** |
| 3237 | * Set the class name of the FunctionTemplate. This is used for |
| 3238 | * printing objects created with the function created from the |
| 3239 | * FunctionTemplate as its constructor. |
| 3240 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3241 | void SetClassName(Handle<String> name); |
| 3242 | |
| 3243 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3244 | * Determines whether the __proto__ accessor ignores instances of |
| 3245 | * the function template. If instances of the function template are |
| 3246 | * ignored, __proto__ skips all instances and instead returns the |
| 3247 | * next object in the prototype chain. |
| 3248 | * |
| 3249 | * Call with a value of true to make the __proto__ accessor ignore |
| 3250 | * instances of the function template. Call with a value of false |
| 3251 | * to make the __proto__ accessor not ignore instances of the |
| 3252 | * function template. By default, instances of a function template |
| 3253 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3254 | */ |
| 3255 | void SetHiddenPrototype(bool value); |
| 3256 | |
| 3257 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3258 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3259 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3260 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3261 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3262 | |
| 3263 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3264 | * Returns true if the given object is an instance of this function |
| 3265 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3266 | */ |
| 3267 | bool HasInstance(Handle<Value> object); |
| 3268 | |
| 3269 | private: |
| 3270 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3271 | friend class Context; |
| 3272 | friend class ObjectTemplate; |
| 3273 | }; |
| 3274 | |
| 3275 | |
| 3276 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3277 | * An ObjectTemplate is used to create objects at runtime. |
| 3278 | * |
| 3279 | * Properties added to an ObjectTemplate are added to each object |
| 3280 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3281 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3282 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3283 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3284 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3285 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3286 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3287 | /** Creates a new instance of this template.*/ |
| 3288 | Local<Object> NewInstance(); |
| 3289 | |
| 3290 | /** |
| 3291 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3292 | * |
| 3293 | * Whenever the property with the given name is accessed on objects |
| 3294 | * created from this ObjectTemplate the getter and setter callbacks |
| 3295 | * are called instead of getting and setting the property directly |
| 3296 | * on the JavaScript object. |
| 3297 | * |
| 3298 | * \param name The name of the property for which an accessor is added. |
| 3299 | * \param getter The callback to invoke when getting the property. |
| 3300 | * \param setter The callback to invoke when setting the property. |
| 3301 | * \param data A piece of data that will be passed to the getter and setter |
| 3302 | * callbacks whenever they are invoked. |
| 3303 | * \param settings Access control settings for the accessor. This is a bit |
| 3304 | * field consisting of one of more of |
| 3305 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3306 | * The default is to not allow cross-context access. |
| 3307 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3308 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3309 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3310 | * cross-context access. |
| 3311 | * \param attribute The attributes of the property for which an accessor |
| 3312 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3313 | * \param signature The signature describes valid receivers for the accessor |
| 3314 | * and is used to perform implicit instance checks against them. If the |
| 3315 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3316 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3317 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3318 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3319 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3320 | void SetAccessor(Handle<String> name, |
| 3321 | AccessorGetter getter, |
| 3322 | AccessorSetter setter = 0, |
| 3323 | Handle<Value> data = Handle<Value>(), |
| 3324 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3325 | PropertyAttribute attribute = None, |
| 3326 | Handle<AccessorSignature> signature = |
| 3327 | Handle<AccessorSignature>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3328 | void SetAccessor(Handle<String> name, |
| 3329 | AccessorGetterCallback getter, |
| 3330 | AccessorSetterCallback setter = 0, |
| 3331 | Handle<Value> data = Handle<Value>(), |
| 3332 | AccessControl settings = DEFAULT, |
| 3333 | PropertyAttribute attribute = None, |
| 3334 | Handle<AccessorSignature> signature = |
| 3335 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3336 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3337 | // This function is not yet stable and should not be used at this time. |
| 3338 | bool SetAccessor(Handle<String> name, |
| 3339 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3340 | AccessControl settings = DEFAULT, |
| 3341 | PropertyAttribute attribute = None, |
| 3342 | Handle<AccessorSignature> signature = |
| 3343 | Handle<AccessorSignature>()); |
| 3344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3345 | /** |
| 3346 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3347 | * |
| 3348 | * Whenever a named property is accessed on objects created from |
| 3349 | * this object template, the provided callback is invoked instead of |
| 3350 | * accessing the property directly on the JavaScript object. |
| 3351 | * |
| 3352 | * \param getter The callback to invoke when getting a property. |
| 3353 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3354 | * \param query The callback to invoke to check if a property is present, |
| 3355 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3356 | * \param deleter The callback to invoke when deleting a property. |
| 3357 | * \param enumerator The callback to invoke to enumerate all the named |
| 3358 | * properties of an object. |
| 3359 | * \param data A piece of data that will be passed to the callbacks |
| 3360 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3361 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3362 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3363 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3364 | NamedPropertySetter setter = 0, |
| 3365 | NamedPropertyQuery query = 0, |
| 3366 | NamedPropertyDeleter deleter = 0, |
| 3367 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3368 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3369 | void SetNamedPropertyHandler( |
| 3370 | NamedPropertyGetterCallback getter, |
| 3371 | NamedPropertySetterCallback setter = 0, |
| 3372 | NamedPropertyQueryCallback query = 0, |
| 3373 | NamedPropertyDeleterCallback deleter = 0, |
| 3374 | NamedPropertyEnumeratorCallback enumerator = 0, |
| 3375 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3376 | |
| 3377 | /** |
| 3378 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3379 | * |
| 3380 | * Whenever an indexed property is accessed on objects created from |
| 3381 | * this object template, the provided callback is invoked instead of |
| 3382 | * accessing the property directly on the JavaScript object. |
| 3383 | * |
| 3384 | * \param getter The callback to invoke when getting a property. |
| 3385 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3386 | * \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] | 3387 | * \param deleter The callback to invoke when deleting a property. |
| 3388 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3389 | * properties of an object. |
| 3390 | * \param data A piece of data that will be passed to the callbacks |
| 3391 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3392 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3393 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3395 | IndexedPropertySetter setter = 0, |
| 3396 | IndexedPropertyQuery query = 0, |
| 3397 | IndexedPropertyDeleter deleter = 0, |
| 3398 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3399 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3400 | void SetIndexedPropertyHandler( |
| 3401 | IndexedPropertyGetterCallback getter, |
| 3402 | IndexedPropertySetterCallback setter = 0, |
| 3403 | IndexedPropertyQueryCallback query = 0, |
| 3404 | IndexedPropertyDeleterCallback deleter = 0, |
| 3405 | IndexedPropertyEnumeratorCallback enumerator = 0, |
| 3406 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3407 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3408 | /** |
| 3409 | * Sets the callback to be used when calling instances created from |
| 3410 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3411 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3412 | * function. |
| 3413 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3414 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3415 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3416 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3417 | void SetCallAsFunctionHandler(FunctionCallback callback, |
| 3418 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3419 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3420 | /** |
| 3421 | * Mark object instances of the template as undetectable. |
| 3422 | * |
| 3423 | * In many ways, undetectable objects behave as though they are not |
| 3424 | * there. They behave like 'undefined' in conditionals and when |
| 3425 | * printed. However, properties can be accessed and called as on |
| 3426 | * normal objects. |
| 3427 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3428 | void MarkAsUndetectable(); |
| 3429 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3430 | /** |
| 3431 | * Sets access check callbacks on the object template. |
| 3432 | * |
| 3433 | * When accessing properties on instances of this object template, |
| 3434 | * the access check callback will be called to determine whether or |
| 3435 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3436 | * The last parameter specifies whether access checks are turned |
| 3437 | * on by default on instances. If access checks are off by default, |
| 3438 | * they can be turned on on individual instances by calling |
| 3439 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3440 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3441 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3442 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3443 | Handle<Value> data = Handle<Value>(), |
| 3444 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3445 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3446 | /** |
| 3447 | * Gets the number of internal fields for objects generated from |
| 3448 | * this template. |
| 3449 | */ |
| 3450 | int InternalFieldCount(); |
| 3451 | |
| 3452 | /** |
| 3453 | * Sets the number of internal fields for objects generated from |
| 3454 | * this template. |
| 3455 | */ |
| 3456 | void SetInternalFieldCount(int value); |
| 3457 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3458 | private: |
| 3459 | ObjectTemplate(); |
| 3460 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3461 | friend class FunctionTemplate; |
| 3462 | }; |
| 3463 | |
| 3464 | |
| 3465 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3466 | * A Signature specifies which receivers and arguments are valid |
| 3467 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3468 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3469 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3470 | public: |
| 3471 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3472 | Handle<FunctionTemplate>(), |
| 3473 | int argc = 0, |
| 3474 | Handle<FunctionTemplate> argv[] = 0); |
| 3475 | private: |
| 3476 | Signature(); |
| 3477 | }; |
| 3478 | |
| 3479 | |
| 3480 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3481 | * An AccessorSignature specifies which receivers are valid parameters |
| 3482 | * to an accessor callback. |
| 3483 | */ |
| 3484 | class V8EXPORT AccessorSignature : public Data { |
| 3485 | public: |
| 3486 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3487 | Handle<FunctionTemplate>()); |
| 3488 | private: |
| 3489 | AccessorSignature(); |
| 3490 | }; |
| 3491 | |
| 3492 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3493 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3494 | private: |
| 3495 | DeclaredAccessorDescriptor(); |
| 3496 | }; |
| 3497 | |
| 3498 | |
| 3499 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3500 | public: |
| 3501 | // This function is not yet stable and should not be used at this time. |
| 3502 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3503 | Isolate* isolate, |
| 3504 | int internal_field); |
| 3505 | private: |
| 3506 | ObjectOperationDescriptor(); |
| 3507 | }; |
| 3508 | |
| 3509 | |
| 3510 | enum DeclaredAccessorDescriptorDataType { |
| 3511 | kDescriptorBoolType, |
| 3512 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3513 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3514 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3515 | kDescriptorFloatType, kDescriptorDoubleType |
| 3516 | }; |
| 3517 | |
| 3518 | |
| 3519 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3520 | public: |
| 3521 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3522 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3523 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3524 | int16_t byte_offset); |
| 3525 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3526 | void* compare_value); |
| 3527 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3528 | Isolate* isolate, |
| 3529 | DeclaredAccessorDescriptorDataType data_type, |
| 3530 | uint8_t bool_offset = 0); |
| 3531 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3532 | uint8_t bitmask, |
| 3533 | uint8_t compare_value); |
| 3534 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3535 | Isolate* isolate, |
| 3536 | uint16_t bitmask, |
| 3537 | uint16_t compare_value); |
| 3538 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3539 | Isolate* isolate, |
| 3540 | uint32_t bitmask, |
| 3541 | uint32_t compare_value); |
| 3542 | |
| 3543 | private: |
| 3544 | RawOperationDescriptor(); |
| 3545 | }; |
| 3546 | |
| 3547 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3548 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3549 | * A utility for determining the type of objects based on the template |
| 3550 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3551 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3552 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3553 | public: |
| 3554 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3555 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3556 | int match(Handle<Value> value); |
| 3557 | private: |
| 3558 | TypeSwitch(); |
| 3559 | }; |
| 3560 | |
| 3561 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3562 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3563 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3564 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3565 | : public String::ExternalAsciiStringResource { |
| 3566 | public: |
| 3567 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3568 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3569 | : data_(data), length_(length) {} |
| 3570 | const char* data() const { return data_; } |
| 3571 | size_t length() const { return length_; } |
| 3572 | |
| 3573 | private: |
| 3574 | const char* data_; |
| 3575 | size_t length_; |
| 3576 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3577 | |
| 3578 | /** |
| 3579 | * Ignore |
| 3580 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3581 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3582 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3583 | // Note that the strings passed into this constructor must live as long |
| 3584 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3585 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3586 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3587 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3588 | const char** deps = 0, |
| 3589 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3590 | virtual ~Extension() { } |
| 3591 | virtual v8::Handle<v8::FunctionTemplate> |
| 3592 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3593 | return v8::Handle<v8::FunctionTemplate>(); |
| 3594 | } |
| 3595 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3596 | const char* name() const { return name_; } |
| 3597 | size_t source_length() const { return source_length_; } |
| 3598 | const String::ExternalAsciiStringResource* source() const { |
| 3599 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3600 | int dependency_count() { return dep_count_; } |
| 3601 | const char** dependencies() { return deps_; } |
| 3602 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3603 | bool auto_enable() { return auto_enable_; } |
| 3604 | |
| 3605 | private: |
| 3606 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3607 | size_t source_length_; // expected to initialize before source_ |
| 3608 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3609 | int dep_count_; |
| 3610 | const char** deps_; |
| 3611 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3612 | |
| 3613 | // Disallow copying and assigning. |
| 3614 | Extension(const Extension&); |
| 3615 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3616 | }; |
| 3617 | |
| 3618 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3619 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3620 | |
| 3621 | |
| 3622 | /** |
| 3623 | * Ignore |
| 3624 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3625 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3626 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3627 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3628 | RegisterExtension(extension); |
| 3629 | } |
| 3630 | }; |
| 3631 | |
| 3632 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3633 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3634 | |
| 3635 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3636 | Handle<Primitive> V8EXPORT Undefined(); |
| 3637 | Handle<Primitive> V8EXPORT Null(); |
| 3638 | Handle<Boolean> V8EXPORT True(); |
| 3639 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3640 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3641 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3642 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3643 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3644 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3645 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3646 | |
| 3647 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3648 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3649 | * You must set the heap size before initializing the VM - the size cannot be |
| 3650 | * adjusted after the VM is initialized. |
| 3651 | * |
| 3652 | * If you are using threads then you should hold the V8::Locker lock while |
| 3653 | * setting the stack limit and you must set a non-default stack limit separately |
| 3654 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3655 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3656 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3657 | public: |
| 3658 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3659 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3660 | 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] | 3661 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3662 | 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] | 3663 | int max_executable_size() { return max_executable_size_; } |
| 3664 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3665 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3666 | // 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] | 3667 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3668 | private: |
| 3669 | int max_young_space_size_; |
| 3670 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3671 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3672 | uint32_t* stack_limit_; |
| 3673 | }; |
| 3674 | |
| 3675 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3676 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3677 | |
| 3678 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3679 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3680 | |
| 3681 | |
| 3682 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3683 | |
| 3684 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3685 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3686 | |
| 3687 | |
| 3688 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3689 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3690 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3691 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3692 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3693 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3694 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3695 | |
| 3696 | /** |
| 3697 | * Create new error objects by calling the corresponding error object |
| 3698 | * constructor with the message. |
| 3699 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3700 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3701 | public: |
| 3702 | static Local<Value> RangeError(Handle<String> message); |
| 3703 | static Local<Value> ReferenceError(Handle<String> message); |
| 3704 | static Local<Value> SyntaxError(Handle<String> message); |
| 3705 | static Local<Value> TypeError(Handle<String> message); |
| 3706 | static Local<Value> Error(Handle<String> message); |
| 3707 | }; |
| 3708 | |
| 3709 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3710 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3711 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3712 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3713 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3714 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3715 | int min, |
| 3716 | int max, |
| 3717 | size_t buckets); |
| 3718 | |
| 3719 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3720 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3721 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3722 | enum ObjectSpace { |
| 3723 | kObjectSpaceNewSpace = 1 << 0, |
| 3724 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3725 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3726 | kObjectSpaceCodeSpace = 1 << 3, |
| 3727 | kObjectSpaceMapSpace = 1 << 4, |
| 3728 | kObjectSpaceLoSpace = 1 << 5, |
| 3729 | |
| 3730 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3731 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3732 | kObjectSpaceLoSpace |
| 3733 | }; |
| 3734 | |
| 3735 | enum AllocationAction { |
| 3736 | kAllocationActionAllocate = 1 << 0, |
| 3737 | kAllocationActionFree = 1 << 1, |
| 3738 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3739 | }; |
| 3740 | |
| 3741 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3742 | AllocationAction action, |
| 3743 | int size); |
| 3744 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3745 | // --- Leave Script Callback --- |
| 3746 | typedef void (*CallCompletedCallback)(); |
| 3747 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3748 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3749 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3750 | AccessType type, |
| 3751 | Local<Value> data); |
| 3752 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3753 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3754 | |
| 3755 | /** |
| 3756 | * Callback to check if code generation from strings is allowed. See |
| 3757 | * Context::AllowCodeGenerationFromStrings. |
| 3758 | */ |
| 3759 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3760 | |
| 3761 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3762 | |
| 3763 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3764 | * Applications can register callback functions which will be called |
| 3765 | * before and after a garbage collection. Allocations are not |
| 3766 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3767 | * objects (set or delete properties for example) since it is possible |
| 3768 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3769 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3770 | enum GCType { |
| 3771 | kGCTypeScavenge = 1 << 0, |
| 3772 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3773 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3774 | }; |
| 3775 | |
| 3776 | enum GCCallbackFlags { |
| 3777 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3778 | kGCCallbackFlagCompacted = 1 << 0, |
| 3779 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3780 | }; |
| 3781 | |
| 3782 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3783 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3784 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3785 | typedef void (*GCCallback)(); |
| 3786 | |
| 3787 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3788 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3789 | * Collection of V8 heap information. |
| 3790 | * |
| 3791 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3792 | * get heap statistics from V8. |
| 3793 | */ |
| 3794 | class V8EXPORT HeapStatistics { |
| 3795 | public: |
| 3796 | HeapStatistics(); |
| 3797 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3798 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3799 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3800 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3801 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3802 | |
| 3803 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3804 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3805 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3806 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3807 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3808 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3809 | |
| 3810 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3811 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3812 | }; |
| 3813 | |
| 3814 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3815 | class RetainedObjectInfo; |
| 3816 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3817 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3818 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3819 | * isolates have completely separate states. Objects from one isolate |
| 3820 | * must not be used in other isolates. When V8 is initialized a |
| 3821 | * default isolate is implicitly created and entered. The embedder |
| 3822 | * can create additional isolates and use them in parallel in multiple |
| 3823 | * 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] | 3824 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3825 | */ |
| 3826 | class V8EXPORT Isolate { |
| 3827 | public: |
| 3828 | /** |
| 3829 | * Stack-allocated class which sets the isolate for all operations |
| 3830 | * executed within a local scope. |
| 3831 | */ |
| 3832 | class V8EXPORT Scope { |
| 3833 | public: |
| 3834 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3835 | isolate->Enter(); |
| 3836 | } |
| 3837 | |
| 3838 | ~Scope() { isolate_->Exit(); } |
| 3839 | |
| 3840 | private: |
| 3841 | Isolate* const isolate_; |
| 3842 | |
| 3843 | // Prevent copying of Scope objects. |
| 3844 | Scope(const Scope&); |
| 3845 | Scope& operator=(const Scope&); |
| 3846 | }; |
| 3847 | |
| 3848 | /** |
| 3849 | * Creates a new isolate. Does not change the currently entered |
| 3850 | * isolate. |
| 3851 | * |
| 3852 | * When an isolate is no longer used its resources should be freed |
| 3853 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3854 | */ |
| 3855 | static Isolate* New(); |
| 3856 | |
| 3857 | /** |
| 3858 | * Returns the entered isolate for the current thread or NULL in |
| 3859 | * case there is no current isolate. |
| 3860 | */ |
| 3861 | static Isolate* GetCurrent(); |
| 3862 | |
| 3863 | /** |
| 3864 | * Methods below this point require holding a lock (using Locker) in |
| 3865 | * a multi-threaded environment. |
| 3866 | */ |
| 3867 | |
| 3868 | /** |
| 3869 | * Sets this isolate as the entered one for the current thread. |
| 3870 | * Saves the previously entered one (if any), so that it can be |
| 3871 | * restored when exiting. Re-entering an isolate is allowed. |
| 3872 | */ |
| 3873 | void Enter(); |
| 3874 | |
| 3875 | /** |
| 3876 | * Exits this isolate by restoring the previously entered one in the |
| 3877 | * current thread. The isolate may still stay the same, if it was |
| 3878 | * entered more than once. |
| 3879 | * |
| 3880 | * Requires: this == Isolate::GetCurrent(). |
| 3881 | */ |
| 3882 | void Exit(); |
| 3883 | |
| 3884 | /** |
| 3885 | * Disposes the isolate. The isolate must not be entered by any |
| 3886 | * thread to be disposable. |
| 3887 | */ |
| 3888 | void Dispose(); |
| 3889 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3890 | /** |
| 3891 | * Associate embedder-specific data with the isolate |
| 3892 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3893 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3894 | |
| 3895 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3896 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3897 | * Returns NULL if SetData has never been called. |
| 3898 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3899 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3900 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3901 | /** |
| 3902 | * Get statistics about the heap memory usage. |
| 3903 | */ |
| 3904 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3905 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3906 | /** |
| 3907 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3908 | * indication of the amount of externally allocated memory that is kept alive |
| 3909 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3910 | * garbage collections. Registering externally allocated memory will trigger |
| 3911 | * global garbage collections more often than it would otherwise in an attempt |
| 3912 | * to garbage collect the JavaScript objects that keep the externally |
| 3913 | * allocated memory alive. |
| 3914 | * |
| 3915 | * \param change_in_bytes the change in externally allocated memory that is |
| 3916 | * kept alive by JavaScript objects. |
| 3917 | * \returns the adjusted value. |
| 3918 | */ |
| 3919 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3920 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3921 | /** |
| 3922 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3923 | * is initialized. |
| 3924 | */ |
| 3925 | HeapProfiler* GetHeapProfiler(); |
| 3926 | |
| 3927 | /** |
| 3928 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3929 | * is initialized. |
| 3930 | */ |
| 3931 | CpuProfiler* GetCpuProfiler(); |
| 3932 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3933 | /** Returns the context that is on the top of the stack. */ |
| 3934 | Local<Context> GetCurrentContext(); |
| 3935 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3936 | /** |
| 3937 | * Allows the host application to group objects together. If one |
| 3938 | * object in the group is alive, all objects in the group are alive. |
| 3939 | * After each garbage collection, object groups are removed. It is |
| 3940 | * intended to be used in the before-garbage-collection callback |
| 3941 | * function, for instance to simulate DOM tree connections among JS |
| 3942 | * wrapper objects. Object groups for all dependent handles need to |
| 3943 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3944 | * garbage collection types it is sufficient to provide object groups |
| 3945 | * for partially dependent handles only. |
| 3946 | */ |
| 3947 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3948 | UniqueId id); |
| 3949 | |
| 3950 | /** |
| 3951 | * Allows the host application to declare implicit references from an object |
| 3952 | * group to an object. If the objects of the object group are alive, the child |
| 3953 | * object is alive too. After each garbage collection, all implicit references |
| 3954 | * are removed. It is intended to be used in the before-garbage-collection |
| 3955 | * callback function. |
| 3956 | */ |
| 3957 | void SetReferenceFromGroup(UniqueId id, |
| 3958 | const Persistent<Value>& child); |
| 3959 | |
| 3960 | /** |
| 3961 | * Allows the host application to declare implicit references from an object |
| 3962 | * to another object. If the parent object is alive, the child object is alive |
| 3963 | * too. After each garbage collection, all implicit references are removed. It |
| 3964 | * is intended to be used in the before-garbage-collection callback function. |
| 3965 | */ |
| 3966 | void SetReference(const Persistent<Object>& parent, |
| 3967 | const Persistent<Value>& child); |
| 3968 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3969 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3970 | Isolate(); |
| 3971 | Isolate(const Isolate&); |
| 3972 | ~Isolate(); |
| 3973 | Isolate& operator=(const Isolate&); |
| 3974 | void* operator new(size_t size); |
| 3975 | void operator delete(void*, size_t); |
| 3976 | }; |
| 3977 | |
| 3978 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3979 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3980 | public: |
| 3981 | enum CompressionAlgorithm { |
| 3982 | kUncompressed, |
| 3983 | kBZip2 |
| 3984 | }; |
| 3985 | |
| 3986 | const char* data; |
| 3987 | int compressed_size; |
| 3988 | int raw_size; |
| 3989 | }; |
| 3990 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3991 | |
| 3992 | /** |
| 3993 | * A helper class for driving V8 startup data decompression. It is based on |
| 3994 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3995 | * for an embedder to use this class, instead, API functions can be used |
| 3996 | * directly. |
| 3997 | * |
| 3998 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3999 | */ |
| 4000 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 4001 | public: |
| 4002 | StartupDataDecompressor(); |
| 4003 | virtual ~StartupDataDecompressor(); |
| 4004 | int Decompress(); |
| 4005 | |
| 4006 | protected: |
| 4007 | virtual int DecompressData(char* raw_data, |
| 4008 | int* raw_data_size, |
| 4009 | const char* compressed_data, |
| 4010 | int compressed_data_size) = 0; |
| 4011 | |
| 4012 | private: |
| 4013 | char** raw_data; |
| 4014 | }; |
| 4015 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4016 | |
| 4017 | /** |
| 4018 | * EntropySource is used as a callback function when v8 needs a source |
| 4019 | * of entropy. |
| 4020 | */ |
| 4021 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 4022 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4023 | |
| 4024 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4025 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 4026 | * resolving the location of a return address on the stack. Profilers that |
| 4027 | * change the return address on the stack can use this to resolve the stack |
| 4028 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4029 | * |
| 4030 | * \param return_addr_location points to a location on stack where a machine |
| 4031 | * return address resides. |
| 4032 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 4033 | * copy of the original return address. |
| 4034 | * |
| 4035 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4036 | */ |
| 4037 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 4038 | uintptr_t return_addr_location); |
| 4039 | |
| 4040 | |
| 4041 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4042 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 4043 | * any generated function when function-level profiling is enabled. |
| 4044 | * |
| 4045 | * \param function the address of the function that's being entered. |
| 4046 | * \param return_addr_location points to a location on stack where the machine |
| 4047 | * return address resides. This can be used to identify the caller of |
| 4048 | * \p function, and/or modified to divert execution when \p function exits. |
| 4049 | * |
| 4050 | * \note the entry hook must not cause garbage collection. |
| 4051 | */ |
| 4052 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 4053 | uintptr_t return_addr_location); |
| 4054 | |
| 4055 | |
| 4056 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4057 | * A JIT code event is issued each time code is added, moved or removed. |
| 4058 | * |
| 4059 | * \note removal events are not currently issued. |
| 4060 | */ |
| 4061 | struct JitCodeEvent { |
| 4062 | enum EventType { |
| 4063 | CODE_ADDED, |
| 4064 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4065 | CODE_REMOVED, |
| 4066 | CODE_ADD_LINE_POS_INFO, |
| 4067 | CODE_START_LINE_INFO_RECORDING, |
| 4068 | CODE_END_LINE_INFO_RECORDING |
| 4069 | }; |
| 4070 | // Definition of the code position type. The "POSITION" type means the place |
| 4071 | // in the source code which are of interest when making stack traces to |
| 4072 | // pin-point the source location of a stack frame as close as possible. |
| 4073 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 4074 | // statement, and is used to indicate possible break locations. |
| 4075 | enum PositionType { |
| 4076 | POSITION, |
| 4077 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4078 | }; |
| 4079 | |
| 4080 | // Type of event. |
| 4081 | EventType type; |
| 4082 | // Start of the instructions. |
| 4083 | void* code_start; |
| 4084 | // Size of the instructions. |
| 4085 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4086 | // Script info for CODE_ADDED event. |
| 4087 | Handle<Script> script; |
| 4088 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 4089 | // code line information which is returned from the |
| 4090 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 4091 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 4092 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4093 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4094 | struct name_t { |
| 4095 | // Name of the object associated with the code, note that the string is not |
| 4096 | // zero-terminated. |
| 4097 | const char* str; |
| 4098 | // Number of chars in str. |
| 4099 | size_t len; |
| 4100 | }; |
| 4101 | |
| 4102 | struct line_info_t { |
| 4103 | // PC offset |
| 4104 | size_t offset; |
| 4105 | // Code postion |
| 4106 | size_t pos; |
| 4107 | // The position type. |
| 4108 | PositionType position_type; |
| 4109 | }; |
| 4110 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4111 | union { |
| 4112 | // Only valid for CODE_ADDED. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4113 | struct name_t name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4114 | |
| 4115 | // Only valid for CODE_ADD_LINE_POS_INFO |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4116 | struct line_info_t line_info; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4117 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4118 | // New location of instructions. Only valid for CODE_MOVED. |
| 4119 | void* new_code_start; |
| 4120 | }; |
| 4121 | }; |
| 4122 | |
| 4123 | /** |
| 4124 | * Option flags passed to the SetJitCodeEventHandler function. |
| 4125 | */ |
| 4126 | enum JitCodeEventOptions { |
| 4127 | kJitCodeEventDefault = 0, |
| 4128 | // Generate callbacks for already existent code. |
| 4129 | kJitCodeEventEnumExisting = 1 |
| 4130 | }; |
| 4131 | |
| 4132 | |
| 4133 | /** |
| 4134 | * Callback function passed to SetJitCodeEventHandler. |
| 4135 | * |
| 4136 | * \param event code add, move or removal event. |
| 4137 | */ |
| 4138 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 4139 | |
| 4140 | |
| 4141 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4142 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4143 | */ |
| 4144 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 4145 | public: |
| 4146 | virtual ~ExternalResourceVisitor() {} |
| 4147 | virtual void VisitExternalString(Handle<String> string) {} |
| 4148 | }; |
| 4149 | |
| 4150 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4151 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4152 | * Interface for iterating through all the persistent handles in the heap. |
| 4153 | */ |
| 4154 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 4155 | public: |
| 4156 | virtual ~PersistentHandleVisitor() {} |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4157 | virtual void VisitPersistentHandle(Persistent<Value>* value, |
| 4158 | uint16_t class_id) {} |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4159 | }; |
| 4160 | |
| 4161 | |
| 4162 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4163 | * Asserts that no action is performed that could cause a handle's value |
| 4164 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 4165 | * be performed. |
| 4166 | */ |
| 4167 | class V8EXPORT AssertNoGCScope { |
| 4168 | #ifndef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4169 | // TODO(yangguo): remove isolate argument. |
| 4170 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4171 | #else |
| 4172 | AssertNoGCScope(Isolate* isolate); |
| 4173 | ~AssertNoGCScope(); |
| 4174 | private: |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4175 | void* disallow_heap_allocation_; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4176 | #endif |
| 4177 | }; |
| 4178 | |
| 4179 | |
| 4180 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4181 | * Container class for static utility functions. |
| 4182 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4183 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4184 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4185 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4186 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 4187 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4188 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4189 | * Set the callback to invoke to check if code generation from |
| 4190 | * strings should be allowed. |
| 4191 | */ |
| 4192 | static void SetAllowCodeGenerationFromStringsCallback( |
| 4193 | AllowCodeGenerationFromStringsCallback that); |
| 4194 | |
| 4195 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4196 | * Ignore out-of-memory exceptions. |
| 4197 | * |
| 4198 | * V8 running out of memory is treated as a fatal error by default. |
| 4199 | * This means that the fatal error handler is called and that V8 is |
| 4200 | * terminated. |
| 4201 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4202 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4203 | * out-of-memory situation as a fatal error. This way, the contexts |
| 4204 | * that did not cause the out of memory problem might be able to |
| 4205 | * continue execution. |
| 4206 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4207 | static void IgnoreOutOfMemoryException(); |
| 4208 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4209 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4210 | * 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] | 4211 | * fatal errors such as out-of-memory situations. |
| 4212 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | static bool IsDead(); |
| 4214 | |
| 4215 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4216 | * The following 4 functions are to be used when V8 is built with |
| 4217 | * the 'compress_startup_data' flag enabled. In this case, the |
| 4218 | * embedder must decompress startup data prior to initializing V8. |
| 4219 | * |
| 4220 | * This is how interaction with V8 should look like: |
| 4221 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 4222 | * v8::StartupData* compressed_data = |
| 4223 | * new v8::StartupData[compressed_data_count]; |
| 4224 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 4225 | * ... decompress data (compressed_data can be updated in-place) ... |
| 4226 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 4227 | * ... now V8 can be initialized |
| 4228 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4229 | * |
| 4230 | * A helper class StartupDataDecompressor is provided. It implements |
| 4231 | * the protocol of the interaction described above, and can be used in |
| 4232 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4233 | */ |
| 4234 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 4235 | static int GetCompressedStartupDataCount(); |
| 4236 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 4237 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 4238 | |
| 4239 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4240 | * Adds a message listener. |
| 4241 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4242 | * 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] | 4243 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4244 | * |
| 4245 | * If data is specified, it will be passed to the callback when it is called. |
| 4246 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4247 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4248 | static bool AddMessageListener(MessageCallback that, |
| 4249 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4250 | |
| 4251 | /** |
| 4252 | * Remove all message listeners from the specified callback function. |
| 4253 | */ |
| 4254 | static void RemoveMessageListeners(MessageCallback that); |
| 4255 | |
| 4256 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4257 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 4258 | * and report it to the message listeners. The option is off by default. |
| 4259 | */ |
| 4260 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 4261 | bool capture, |
| 4262 | int frame_limit = 10, |
| 4263 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 4264 | |
| 4265 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4266 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4267 | */ |
| 4268 | static void SetFlagsFromString(const char* str, int length); |
| 4269 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4270 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4271 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4272 | */ |
| 4273 | static void SetFlagsFromCommandLine(int* argc, |
| 4274 | char** argv, |
| 4275 | bool remove_flags); |
| 4276 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4277 | /** Get the version string. */ |
| 4278 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4279 | |
| 4280 | /** |
| 4281 | * Enables the host application to provide a mechanism for recording |
| 4282 | * statistics counters. |
| 4283 | */ |
| 4284 | static void SetCounterFunction(CounterLookupCallback); |
| 4285 | |
| 4286 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4287 | * Enables the host application to provide a mechanism for recording |
| 4288 | * histograms. The CreateHistogram function returns a |
| 4289 | * histogram which will later be passed to the AddHistogramSample |
| 4290 | * function. |
| 4291 | */ |
| 4292 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4293 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4294 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4295 | /** Callback function for reporting failed access checks.*/ |
| 4296 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4297 | |
| 4298 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4299 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4300 | * garbage collection. Allocations are not allowed in the |
| 4301 | * callback function, you therefore cannot manipulate objects (set |
| 4302 | * or delete properties for example) since it is possible such |
| 4303 | * operations will result in the allocation of objects. It is possible |
| 4304 | * to specify the GCType filter for your callback. But it is not possible to |
| 4305 | * register the same callback function two times with different |
| 4306 | * GCType filters. |
| 4307 | */ |
| 4308 | static void AddGCPrologueCallback( |
| 4309 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4310 | |
| 4311 | /** |
| 4312 | * This function removes callback which was installed by |
| 4313 | * AddGCPrologueCallback function. |
| 4314 | */ |
| 4315 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4316 | |
| 4317 | /** |
| 4318 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4319 | * Enables the host application to receive a notification before a |
| 4320 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4321 | * callback function, you therefore cannot manipulate objects (set |
| 4322 | * or delete properties for example) since it is possible such |
| 4323 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4324 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4325 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4326 | |
| 4327 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4328 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4329 | * garbage collection. Allocations are not allowed in the |
| 4330 | * callback function, you therefore cannot manipulate objects (set |
| 4331 | * or delete properties for example) since it is possible such |
| 4332 | * operations will result in the allocation of objects. It is possible |
| 4333 | * to specify the GCType filter for your callback. But it is not possible to |
| 4334 | * register the same callback function two times with different |
| 4335 | * GCType filters. |
| 4336 | */ |
| 4337 | static void AddGCEpilogueCallback( |
| 4338 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4339 | |
| 4340 | /** |
| 4341 | * This function removes callback which was installed by |
| 4342 | * AddGCEpilogueCallback function. |
| 4343 | */ |
| 4344 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4345 | |
| 4346 | /** |
| 4347 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4348 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4349 | * major garbage collection. Allocations are not allowed in the |
| 4350 | * callback function, you therefore cannot manipulate objects (set |
| 4351 | * or delete properties for example) since it is possible such |
| 4352 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4353 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4354 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4355 | |
| 4356 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4357 | * Enables the host application to provide a mechanism to be notified |
| 4358 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4359 | */ |
| 4360 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4361 | ObjectSpace space, |
| 4362 | AllocationAction action); |
| 4363 | |
| 4364 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4365 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4366 | */ |
| 4367 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4368 | |
| 4369 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4370 | * Adds a callback to notify the host application when a script finished |
| 4371 | * running. If a script re-enters the runtime during executing, the |
| 4372 | * CallCompletedCallback is only invoked when the outer-most script |
| 4373 | * execution ends. Executing scripts inside the callback do not trigger |
| 4374 | * further callbacks. |
| 4375 | */ |
| 4376 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4377 | |
| 4378 | /** |
| 4379 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4380 | */ |
| 4381 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4382 | |
| 4383 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4384 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4385 | * initialize from scratch. This function is called implicitly if |
| 4386 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4387 | */ |
| 4388 | static bool Initialize(); |
| 4389 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4390 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4391 | * Allows the host application to provide a callback which can be used |
| 4392 | * as a source of entropy for random number generators. |
| 4393 | */ |
| 4394 | static void SetEntropySource(EntropySource source); |
| 4395 | |
| 4396 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4397 | * Allows the host application to provide a callback that allows v8 to |
| 4398 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4399 | */ |
| 4400 | static void SetReturnAddressLocationResolver( |
| 4401 | ReturnAddressLocationResolver return_address_resolver); |
| 4402 | |
| 4403 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4404 | * Allows the host application to provide the address of a function that's |
| 4405 | * invoked on entry to every V8-generated function. |
| 4406 | * Note that \p entry_hook is invoked at the very start of each |
| 4407 | * generated function. |
| 4408 | * |
| 4409 | * \param entry_hook a function that will be invoked on entry to every |
| 4410 | * V8-generated function. |
| 4411 | * \returns true on success on supported platforms, false on failure. |
| 4412 | * \note Setting a new entry hook function when one is already active will |
| 4413 | * fail. |
| 4414 | */ |
| 4415 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4416 | |
| 4417 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4418 | * Allows the host application to provide the address of a function that is |
| 4419 | * notified each time code is added, moved or removed. |
| 4420 | * |
| 4421 | * \param options options for the JIT code event handler. |
| 4422 | * \param event_handler the JIT code event handler, which will be invoked |
| 4423 | * each time code is added, moved or removed. |
| 4424 | * \note \p event_handler won't get notified of existent code. |
| 4425 | * \note since code removal notifications are not currently issued, the |
| 4426 | * \p event_handler may get notifications of code that overlaps earlier |
| 4427 | * code notifications. This happens when code areas are reused, and the |
| 4428 | * earlier overlapping code areas should therefore be discarded. |
| 4429 | * \note the events passed to \p event_handler and the strings they point to |
| 4430 | * are not guaranteed to live past each call. The \p event_handler must |
| 4431 | * copy strings and other parameters it needs to keep around. |
| 4432 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4433 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4434 | * new members. The \p event_handler function must ignore event codes |
| 4435 | * it does not recognize to maintain future compatibility. |
| 4436 | */ |
| 4437 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4438 | JitCodeEventHandler event_handler); |
| 4439 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4440 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4441 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4442 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4443 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4444 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4445 | /** |
| 4446 | * Suspends recording of tick samples in the profiler. |
| 4447 | * When the V8 profiling mode is enabled (usually via command line |
| 4448 | * switches) this function suspends recording of tick samples. |
| 4449 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4450 | * |
| 4451 | * See also the --prof and --prof_auto command line switches to |
| 4452 | * enable V8 profiling. |
| 4453 | */ |
| 4454 | static void PauseProfiler(); |
| 4455 | |
| 4456 | /** |
| 4457 | * Resumes recording of tick samples in the profiler. |
| 4458 | * See also PauseProfiler(). |
| 4459 | */ |
| 4460 | static void ResumeProfiler(); |
| 4461 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4462 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4463 | * Return whether profiler is currently paused. |
| 4464 | */ |
| 4465 | static bool IsProfilerPaused(); |
| 4466 | |
| 4467 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4468 | * Retrieve the V8 thread id of the calling thread. |
| 4469 | * |
| 4470 | * The thread id for a thread should only be retrieved after the V8 |
| 4471 | * lock has been acquired with a Locker object with that thread. |
| 4472 | */ |
| 4473 | static int GetCurrentThreadId(); |
| 4474 | |
| 4475 | /** |
| 4476 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4477 | * be used to terminate long-running scripts. |
| 4478 | * |
| 4479 | * TerminateExecution should only be called when then V8 lock has |
| 4480 | * been acquired with a Locker object. Therefore, in order to be |
| 4481 | * able to terminate long-running threads, preemption must be |
| 4482 | * enabled to allow the user of TerminateExecution to acquire the |
| 4483 | * lock. |
| 4484 | * |
| 4485 | * The termination is achieved by throwing an exception that is |
| 4486 | * uncatchable by JavaScript exception handlers. Termination |
| 4487 | * 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] | 4488 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4489 | * exception handler that catches an exception should check if that |
| 4490 | * exception is a termination exception and immediately return if |
| 4491 | * that is the case. Returning immediately in that case will |
| 4492 | * continue the propagation of the termination exception if needed. |
| 4493 | * |
| 4494 | * The thread id passed to TerminateExecution must have been |
| 4495 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4496 | * |
| 4497 | * \param thread_id The thread id of the thread to terminate. |
| 4498 | */ |
| 4499 | static void TerminateExecution(int thread_id); |
| 4500 | |
| 4501 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4502 | * Forcefully terminate the current thread of JavaScript execution |
| 4503 | * in the given isolate. If no isolate is provided, the default |
| 4504 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4505 | * |
| 4506 | * This method can be used by any thread even if that thread has not |
| 4507 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4508 | * |
| 4509 | * \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] | 4510 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4511 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4512 | |
| 4513 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4514 | * Is V8 terminating JavaScript execution. |
| 4515 | * |
| 4516 | * Returns true if JavaScript execution is currently terminating |
| 4517 | * because of a call to TerminateExecution. In that case there are |
| 4518 | * still JavaScript frames on the stack and the termination |
| 4519 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4520 | * |
| 4521 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4522 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4523 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4524 | |
| 4525 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4526 | * Resume execution capability in the given isolate, whose execution |
| 4527 | * was previously forcefully terminated using TerminateExecution(). |
| 4528 | * |
| 4529 | * When execution is forcefully terminated using TerminateExecution(), |
| 4530 | * the isolate can not resume execution until all JavaScript frames |
| 4531 | * have propagated the uncatchable exception which is generated. This |
| 4532 | * method allows the program embedding the engine to handle the |
| 4533 | * termination event and resume execution capability, even if |
| 4534 | * JavaScript frames remain on the stack. |
| 4535 | * |
| 4536 | * This method can be used by any thread even if that thread has not |
| 4537 | * acquired the V8 lock with a Locker object. |
| 4538 | * |
| 4539 | * \param isolate The isolate in which to resume execution capability. |
| 4540 | */ |
| 4541 | static void CancelTerminateExecution(Isolate* isolate); |
| 4542 | |
| 4543 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4544 | * Releases any resources used by v8 and stops any utility threads |
| 4545 | * that may be running. Note that disposing v8 is permanent, it |
| 4546 | * cannot be reinitialized. |
| 4547 | * |
| 4548 | * It should generally not be necessary to dispose v8 before exiting |
| 4549 | * a process, this should happen automatically. It is only necessary |
| 4550 | * to use if the process needs the resources taken up by v8. |
| 4551 | */ |
| 4552 | static bool Dispose(); |
| 4553 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4554 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4555 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4556 | |
| 4557 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4558 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4559 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4560 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4561 | */ |
| 4562 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4563 | |
| 4564 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4565 | * Iterates through all the persistent handles in the current isolate's heap |
| 4566 | * that have class_ids. |
| 4567 | */ |
| 4568 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4569 | |
| 4570 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4571 | * Iterates through all the persistent handles in the current isolate's heap |
| 4572 | * that have class_ids and are candidates to be marked as partially dependent |
| 4573 | * handles. This will visit handles to young objects created since the last |
| 4574 | * garbage collection but is free to visit an arbitrary superset of these |
| 4575 | * objects. |
| 4576 | */ |
| 4577 | static void VisitHandlesForPartialDependence( |
| 4578 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4579 | |
| 4580 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4581 | * Optional notification that the embedder is idle. |
| 4582 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4583 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4584 | * Returns true if the embedder should stop calling IdleNotification |
| 4585 | * until real work has been done. This indicates that V8 has done |
| 4586 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4587 | * |
| 4588 | * The hint argument specifies the amount of work to be done in the function |
| 4589 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4590 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4591 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4592 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4593 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4594 | /** |
| 4595 | * Optional notification that the system is running low on memory. |
| 4596 | * V8 uses these notifications to attempt to free memory. |
| 4597 | */ |
| 4598 | static void LowMemoryNotification(); |
| 4599 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4600 | /** |
| 4601 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4602 | * these notifications to guide the GC heuristic. Returns the number |
| 4603 | * of context disposals - including this one - since the last time |
| 4604 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4605 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4606 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4607 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4608 | private: |
| 4609 | V8(); |
| 4610 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4611 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4612 | internal::Object** handle); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4613 | static void DisposeGlobal(internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4614 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4615 | static void MakeWeak(internal::Object** global_handle, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4616 | void* data, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4617 | RevivableCallback weak_reference_callback); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 4618 | static void ClearWeak(internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4619 | |
| 4620 | template <class T> friend class Handle; |
| 4621 | template <class T> friend class Local; |
| 4622 | template <class T> friend class Persistent; |
| 4623 | friend class Context; |
| 4624 | }; |
| 4625 | |
| 4626 | |
| 4627 | /** |
| 4628 | * An external exception handler. |
| 4629 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4630 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4631 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4632 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4633 | * Creates a new try/catch block and registers it with v8. Note that |
| 4634 | * all TryCatch blocks should be stack allocated because the memory |
| 4635 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4636 | */ |
| 4637 | TryCatch(); |
| 4638 | |
| 4639 | /** |
| 4640 | * Unregisters and deletes this try/catch block. |
| 4641 | */ |
| 4642 | ~TryCatch(); |
| 4643 | |
| 4644 | /** |
| 4645 | * Returns true if an exception has been caught by this try/catch block. |
| 4646 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4647 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4648 | |
| 4649 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4650 | * 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] | 4651 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4652 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4653 | * cleanup needed and then return. If CanContinue returns false and |
| 4654 | * HasTerminated returns true, it is possible to call |
| 4655 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4656 | */ |
| 4657 | bool CanContinue() const; |
| 4658 | |
| 4659 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4660 | * Returns true if an exception has been caught due to script execution |
| 4661 | * being terminated. |
| 4662 | * |
| 4663 | * There is no JavaScript representation of an execution termination |
| 4664 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4665 | * methods are called to terminate a long-running script. |
| 4666 | * |
| 4667 | * If such an exception has been thrown, HasTerminated will return true, |
| 4668 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4669 | * to continue calling into the engine. |
| 4670 | */ |
| 4671 | bool HasTerminated() const; |
| 4672 | |
| 4673 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4674 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4675 | * it being caught again by this same TryCatch. As with ThrowException |
| 4676 | * it is illegal to execute any JavaScript operations after calling |
| 4677 | * ReThrow; the caller must return immediately to where the exception |
| 4678 | * is caught. |
| 4679 | */ |
| 4680 | Handle<Value> ReThrow(); |
| 4681 | |
| 4682 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4683 | * Returns the exception caught by this try/catch block. If no exception has |
| 4684 | * been caught an empty handle is returned. |
| 4685 | * |
| 4686 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4687 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4688 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4689 | |
| 4690 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4691 | * Returns the .stack property of the thrown object. If no .stack |
| 4692 | * property is present an empty handle is returned. |
| 4693 | */ |
| 4694 | Local<Value> StackTrace() const; |
| 4695 | |
| 4696 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4697 | * Returns the message associated with this exception. If there is |
| 4698 | * no message associated an empty handle is returned. |
| 4699 | * |
| 4700 | * The returned handle is valid until this TryCatch block has been |
| 4701 | * destroyed. |
| 4702 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4703 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4704 | |
| 4705 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4706 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4707 | * After this method has been called, HasCaught() will return false. |
| 4708 | * |
| 4709 | * It is not necessary to clear a try/catch block before using it again; if |
| 4710 | * another exception is thrown the previously caught exception will just be |
| 4711 | * overwritten. However, it is often a good idea since it makes it easier |
| 4712 | * to determine which operation threw a given exception. |
| 4713 | */ |
| 4714 | void Reset(); |
| 4715 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4716 | /** |
| 4717 | * Set verbosity of the external exception handler. |
| 4718 | * |
| 4719 | * By default, exceptions that are caught by an external exception |
| 4720 | * handler are not reported. Call SetVerbose with true on an |
| 4721 | * external exception handler to have exceptions caught by the |
| 4722 | * handler reported as if they were not caught. |
| 4723 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4724 | void SetVerbose(bool value); |
| 4725 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4726 | /** |
| 4727 | * Set whether or not this TryCatch should capture a Message object |
| 4728 | * which holds source information about where the exception |
| 4729 | * occurred. True by default. |
| 4730 | */ |
| 4731 | void SetCaptureMessage(bool value); |
| 4732 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4733 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4734 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4735 | TryCatch(const TryCatch&); |
| 4736 | void operator=(const TryCatch&); |
| 4737 | void* operator new(size_t size); |
| 4738 | void operator delete(void*, size_t); |
| 4739 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4740 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4741 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4742 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4743 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4744 | bool is_verbose_ : 1; |
| 4745 | bool can_continue_ : 1; |
| 4746 | bool capture_message_ : 1; |
| 4747 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4748 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4749 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4750 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4751 | }; |
| 4752 | |
| 4753 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4754 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4755 | |
| 4756 | |
| 4757 | /** |
| 4758 | * Ignore |
| 4759 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4760 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4761 | public: |
| 4762 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4763 | : name_count_(name_count), names_(names) { } |
| 4764 | private: |
| 4765 | friend class ImplementationUtilities; |
| 4766 | int name_count_; |
| 4767 | const char** names_; |
| 4768 | }; |
| 4769 | |
| 4770 | |
| 4771 | /** |
| 4772 | * A sandboxed execution context with its own set of built-in objects |
| 4773 | * and functions. |
| 4774 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4775 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4776 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4777 | /** |
| 4778 | * Returns the global proxy object or global object itself for |
| 4779 | * detached contexts. |
| 4780 | * |
| 4781 | * Global proxy object is a thin wrapper whose prototype points to |
| 4782 | * actual context's global object with the properties like Object, etc. |
| 4783 | * This is done that way for security reasons (for more details see |
| 4784 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4785 | * |
| 4786 | * Please note that changes to global proxy object prototype most probably |
| 4787 | * would break VM---v8 expects only global object as a prototype of |
| 4788 | * global proxy object. |
| 4789 | * |
| 4790 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4791 | * object until global is reattached with ReattachGlobal(). |
| 4792 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4793 | Local<Object> Global(); |
| 4794 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4795 | /** |
| 4796 | * Detaches the global object from its context before |
| 4797 | * the global object can be reused to create a new context. |
| 4798 | */ |
| 4799 | void DetachGlobal(); |
| 4800 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4801 | /** |
| 4802 | * Reattaches a global object to a context. This can be used to |
| 4803 | * restore the connection between a global object and a context |
| 4804 | * after DetachGlobal has been called. |
| 4805 | * |
| 4806 | * \param global_object The global object to reattach to the |
| 4807 | * context. For this to work, the global object must be the global |
| 4808 | * object that was associated with this context before a call to |
| 4809 | * DetachGlobal. |
| 4810 | */ |
| 4811 | void ReattachGlobal(Handle<Object> global_object); |
| 4812 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4813 | /** |
| 4814 | * Creates a new context and returns a handle to the newly allocated |
| 4815 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4816 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4817 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4818 | * |
| 4819 | * \param extensions An optional extension configuration containing |
| 4820 | * the extensions to be installed in the newly created context. |
| 4821 | * |
| 4822 | * \param global_template An optional object template from which the |
| 4823 | * global object for the newly created context will be created. |
| 4824 | * |
| 4825 | * \param global_object An optional global object to be reused for |
| 4826 | * the newly created context. This global object must have been |
| 4827 | * created by a previous call to Context::New with the same global |
| 4828 | * template. The state of the global object will be completely reset |
| 4829 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4830 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4831 | static Local<Context> New( |
| 4832 | Isolate* isolate, |
| 4833 | ExtensionConfiguration* extensions = NULL, |
| 4834 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4835 | Handle<Value> global_object = Handle<Value>()); |
| 4836 | |
| 4837 | /** Deprecated. Use Isolate version instead. */ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4838 | V8_DEPRECATED(static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4839 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4840 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4841 | Handle<Value> global_object = Handle<Value>())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4842 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4843 | /** Returns the last entered context. */ |
| 4844 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4845 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4846 | // TODO(svenpanne) Actually deprecate this. |
| 4847 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4848 | static Local<Context> GetCurrent(); |
| 4849 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4850 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4851 | * Returns the context of the calling JavaScript code. That is the |
| 4852 | * context of the top-most JavaScript frame. If there are no |
| 4853 | * JavaScript frames an empty handle is returned. |
| 4854 | */ |
| 4855 | static Local<Context> GetCalling(); |
| 4856 | |
| 4857 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4858 | * Sets the security token for the context. To access an object in |
| 4859 | * another context, the security tokens must match. |
| 4860 | */ |
| 4861 | void SetSecurityToken(Handle<Value> token); |
| 4862 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4863 | /** Restores the security token to the default value. */ |
| 4864 | void UseDefaultSecurityToken(); |
| 4865 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4866 | /** Returns the security token of this context.*/ |
| 4867 | Handle<Value> GetSecurityToken(); |
| 4868 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4869 | /** |
| 4870 | * Enter this context. After entering a context, all code compiled |
| 4871 | * and run is compiled and run in this context. If another context |
| 4872 | * is already entered, this old context is saved so it can be |
| 4873 | * restored when the new context is exited. |
| 4874 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4875 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4876 | |
| 4877 | /** |
| 4878 | * Exit this context. Exiting the current context restores the |
| 4879 | * context that was in place when entering the current context. |
| 4880 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4881 | void Exit(); |
| 4882 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4883 | /** 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] | 4884 | bool HasOutOfMemoryException(); |
| 4885 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4886 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4887 | static bool InContext(); |
| 4888 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4889 | /** Returns an isolate associated with a current context. */ |
| 4890 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4891 | |
| 4892 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4893 | * Gets the embedder data with the given index, which must have been set by a |
| 4894 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4895 | * currently has a special meaning for Chrome's debugger. |
| 4896 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4897 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4898 | |
| 4899 | /** |
| 4900 | * Sets the embedder data with the given index, growing the data as |
| 4901 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4902 | * debugger. |
| 4903 | */ |
| 4904 | void SetEmbedderData(int index, Handle<Value> value); |
| 4905 | |
| 4906 | /** |
| 4907 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4908 | * index, which must have bees set by a previous call to |
| 4909 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4910 | * currently has a special meaning for Chrome's debugger. |
| 4911 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4912 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4913 | |
| 4914 | /** |
| 4915 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4916 | * index, growing the data as needed. Note that index 0 currently has a |
| 4917 | * special meaning for Chrome's debugger. |
| 4918 | */ |
| 4919 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4920 | |
| 4921 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4922 | * Control whether code generation from strings is allowed. Calling |
| 4923 | * this method with false will disable 'eval' and the 'Function' |
| 4924 | * constructor for code running in this context. If 'eval' or the |
| 4925 | * 'Function' constructor are used an exception will be thrown. |
| 4926 | * |
| 4927 | * If code generation from strings is not allowed the |
| 4928 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4929 | * set before blocking the call to 'eval' or the 'Function' |
| 4930 | * constructor. If that callback returns true, the call will be |
| 4931 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4932 | * set an exception will be thrown. |
| 4933 | */ |
| 4934 | void AllowCodeGenerationFromStrings(bool allow); |
| 4935 | |
| 4936 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4937 | * Returns true if code generation from strings is allowed for the context. |
| 4938 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4939 | */ |
| 4940 | bool IsCodeGenerationFromStringsAllowed(); |
| 4941 | |
| 4942 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4943 | * Sets the error description for the exception that is thrown when |
| 4944 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4945 | * constructor are called. |
| 4946 | */ |
| 4947 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4948 | |
| 4949 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4950 | * Stack-allocated class which sets the execution context for all |
| 4951 | * operations executed within a local scope. |
| 4952 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4953 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4954 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4955 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4956 | context_->Enter(); |
| 4957 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 4958 | // TODO(dcarney): deprecate |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4959 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4960 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4961 | : context_(Handle<Context>::New(isolate, context)) { |
| 4962 | #else |
| 4963 | : context_(Local<Context>::New(isolate, context)) { |
| 4964 | #endif |
| 4965 | context_->Enter(); |
| 4966 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4967 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4968 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4969 | private: |
| 4970 | Handle<Context> context_; |
| 4971 | }; |
| 4972 | |
| 4973 | private: |
| 4974 | friend class Value; |
| 4975 | friend class Script; |
| 4976 | friend class Object; |
| 4977 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4978 | |
| 4979 | Local<Value> SlowGetEmbedderData(int index); |
| 4980 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4981 | }; |
| 4982 | |
| 4983 | |
| 4984 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4985 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4986 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4987 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4988 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4989 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4990 | * constraint is not violated. In addition to any other synchronization |
| 4991 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4992 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4993 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4994 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4995 | * construction and destruction, the current thread is allowed to use the locked |
| 4996 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4997 | * 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] | 4998 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4999 | * Sample usage: |
| 5000 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5001 | * ... |
| 5002 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5003 | * v8::Locker locker(isolate); |
| 5004 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5005 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5006 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5007 | * ... |
| 5008 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5009 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5010 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5011 | * If you wish to stop using V8 in a thread A you can do this either by |
| 5012 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 5013 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5014 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5015 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5017 | * isolate->Exit(); |
| 5018 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | * ... |
| 5020 | * // Code not using V8 goes here while V8 can run in another thread. |
| 5021 | * ... |
| 5022 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5023 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5024 | * \endcode |
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 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 5027 | * 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] | 5028 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5029 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 5030 | * given thread. This can be useful if you have code that can be called either |
| 5031 | * from code that holds the lock or from code that does not. The Unlocker is |
| 5032 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 5033 | * 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] | 5034 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5035 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 5036 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5037 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5038 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5039 | * // V8 not locked. |
| 5040 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5041 | * v8::Locker locker(isolate); |
| 5042 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5043 | * // V8 locked. |
| 5044 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5045 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5046 | * // V8 still locked (2 levels). |
| 5047 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5048 | * isolate->Exit(); |
| 5049 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5050 | * // V8 not locked. |
| 5051 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5052 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5053 | * // V8 locked again (2 levels). |
| 5054 | * } |
| 5055 | * // V8 still locked (1 level). |
| 5056 | * } |
| 5057 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5058 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5059 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5060 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5062 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5063 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5064 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5065 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 5066 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5067 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5068 | V8_DEPRECATED(Unlocker()); |
| 5069 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5070 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5071 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5072 | void Initialize(Isolate* isolate); |
| 5073 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5074 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5075 | }; |
| 5076 | |
| 5077 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5078 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5079 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5080 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5081 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5082 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5083 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 5084 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5085 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5086 | V8_DEPRECATED(Locker()); |
| 5087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5088 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5089 | |
| 5090 | /** |
| 5091 | * Start preemption. |
| 5092 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5093 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5094 | * that will switch between multiple threads that are in contention |
| 5095 | * for the V8 lock. |
| 5096 | */ |
| 5097 | static void StartPreemption(int every_n_ms); |
| 5098 | |
| 5099 | /** |
| 5100 | * Stop preemption. |
| 5101 | */ |
| 5102 | static void StopPreemption(); |
| 5103 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5104 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5105 | * Returns whether or not the locker for a given isolate, is locked by the |
| 5106 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5107 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5108 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5109 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5110 | /** |
| 5111 | * Returns whether v8::Locker is being used by this V8 instance. |
| 5112 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5113 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5114 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5115 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5116 | void Initialize(Isolate* isolate); |
| 5117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5118 | bool has_lock_; |
| 5119 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5120 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5121 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5122 | static bool active_; |
| 5123 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5124 | // Disallow copying and assigning. |
| 5125 | Locker(const Locker&); |
| 5126 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5127 | }; |
| 5128 | |
| 5129 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5130 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5131 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 5132 | */ |
| 5133 | struct HeapStatsUpdate; |
| 5134 | |
| 5135 | |
| 5136 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5137 | * An interface for exporting data from V8, using "push" model. |
| 5138 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5139 | class V8EXPORT OutputStream { // NOLINT |
| 5140 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5141 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5142 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5143 | }; |
| 5144 | enum WriteResult { |
| 5145 | kContinue = 0, |
| 5146 | kAbort = 1 |
| 5147 | }; |
| 5148 | virtual ~OutputStream() {} |
| 5149 | /** Notify about the end of stream. */ |
| 5150 | virtual void EndOfStream() = 0; |
| 5151 | /** Get preferred output chunk size. Called only once. */ |
| 5152 | virtual int GetChunkSize() { return 1024; } |
| 5153 | /** Get preferred output encoding. Called only once. */ |
| 5154 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 5155 | /** |
| 5156 | * Writes the next chunk of snapshot data into the stream. Writing |
| 5157 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5158 | * will not be called in case writing was aborted. |
| 5159 | */ |
| 5160 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5161 | /** |
| 5162 | * Writes the next chunk of heap stats data into the stream. Writing |
| 5163 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5164 | * will not be called in case writing was aborted. |
| 5165 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5166 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 5167 | return kAbort; |
| 5168 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5169 | }; |
| 5170 | |
| 5171 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5172 | /** |
| 5173 | * An interface for reporting progress and controlling long-running |
| 5174 | * activities. |
| 5175 | */ |
| 5176 | class V8EXPORT ActivityControl { // NOLINT |
| 5177 | public: |
| 5178 | enum ControlOption { |
| 5179 | kContinue = 0, |
| 5180 | kAbort = 1 |
| 5181 | }; |
| 5182 | virtual ~ActivityControl() {} |
| 5183 | /** |
| 5184 | * Notify about current progress. The activity can be stopped by |
| 5185 | * returning kAbort as the callback result. |
| 5186 | */ |
| 5187 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 5188 | }; |
| 5189 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5190 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5191 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5192 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5193 | |
| 5194 | namespace internal { |
| 5195 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5196 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 5197 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5198 | |
| 5199 | // Tag information for HeapObject. |
| 5200 | const int kHeapObjectTag = 1; |
| 5201 | const int kHeapObjectTagSize = 2; |
| 5202 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 5203 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5204 | // Tag information for Smi. |
| 5205 | const int kSmiTag = 0; |
| 5206 | const int kSmiTagSize = 1; |
| 5207 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 5208 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5209 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5210 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5211 | template<int kSmiShiftSize> |
| 5212 | V8_INLINE(internal::Object* IntToSmi(int value)) { |
| 5213 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5214 | intptr_t tagged_value = |
| 5215 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
| 5216 | return reinterpret_cast<internal::Object*>(tagged_value); |
| 5217 | } |
| 5218 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5219 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5220 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5221 | static const int kSmiShiftSize = 0; |
| 5222 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5223 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5224 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5225 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 5226 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 5227 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5228 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5229 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5230 | } |
| 5231 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5232 | // To be representable as an tagged small integer, the two |
| 5233 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 5234 | // sign-extension. To check this we add 01 to the two |
| 5235 | // most-significant bits, and check if the most-significant bit is 0 |
| 5236 | // |
| 5237 | // CAUTION: The original code below: |
| 5238 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 5239 | // may lead to incorrect results according to the C language spec, and |
| 5240 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 5241 | // compiler may produce undefined results in case of signed integer |
| 5242 | // overflow. The computation must be done w/ unsigned ints. |
| 5243 | return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; |
| 5244 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5245 | }; |
| 5246 | |
| 5247 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5248 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5249 | static const int kSmiShiftSize = 31; |
| 5250 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5251 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5252 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5253 | // Shift down and throw away top 32 bits. |
| 5254 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5255 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5256 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5257 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5258 | } |
| 5259 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5260 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 5261 | return (value == static_cast<int32_t>(value)); |
| 5262 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5263 | }; |
| 5264 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5265 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5266 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5267 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5268 | |
| 5269 | /** |
| 5270 | * This class exports constants and functionality from within v8 that |
| 5271 | * is necessary to implement inline functions in the v8 api. Don't |
| 5272 | * depend on functions and constants defined here. |
| 5273 | */ |
| 5274 | class Internals { |
| 5275 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5276 | // These values match non-compiler-dependent values defined within |
| 5277 | // the implementation of v8. |
| 5278 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5279 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5280 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5281 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5282 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5283 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5284 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5285 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5286 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5287 | static const int kContextEmbedderDataIndex = 64; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5288 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5289 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5290 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5291 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5292 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5293 | static const int kIsolateStateOffset = 0; |
| 5294 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5295 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5296 | static const int kUndefinedValueRootIndex = 5; |
| 5297 | static const int kNullValueRootIndex = 7; |
| 5298 | static const int kTrueValueRootIndex = 8; |
| 5299 | static const int kFalseValueRootIndex = 9; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5300 | static const int kEmptyStringRootIndex = 130; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5301 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5302 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5303 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5304 | static const int kNodeStateMask = 0xf; |
| 5305 | static const int kNodeStateIsWeakValue = 2; |
| 5306 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5307 | static const int kNodeIsIndependentShift = 4; |
| 5308 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5309 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5310 | static const int kJSObjectType = 0xaf; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5311 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5312 | static const int kOddballType = 0x83; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5313 | static const int kForeignType = 0x87; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5314 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5315 | static const int kUndefinedOddballKind = 5; |
| 5316 | static const int kNullOddballKind = 3; |
| 5317 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5318 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5319 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5320 | kHeapObjectTag); |
| 5321 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5322 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5323 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5324 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5327 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5328 | return PlatformSmiTagging::IntToSmi(value); |
| 5329 | } |
| 5330 | |
| 5331 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5332 | return PlatformSmiTagging::IsValidSmi(value); |
| 5333 | } |
| 5334 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5335 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5336 | typedef internal::Object O; |
| 5337 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5338 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5339 | } |
| 5340 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5341 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5342 | typedef internal::Object O; |
| 5343 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5344 | } |
| 5345 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5346 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5347 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5348 | return representation == kExternalTwoByteRepresentationTag; |
| 5349 | } |
| 5350 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5351 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5352 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5353 | return *reinterpret_cast<int*>(addr) == 1; |
| 5354 | } |
| 5355 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5356 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5357 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5358 | return *addr & (1 << shift); |
| 5359 | } |
| 5360 | |
| 5361 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5362 | bool value, int shift)) { |
| 5363 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5364 | uint8_t mask = 1 << shift; |
| 5365 | *addr = (*addr & ~mask) | (value << shift); |
| 5366 | } |
| 5367 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5368 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5369 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5370 | return *addr & kNodeStateMask; |
| 5371 | } |
| 5372 | |
| 5373 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5374 | uint8_t value)) { |
| 5375 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5376 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5377 | } |
| 5378 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5379 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5380 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5381 | kIsolateEmbedderDataOffset; |
| 5382 | *reinterpret_cast<void**>(addr) = data; |
| 5383 | } |
| 5384 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5385 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5386 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5387 | kIsolateEmbedderDataOffset; |
| 5388 | return *reinterpret_cast<void**>(addr); |
| 5389 | } |
| 5390 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5391 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5392 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5393 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5394 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5395 | } |
| 5396 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5397 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5398 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5399 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5400 | return *reinterpret_cast<T*>(addr); |
| 5401 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5402 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5403 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5404 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5405 | typedef internal::Object O; |
| 5406 | typedef internal::Internals I; |
| 5407 | O* ctx = *reinterpret_cast<O**>(context); |
| 5408 | int embedder_data_offset = I::kContextHeaderSize + |
| 5409 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5410 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5411 | int value_offset = |
| 5412 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5413 | return I::ReadField<T>(embedder_data, value_offset); |
| 5414 | } |
| 5415 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5416 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5417 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5418 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5419 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5420 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5421 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5422 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5423 | }; |
| 5424 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5425 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5426 | |
| 5427 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5428 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5429 | Local<T>::Local() : Handle<T>() { } |
| 5430 | |
| 5431 | |
| 5432 | template <class T> |
| 5433 | Local<T> Local<T>::New(Handle<T> that) { |
| 5434 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5435 | T* that_ptr = *that; |
| 5436 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5437 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5438 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5439 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5440 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5441 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5442 | } |
| 5443 | |
| 5444 | |
| 5445 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5446 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5447 | return New(isolate, that.val_); |
| 5448 | } |
| 5449 | |
| 5450 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5451 | template <class T> |
| 5452 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5453 | return New(isolate, that.val_); |
| 5454 | } |
| 5455 | |
| 5456 | template <class T> |
| 5457 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5458 | if (that == NULL) return Handle<T>(); |
| 5459 | T* that_ptr = that; |
| 5460 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5461 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5462 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5463 | } |
| 5464 | #endif |
| 5465 | |
| 5466 | |
| 5467 | template <class T> |
| 5468 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5469 | if (that == NULL) return Local<T>(); |
| 5470 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5471 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5472 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5473 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5474 | } |
| 5475 | |
| 5476 | |
| 5477 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5478 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5479 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | |
| 5483 | template <class T> |
| 5484 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5485 | return New(Isolate::GetCurrent(), that.val_); |
| 5486 | } |
| 5487 | |
| 5488 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5489 | template <class T> |
| 5490 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5491 | return New(Isolate::GetCurrent(), that.val_); |
| 5492 | } |
| 5493 | #endif |
| 5494 | |
| 5495 | template <class T> |
| 5496 | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5497 | if (that == NULL) return Persistent<T>(); |
| 5498 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5499 | return Persistent<T>(reinterpret_cast<T*>( |
| 5500 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5501 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | |
| 5505 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5506 | bool Persistent<T>::IsIndependent() const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5507 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5508 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5509 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5510 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | |
| 5514 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5515 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5516 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5517 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5518 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5519 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5520 | } |
| 5521 | |
| 5522 | |
| 5523 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5524 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5525 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5526 | if (this->IsEmpty()) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5527 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5528 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5533 | void Persistent<T>::Dispose() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5534 | if (this->IsEmpty()) return; |
| 5535 | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); |
| 5536 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5537 | val_ = 0; |
| 5538 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | |
| 5542 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5543 | template <typename S, typename P> |
| 5544 | void Persistent<T>::MakeWeak( |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5545 | P* parameters, |
| 5546 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5547 | TYPE_CHECK(S, T); |
| 5548 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5549 | V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5550 | parameters, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5551 | reinterpret_cast<Revivable>(callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5554 | |
| 5555 | template <class T> |
| 5556 | template <typename P> |
| 5557 | void Persistent<T>::MakeWeak( |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5558 | P* parameters, |
| 5559 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5560 | MakeWeak<T, P>(parameters, callback); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5564 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5565 | void Persistent<T>::ClearWeak() { |
| 5566 | V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5567 | } |
| 5568 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5569 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5570 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5571 | void Persistent<T>::MarkIndependent() { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5572 | typedef internal::Internals I; |
| 5573 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5574 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5575 | true, |
| 5576 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5577 | } |
| 5578 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5579 | |
| 5580 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5581 | void Persistent<T>::MarkPartiallyDependent() { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5582 | typedef internal::Internals I; |
| 5583 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5584 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5585 | true, |
| 5586 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5589 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5590 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5591 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5592 | Dispose(isolate); |
| 5593 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5594 | *this = *New(isolate, other); |
| 5595 | #else |
| 5596 | if (other.IsEmpty()) { |
| 5597 | this->val_ = NULL; |
| 5598 | return; |
| 5599 | } |
| 5600 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5601 | this->val_ = reinterpret_cast<T*>( |
| 5602 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5603 | #endif |
| 5604 | } |
| 5605 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5606 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5607 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5608 | template <class T> |
| 5609 | void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { |
| 5610 | Dispose(isolate); |
| 5611 | if (other.IsEmpty()) { |
| 5612 | this->val_ = NULL; |
| 5613 | return; |
| 5614 | } |
| 5615 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5616 | this->val_ = reinterpret_cast<T*>( |
| 5617 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5618 | } |
| 5619 | #endif |
| 5620 | |
| 5621 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5622 | template <class T> |
| 5623 | T* Persistent<T>::ClearAndLeak() { |
| 5624 | T* old; |
| 5625 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5626 | old = **this; |
| 5627 | *this = Persistent<T>(); |
| 5628 | #else |
| 5629 | old = val_; |
| 5630 | val_ = NULL; |
| 5631 | #endif |
| 5632 | return old; |
| 5633 | } |
| 5634 | |
| 5635 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5636 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5637 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5638 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5639 | if (this->IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5640 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5641 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5642 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5643 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5644 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5645 | |
| 5646 | template <class T> |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5647 | uint16_t Persistent<T>::WrapperClassId() const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5648 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5649 | if (this->IsEmpty()) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5650 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5651 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5652 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5653 | } |
| 5654 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5655 | |
| 5656 | template<typename T> |
| 5657 | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| 5658 | |
| 5659 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5660 | template<typename S> |
| 5661 | void ReturnValue<T>::Set(const Persistent<S>& handle) { |
| 5662 | TYPE_CHECK(T, S); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5663 | if (V8_UNLIKELY(handle.IsEmpty())) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 5664 | *value_ = GetDefaultValue(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5665 | } else { |
| 5666 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5667 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | template<typename T> |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5671 | template<typename S> |
| 5672 | void ReturnValue<T>::Set(const Handle<S> handle) { |
| 5673 | TYPE_CHECK(T, S); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5674 | if (V8_UNLIKELY(handle.IsEmpty())) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 5675 | *value_ = GetDefaultValue(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5676 | } else { |
| 5677 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5678 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5682 | void ReturnValue<T>::Set(double i) { |
| 5683 | Set(Number::New(GetIsolate(), i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5687 | void ReturnValue<T>::Set(int32_t i) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5688 | typedef internal::Internals I; |
| 5689 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5690 | *value_ = I::IntToSmi(i); |
| 5691 | return; |
| 5692 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5693 | Set(Integer::New(i, GetIsolate())); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5697 | void ReturnValue<T>::Set(uint32_t i) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5698 | typedef internal::Internals I; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5699 | // Can't simply use INT32_MAX here for whatever reason. |
| 5700 | bool fits_into_int32_t = (i & (1 << 31)) == 0; |
| 5701 | if (V8_LIKELY(fits_into_int32_t)) { |
| 5702 | Set(static_cast<int32_t>(i)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5703 | return; |
| 5704 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5705 | Set(Integer::NewFromUnsigned(i, GetIsolate())); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5709 | void ReturnValue<T>::Set(bool value) { |
| 5710 | typedef internal::Internals I; |
| 5711 | int root_index; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5712 | if (value) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5713 | root_index = I::kTrueValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5714 | } else { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5715 | root_index = I::kFalseValueRootIndex; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5716 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5717 | *value_ = *I::GetRoot(GetIsolate(), root_index); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5721 | void ReturnValue<T>::SetNull() { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5722 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5723 | *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5727 | void ReturnValue<T>::SetUndefined() { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5728 | typedef internal::Internals I; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5729 | *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | template<typename T> |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 5733 | Isolate* ReturnValue<T>::GetIsolate() { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame^] | 5734 | // Isolate is always the pointer below the default value on the stack. |
| 5735 | return *reinterpret_cast<Isolate**>(&value_[-2]); |
| 5736 | } |
| 5737 | |
| 5738 | template<typename T> |
| 5739 | internal::Object* ReturnValue<T>::GetDefaultValue() { |
| 5740 | // Default value is always the pointer below value_ on the stack. |
| 5741 | return value_[-1]; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | |
| 5745 | template<typename T> |
| 5746 | FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, |
| 5747 | internal::Object** values, |
| 5748 | int length, |
| 5749 | bool is_construct_call) |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5750 | : implicit_args_(implicit_args), |
| 5751 | values_(values), |
| 5752 | length_(length), |
| 5753 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5754 | |
| 5755 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5756 | Arguments::Arguments(internal::Object** args, |
| 5757 | internal::Object** values, |
| 5758 | int length, |
| 5759 | bool is_construct_call) |
| 5760 | : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { } |
| 5761 | |
| 5762 | |
| 5763 | template<typename T> |
| 5764 | Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5765 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5766 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5767 | } |
| 5768 | |
| 5769 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5770 | template<typename T> |
| 5771 | Local<Function> FunctionCallbackInfo<T>::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5772 | return Local<Function>(reinterpret_cast<Function*>( |
| 5773 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5777 | template<typename T> |
| 5778 | Local<Object> FunctionCallbackInfo<T>::This() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5779 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5780 | } |
| 5781 | |
| 5782 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5783 | template<typename T> |
| 5784 | Local<Object> FunctionCallbackInfo<T>::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5785 | return Local<Object>(reinterpret_cast<Object*>( |
| 5786 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5790 | template<typename T> |
| 5791 | Local<Value> FunctionCallbackInfo<T>::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5792 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5796 | template<typename T> |
| 5797 | Isolate* FunctionCallbackInfo<T>::GetIsolate() const { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5798 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5799 | } |
| 5800 | |
| 5801 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5802 | template<typename T> |
| 5803 | ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const { |
| 5804 | return ReturnValue<T>(&implicit_args_[kReturnValueIndex]); |
| 5805 | } |
| 5806 | |
| 5807 | |
| 5808 | template<typename T> |
| 5809 | bool FunctionCallbackInfo<T>::IsConstructCall() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5810 | return is_construct_call_; |
| 5811 | } |
| 5812 | |
| 5813 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5814 | template<typename T> |
| 5815 | int FunctionCallbackInfo<T>::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5816 | return length_; |
| 5817 | } |
| 5818 | |
| 5819 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5820 | template <class T> |
| 5821 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5822 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5823 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5824 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5825 | } |
| 5826 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5827 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5828 | return resource_name_; |
| 5829 | } |
| 5830 | |
| 5831 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5832 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5833 | return resource_line_offset_; |
| 5834 | } |
| 5835 | |
| 5836 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5837 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5838 | return resource_column_offset_; |
| 5839 | } |
| 5840 | |
| 5841 | |
| 5842 | Handle<Boolean> Boolean::New(bool value) { |
| 5843 | return value ? True() : False(); |
| 5844 | } |
| 5845 | |
| 5846 | |
| 5847 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5848 | Set(v8::String::New(name), value); |
| 5849 | } |
| 5850 | |
| 5851 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5852 | Local<Value> Object::GetInternalField(int index) { |
| 5853 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5854 | typedef internal::Object O; |
| 5855 | typedef internal::Internals I; |
| 5856 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5857 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5858 | // 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] | 5859 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5860 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5861 | O* value = I::ReadField<O*>(obj, offset); |
| 5862 | O** result = HandleScope::CreateHandle(value); |
| 5863 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5864 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5865 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5866 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5870 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5871 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5872 | typedef internal::Object O; |
| 5873 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5874 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5875 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5876 | // 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] | 5877 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5878 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5879 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5880 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5881 | #endif |
| 5882 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | |
| 5886 | String* String::Cast(v8::Value* value) { |
| 5887 | #ifdef V8_ENABLE_CHECKS |
| 5888 | CheckCast(value); |
| 5889 | #endif |
| 5890 | return static_cast<String*>(value); |
| 5891 | } |
| 5892 | |
| 5893 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5894 | Local<String> String::Empty(Isolate* isolate) { |
| 5895 | typedef internal::Object* S; |
| 5896 | typedef internal::Internals I; |
| 5897 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5898 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5899 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5900 | } |
| 5901 | |
| 5902 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5903 | Local<String> String::New(const char* data, int length) { |
| 5904 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5905 | } |
| 5906 | |
| 5907 | |
| 5908 | Local<String> String::New(const uint16_t* data, int length) { |
| 5909 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5910 | } |
| 5911 | |
| 5912 | |
| 5913 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5914 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5915 | } |
| 5916 | |
| 5917 | |
| 5918 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5919 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5920 | } |
| 5921 | |
| 5922 | |
| 5923 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5924 | return NewFromTwoByte( |
| 5925 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5926 | } |
| 5927 | |
| 5928 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5929 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5930 | typedef internal::Object O; |
| 5931 | typedef internal::Internals I; |
| 5932 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5933 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5934 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5935 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5936 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5937 | } else { |
| 5938 | result = NULL; |
| 5939 | } |
| 5940 | #ifdef V8_ENABLE_CHECKS |
| 5941 | VerifyExternalStringResource(result); |
| 5942 | #endif |
| 5943 | return result; |
| 5944 | } |
| 5945 | |
| 5946 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5947 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5948 | String::Encoding* encoding_out) const { |
| 5949 | typedef internal::Object O; |
| 5950 | typedef internal::Internals I; |
| 5951 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5952 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5953 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5954 | ExternalStringResourceBase* resource = NULL; |
| 5955 | if (type == I::kExternalAsciiRepresentationTag || |
| 5956 | type == I::kExternalTwoByteRepresentationTag) { |
| 5957 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5958 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5959 | } |
| 5960 | #ifdef V8_ENABLE_CHECKS |
| 5961 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5962 | #endif |
| 5963 | return resource; |
| 5964 | } |
| 5965 | |
| 5966 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5967 | bool Value::IsUndefined() const { |
| 5968 | #ifdef V8_ENABLE_CHECKS |
| 5969 | return FullIsUndefined(); |
| 5970 | #else |
| 5971 | return QuickIsUndefined(); |
| 5972 | #endif |
| 5973 | } |
| 5974 | |
| 5975 | bool Value::QuickIsUndefined() const { |
| 5976 | typedef internal::Object O; |
| 5977 | typedef internal::Internals I; |
| 5978 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5979 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5980 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5981 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 5982 | } |
| 5983 | |
| 5984 | |
| 5985 | bool Value::IsNull() const { |
| 5986 | #ifdef V8_ENABLE_CHECKS |
| 5987 | return FullIsNull(); |
| 5988 | #else |
| 5989 | return QuickIsNull(); |
| 5990 | #endif |
| 5991 | } |
| 5992 | |
| 5993 | bool Value::QuickIsNull() const { |
| 5994 | typedef internal::Object O; |
| 5995 | typedef internal::Internals I; |
| 5996 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5997 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5998 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5999 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 6000 | } |
| 6001 | |
| 6002 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6003 | bool Value::IsString() const { |
| 6004 | #ifdef V8_ENABLE_CHECKS |
| 6005 | return FullIsString(); |
| 6006 | #else |
| 6007 | return QuickIsString(); |
| 6008 | #endif |
| 6009 | } |
| 6010 | |
| 6011 | bool Value::QuickIsString() const { |
| 6012 | typedef internal::Object O; |
| 6013 | typedef internal::Internals I; |
| 6014 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6015 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6016 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 6020 | template <class T> Value* Value::Cast(T* value) { |
| 6021 | return static_cast<Value*>(value); |
| 6022 | } |
| 6023 | |
| 6024 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6025 | Symbol* Symbol::Cast(v8::Value* value) { |
| 6026 | #ifdef V8_ENABLE_CHECKS |
| 6027 | CheckCast(value); |
| 6028 | #endif |
| 6029 | return static_cast<Symbol*>(value); |
| 6030 | } |
| 6031 | |
| 6032 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6033 | Number* Number::Cast(v8::Value* value) { |
| 6034 | #ifdef V8_ENABLE_CHECKS |
| 6035 | CheckCast(value); |
| 6036 | #endif |
| 6037 | return static_cast<Number*>(value); |
| 6038 | } |
| 6039 | |
| 6040 | |
| 6041 | Integer* Integer::Cast(v8::Value* value) { |
| 6042 | #ifdef V8_ENABLE_CHECKS |
| 6043 | CheckCast(value); |
| 6044 | #endif |
| 6045 | return static_cast<Integer*>(value); |
| 6046 | } |
| 6047 | |
| 6048 | |
| 6049 | Date* Date::Cast(v8::Value* value) { |
| 6050 | #ifdef V8_ENABLE_CHECKS |
| 6051 | CheckCast(value); |
| 6052 | #endif |
| 6053 | return static_cast<Date*>(value); |
| 6054 | } |
| 6055 | |
| 6056 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6057 | StringObject* StringObject::Cast(v8::Value* value) { |
| 6058 | #ifdef V8_ENABLE_CHECKS |
| 6059 | CheckCast(value); |
| 6060 | #endif |
| 6061 | return static_cast<StringObject*>(value); |
| 6062 | } |
| 6063 | |
| 6064 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6065 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 6066 | #ifdef V8_ENABLE_CHECKS |
| 6067 | CheckCast(value); |
| 6068 | #endif |
| 6069 | return static_cast<SymbolObject*>(value); |
| 6070 | } |
| 6071 | |
| 6072 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6073 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 6074 | #ifdef V8_ENABLE_CHECKS |
| 6075 | CheckCast(value); |
| 6076 | #endif |
| 6077 | return static_cast<NumberObject*>(value); |
| 6078 | } |
| 6079 | |
| 6080 | |
| 6081 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 6082 | #ifdef V8_ENABLE_CHECKS |
| 6083 | CheckCast(value); |
| 6084 | #endif |
| 6085 | return static_cast<BooleanObject*>(value); |
| 6086 | } |
| 6087 | |
| 6088 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 6089 | RegExp* RegExp::Cast(v8::Value* value) { |
| 6090 | #ifdef V8_ENABLE_CHECKS |
| 6091 | CheckCast(value); |
| 6092 | #endif |
| 6093 | return static_cast<RegExp*>(value); |
| 6094 | } |
| 6095 | |
| 6096 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6097 | Object* Object::Cast(v8::Value* value) { |
| 6098 | #ifdef V8_ENABLE_CHECKS |
| 6099 | CheckCast(value); |
| 6100 | #endif |
| 6101 | return static_cast<Object*>(value); |
| 6102 | } |
| 6103 | |
| 6104 | |
| 6105 | Array* Array::Cast(v8::Value* value) { |
| 6106 | #ifdef V8_ENABLE_CHECKS |
| 6107 | CheckCast(value); |
| 6108 | #endif |
| 6109 | return static_cast<Array*>(value); |
| 6110 | } |
| 6111 | |
| 6112 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6113 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 6114 | #ifdef V8_ENABLE_CHECKS |
| 6115 | CheckCast(value); |
| 6116 | #endif |
| 6117 | return static_cast<ArrayBuffer*>(value); |
| 6118 | } |
| 6119 | |
| 6120 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6121 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 6122 | #ifdef V8_ENABLE_CHECKS |
| 6123 | CheckCast(value); |
| 6124 | #endif |
| 6125 | return static_cast<TypedArray*>(value); |
| 6126 | } |
| 6127 | |
| 6128 | |
| 6129 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 6130 | #ifdef V8_ENABLE_CHECKS |
| 6131 | CheckCast(value); |
| 6132 | #endif |
| 6133 | return static_cast<Uint8Array*>(value); |
| 6134 | } |
| 6135 | |
| 6136 | |
| 6137 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 6138 | #ifdef V8_ENABLE_CHECKS |
| 6139 | CheckCast(value); |
| 6140 | #endif |
| 6141 | return static_cast<Int8Array*>(value); |
| 6142 | } |
| 6143 | |
| 6144 | |
| 6145 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 6146 | #ifdef V8_ENABLE_CHECKS |
| 6147 | CheckCast(value); |
| 6148 | #endif |
| 6149 | return static_cast<Uint16Array*>(value); |
| 6150 | } |
| 6151 | |
| 6152 | |
| 6153 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 6154 | #ifdef V8_ENABLE_CHECKS |
| 6155 | CheckCast(value); |
| 6156 | #endif |
| 6157 | return static_cast<Int16Array*>(value); |
| 6158 | } |
| 6159 | |
| 6160 | |
| 6161 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 6162 | #ifdef V8_ENABLE_CHECKS |
| 6163 | CheckCast(value); |
| 6164 | #endif |
| 6165 | return static_cast<Uint32Array*>(value); |
| 6166 | } |
| 6167 | |
| 6168 | |
| 6169 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 6170 | #ifdef V8_ENABLE_CHECKS |
| 6171 | CheckCast(value); |
| 6172 | #endif |
| 6173 | return static_cast<Int32Array*>(value); |
| 6174 | } |
| 6175 | |
| 6176 | |
| 6177 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 6178 | #ifdef V8_ENABLE_CHECKS |
| 6179 | CheckCast(value); |
| 6180 | #endif |
| 6181 | return static_cast<Float32Array*>(value); |
| 6182 | } |
| 6183 | |
| 6184 | |
| 6185 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 6186 | #ifdef V8_ENABLE_CHECKS |
| 6187 | CheckCast(value); |
| 6188 | #endif |
| 6189 | return static_cast<Float64Array*>(value); |
| 6190 | } |
| 6191 | |
| 6192 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 6193 | Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) { |
| 6194 | #ifdef V8_ENABLE_CHECKS |
| 6195 | CheckCast(value); |
| 6196 | #endif |
| 6197 | return static_cast<Uint8ClampedArray*>(value); |
| 6198 | } |
| 6199 | |
| 6200 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6201 | Function* Function::Cast(v8::Value* value) { |
| 6202 | #ifdef V8_ENABLE_CHECKS |
| 6203 | CheckCast(value); |
| 6204 | #endif |
| 6205 | return static_cast<Function*>(value); |
| 6206 | } |
| 6207 | |
| 6208 | |
| 6209 | External* External::Cast(v8::Value* value) { |
| 6210 | #ifdef V8_ENABLE_CHECKS |
| 6211 | CheckCast(value); |
| 6212 | #endif |
| 6213 | return static_cast<External*>(value); |
| 6214 | } |
| 6215 | |
| 6216 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6217 | template<typename T> |
| 6218 | Isolate* PropertyCallbackInfo<T>::GetIsolate() const { |
| 6219 | return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6223 | template<typename T> |
| 6224 | Local<Value> PropertyCallbackInfo<T>::Data() const { |
| 6225 | return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6229 | template<typename T> |
| 6230 | Local<Object> PropertyCallbackInfo<T>::This() const { |
| 6231 | return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6235 | template<typename T> |
| 6236 | Local<Object> PropertyCallbackInfo<T>::Holder() const { |
| 6237 | return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex])); |
| 6238 | } |
| 6239 | |
| 6240 | |
| 6241 | template<typename T> |
| 6242 | ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { |
| 6243 | return ReturnValue<T>(&args_[kReturnValueIndex]); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 6247 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 6248 | typedef internal::Object* S; |
| 6249 | typedef internal::Internals I; |
| 6250 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 6251 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 6252 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6253 | } |
| 6254 | |
| 6255 | |
| 6256 | Handle<Primitive> Null(Isolate* isolate) { |
| 6257 | typedef internal::Object* S; |
| 6258 | typedef internal::Internals I; |
| 6259 | if (!I::IsInitialized(isolate)) return Null(); |
| 6260 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 6261 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6262 | } |
| 6263 | |
| 6264 | |
| 6265 | Handle<Boolean> True(Isolate* isolate) { |
| 6266 | typedef internal::Object* S; |
| 6267 | typedef internal::Internals I; |
| 6268 | if (!I::IsInitialized(isolate)) return True(); |
| 6269 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 6270 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6271 | } |
| 6272 | |
| 6273 | |
| 6274 | Handle<Boolean> False(Isolate* isolate) { |
| 6275 | typedef internal::Object* S; |
| 6276 | typedef internal::Internals I; |
| 6277 | if (!I::IsInitialized(isolate)) return False(); |
| 6278 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 6279 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6280 | } |
| 6281 | |
| 6282 | |
| 6283 | void Isolate::SetData(void* data) { |
| 6284 | typedef internal::Internals I; |
| 6285 | I::SetEmbedderData(this, data); |
| 6286 | } |
| 6287 | |
| 6288 | |
| 6289 | void* Isolate::GetData() { |
| 6290 | typedef internal::Internals I; |
| 6291 | return I::GetEmbedderData(this); |
| 6292 | } |
| 6293 | |
| 6294 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 6295 | Local<Value> Context::GetEmbedderData(int index) { |
| 6296 | #ifndef V8_ENABLE_CHECKS |
| 6297 | typedef internal::Object O; |
| 6298 | typedef internal::Internals I; |
| 6299 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 6300 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 6301 | #else |
| 6302 | return SlowGetEmbedderData(index); |
| 6303 | #endif |
| 6304 | } |
| 6305 | |
| 6306 | |
| 6307 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 6308 | #ifndef V8_ENABLE_CHECKS |
| 6309 | typedef internal::Internals I; |
| 6310 | return I::ReadEmbedderData<void*>(this, index); |
| 6311 | #else |
| 6312 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 6313 | #endif |
| 6314 | } |
| 6315 | |
| 6316 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6317 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 6318 | * \example shell.cc |
| 6319 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6320 | * command-line and executes them. |
| 6321 | */ |
| 6322 | |
| 6323 | |
| 6324 | /** |
| 6325 | * \example process.cc |
| 6326 | */ |
| 6327 | |
| 6328 | |
| 6329 | } // namespace v8 |
| 6330 | |
| 6331 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6332 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6333 | #undef TYPE_CHECK |
| 6334 | |
| 6335 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6336 | #endif // V8_H_ |