jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 32 | * This set of documents provides reference material generated from the |
| 33 | * V8 header file, include/v8.h. |
| 34 | * |
| 35 | * For other documentation see http://code.google.com/apis/v8/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 66 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 67 | (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 68 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 70 | #else |
| 71 | #define V8EXPORT |
| 72 | #endif |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 73 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 75 | #endif |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // _WIN32 |
| 78 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 79 | #if defined(__GNUC__) && !defined(DEBUG) |
| 80 | #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 81 | #elif defined(_MSC_VER) && !defined(DEBUG) |
| 82 | #define V8_INLINE(declarator) __forceinline declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 83 | #else |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 84 | #define V8_INLINE(declarator) inline declarator |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS |
| 88 | #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated)) |
| 89 | #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS |
| 90 | #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 91 | #else |
| 92 | #define V8_DEPRECATED(declarator) declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 95 | #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 96 | #define V8_UNLIKELY(condition) __builtin_expect((condition), 0) |
| 97 | #define V8_LIKELY(condition) __builtin_expect((condition), 1) |
| 98 | #else |
| 99 | #define V8_UNLIKELY(condition) (condition) |
| 100 | #define V8_LIKELY(condition) (condition) |
| 101 | #endif |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 104 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | */ |
| 106 | namespace v8 { |
| 107 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 108 | class AccessorInfo; |
| 109 | class AccessorSignature; |
| 110 | class Array; |
| 111 | class Boolean; |
| 112 | class BooleanObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | class Context; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 114 | class CpuProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 115 | class Data; |
| 116 | class Date; |
| 117 | class DeclaredAccessorDescriptor; |
| 118 | class External; |
| 119 | class Function; |
| 120 | class FunctionTemplate; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 121 | class HeapProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 122 | class ImplementationUtilities; |
| 123 | class Int32; |
| 124 | class Integer; |
| 125 | class Isolate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | class LocalContext; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 128 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 130 | class ObjectOperationDescriptor; |
| 131 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 133 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 135 | class StackFrame; |
| 136 | class StackTrace; |
| 137 | class String; |
| 138 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 139 | class Symbol; |
| 140 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 141 | class Uint32; |
| 142 | class Utils; |
| 143 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | template <class T> class Handle; |
| 145 | template <class T> class Local; |
| 146 | template <class T> class Persistent; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 147 | class FunctionTemplate; |
| 148 | class ObjectTemplate; |
| 149 | class Data; |
| 150 | class AccessorInfo; |
| 151 | template<typename T> class PropertyCallbackInfo; |
| 152 | class StackTrace; |
| 153 | class StackFrame; |
| 154 | class Isolate; |
| 155 | class DeclaredAccessorDescriptor; |
| 156 | class ObjectOperationDescriptor; |
| 157 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 159 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 160 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 161 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 162 | class HeapObject; |
| 163 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 164 | class Object; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 165 | template<typename T> |
| 166 | class CustomArguments; |
| 167 | class PropertyCallbackArguments; |
| 168 | class FunctionCallbackArguments; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 169 | } |
| 170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 172 | /** |
| 173 | * General purpose unique identifier. |
| 174 | */ |
| 175 | class UniqueId { |
| 176 | public: |
| 177 | explicit UniqueId(intptr_t data) |
| 178 | : data_(data) {} |
| 179 | |
| 180 | bool operator==(const UniqueId& other) const { |
| 181 | return data_ == other.data_; |
| 182 | } |
| 183 | |
| 184 | bool operator!=(const UniqueId& other) const { |
| 185 | return data_ != other.data_; |
| 186 | } |
| 187 | |
| 188 | bool operator<(const UniqueId& other) const { |
| 189 | return data_ < other.data_; |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | intptr_t data_; |
| 194 | }; |
| 195 | |
| 196 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 197 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | |
| 199 | |
| 200 | /** |
| 201 | * A weak reference callback function. |
| 202 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 203 | * This callback should either explicitly invoke Dispose on |object| if |
| 204 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 205 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | * \param object the weak global object to be reclaimed by the garbage collector |
| 207 | * \param parameter the value passed in when making the weak global object |
| 208 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 209 | template<typename T, typename P> |
| 210 | class WeakReferenceCallbacks { |
| 211 | public: |
| 212 | typedef void (*Revivable)(Isolate* isolate, |
| 213 | Persistent<T>* object, |
| 214 | P* parameter); |
| 215 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 217 | // TODO(svenpanne) Temporary definition until Chrome is in sync. |
| 218 | typedef void (*NearDeathCallback)(Isolate* isolate, |
| 219 | Persistent<Value> object, |
| 220 | void* parameter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 222 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 224 | #define TYPE_CHECK(T, S) \ |
| 225 | while (false) { \ |
| 226 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | } |
| 228 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 229 | |
| 230 | #define V8_USE_UNSAFE_HANDLES |
| 231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | /** |
| 233 | * An object reference managed by the v8 garbage collector. |
| 234 | * |
| 235 | * All objects returned from v8 have to be tracked by the garbage |
| 236 | * collector so that it knows that the objects are still alive. Also, |
| 237 | * because the garbage collector may move objects, it is unsafe to |
| 238 | * point directly to an object. Instead, all objects are stored in |
| 239 | * handles which are known by the garbage collector and updated |
| 240 | * whenever an object moves. Handles should always be passed by value |
| 241 | * (except in cases like out-parameters) and they should never be |
| 242 | * allocated on the heap. |
| 243 | * |
| 244 | * There are two types of handles: local and persistent handles. |
| 245 | * Local handles are light-weight and transient and typically used in |
| 246 | * local operations. They are managed by HandleScopes. Persistent |
| 247 | * handles can be used when storing objects across several independent |
| 248 | * operations and have to be explicitly deallocated when they're no |
| 249 | * longer used. |
| 250 | * |
| 251 | * It is safe to extract the object stored in the handle by |
| 252 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 253 | * a Handle<Object>); the value will still be governed by a handle |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 254 | * behind the scenes and the same rules apply to these values as to |
| 255 | * their handles. |
| 256 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 257 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | /** |
| 260 | * Creates an empty handle. |
| 261 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 262 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 264 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | /** |
| 266 | * Creates a new handle for the specified value. |
| 267 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 268 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 269 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Creates a handle for the contents of the specified handle. This |
| 273 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 274 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 276 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | * between compatible handles, for instance assigning a |
| 278 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 279 | * because String is a subclass of Value. |
| 280 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 281 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | : val_(reinterpret_cast<T*>(*that)) { |
| 283 | /** |
| 284 | * This check fails when trying to convert between incompatible |
| 285 | * handles. For example, converting from a Handle<String> to a |
| 286 | * Handle<Number>. |
| 287 | */ |
| 288 | TYPE_CHECK(T, S); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Returns true if the handle is empty. |
| 293 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 294 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | /** |
| 297 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 298 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 299 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 300 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 301 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 302 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 303 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * Checks whether two handles are the same. |
| 307 | * Returns true if both are empty, or if the objects |
| 308 | * to which they refer are identical. |
| 309 | * The handles' references are not checked. |
| 310 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 311 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 312 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 313 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | if (a == 0) return b == 0; |
| 315 | if (b == 0) return false; |
| 316 | return *a == *b; |
| 317 | } |
| 318 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 319 | #ifndef V8_USE_UNSAFE_HANDLES |
| 320 | template <class S> V8_INLINE( |
| 321 | bool operator==(const Persistent<S>& that) const) { |
| 322 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 323 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 324 | if (a == 0) return b == 0; |
| 325 | if (b == 0) return false; |
| 326 | return *a == *b; |
| 327 | } |
| 328 | #endif |
| 329 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | /** |
| 331 | * Checks whether two handles are different. |
| 332 | * Returns true if only one of the handles is empty, or if |
| 333 | * the objects to which they refer are different. |
| 334 | * The handles' references are not checked. |
| 335 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 336 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | return !operator==(that); |
| 338 | } |
| 339 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 340 | template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 341 | #ifdef V8_ENABLE_CHECKS |
| 342 | // If we're going to perform the type check then we have to check |
| 343 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 345 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | return Handle<T>(T::Cast(*that)); |
| 347 | } |
| 348 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 349 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 350 | return Handle<S>::Cast(*this); |
| 351 | } |
| 352 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 353 | #ifndef V8_USE_UNSAFE_HANDLES |
| 354 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 355 | return New(isolate, that.val_); |
| 356 | } |
| 357 | // TODO(dcarney): remove before cutover |
| 358 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 359 | return New(isolate, that.val_); |
| 360 | } |
| 361 | |
| 362 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 365 | #endif |
| 366 | /** |
| 367 | * Creates a new handle for the specified value. |
| 368 | */ |
| 369 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 370 | #endif |
| 371 | |
| 372 | private: |
| 373 | template<class F> |
| 374 | friend class Persistent; |
| 375 | template<class F> |
| 376 | friend class Local; |
| 377 | friend class Arguments; |
| 378 | friend class String; |
| 379 | friend class Object; |
| 380 | friend class AccessorInfo; |
| 381 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 382 | friend Handle<Primitive> Null(Isolate* isolate); |
| 383 | friend Handle<Boolean> True(Isolate* isolate); |
| 384 | friend Handle<Boolean> False(Isolate* isolate); |
| 385 | friend class Context; |
| 386 | friend class InternalHandleHelper; |
| 387 | friend class LocalContext; |
| 388 | |
| 389 | #ifndef V8_USE_UNSAFE_HANDLES |
| 390 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 391 | #endif |
| 392 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | T* val_; |
| 394 | }; |
| 395 | |
| 396 | |
| 397 | /** |
| 398 | * A light-weight stack-allocated object handle. All operations |
| 399 | * that return objects from within v8 return them in local handles. They |
| 400 | * are created within HandleScopes, and all local handles allocated within a |
| 401 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 402 | * is not necessary to explicitly deallocate local handles. |
| 403 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 404 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 405 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 406 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 407 | V8_INLINE(Local()); |
| 408 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 410 | /** |
| 411 | * This check fails when trying to convert between incompatible |
| 412 | * handles. For example, converting from a Handle<String> to a |
| 413 | * Handle<Number>. |
| 414 | */ |
| 415 | TYPE_CHECK(T, S); |
| 416 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 417 | |
| 418 | |
| 419 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 420 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 421 | #endif |
| 422 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 423 | template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 424 | #ifdef V8_ENABLE_CHECKS |
| 425 | // If we're going to perform the type check then we have to check |
| 426 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 428 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | return Local<T>(T::Cast(*that)); |
| 430 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 431 | #ifndef V8_USE_UNSAFE_HANDLES |
| 432 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 433 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 434 | TYPE_CHECK(T, S); |
| 435 | } |
| 436 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 438 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 439 | return Local<S>::Cast(*this); |
| 440 | } |
| 441 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 442 | /** |
| 443 | * Create a local handle for the content of another handle. |
| 444 | * The referee is kept alive by the local handle even when |
| 445 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 447 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 448 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 449 | #ifndef V8_USE_UNSAFE_HANDLES |
| 450 | // TODO(dcarney): remove before cutover |
| 451 | V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 453 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 454 | |
| 455 | private: |
| 456 | #endif |
| 457 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 458 | #endif |
| 459 | |
| 460 | private: |
| 461 | template<class F> |
| 462 | friend class Persistent; |
| 463 | template<class F> |
| 464 | friend class Handle; |
| 465 | friend class Arguments; |
| 466 | friend class String; |
| 467 | friend class Object; |
| 468 | friend class AccessorInfo; |
| 469 | friend class Context; |
| 470 | friend class InternalHandleHelper; |
| 471 | friend class LocalContext; |
| 472 | |
| 473 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 474 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 478 | * a Local handle only lives as long as the HandleScope in which it was |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | * allocated, a Persistent handle remains valid until it is explicitly |
| 480 | * disposed. |
| 481 | * |
| 482 | * A persistent handle contains a reference to a storage cell within |
| 483 | * the v8 engine which holds an object value and which is updated by |
| 484 | * the garbage collector whenever the object is moved. A new storage |
| 485 | * cell can be created using Persistent::New and existing handles can |
| 486 | * be disposed using Persistent::Dispose. Since persistent handles |
| 487 | * are passed by value you may have many persistent handle objects |
| 488 | * that point to the same storage cell. For instance, if you pass a |
| 489 | * persistent handle as an argument to a function you will not get two |
| 490 | * different storage cells but rather two references to the same |
| 491 | * storage cell. |
| 492 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 493 | template <class T> class Persistent // NOLINT |
| 494 | #ifdef V8_USE_UNSAFE_HANDLES |
| 495 | : public Handle<T> { |
| 496 | #else |
| 497 | { // NOLINT |
| 498 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 500 | #ifndef V8_USE_UNSAFE_HANDLES |
| 501 | V8_INLINE(Persistent()) : val_(0) { } |
| 502 | V8_INLINE(~Persistent()) { |
| 503 | // TODO(dcarney): add this back before cutover. |
| 504 | // Dispose(); |
| 505 | } |
| 506 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 507 | // TODO(dcarney): remove somehow before cutover |
| 508 | // The handle should either be 0, or a pointer to a live cell. |
| 509 | V8_INLINE(void Clear()) { val_ = 0; } |
| 510 | |
| 511 | /** |
| 512 | * A constructor that creates a new global cell pointing to that. In contrast |
| 513 | * to the copy constructor, this creates a new persistent handle which needs |
| 514 | * to be separately disposed. |
| 515 | */ |
| 516 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 517 | : val_(*New(isolate, that)) { } |
| 518 | |
| 519 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | /** |
| 521 | * Creates an empty persistent handle that doesn't point to any |
| 522 | * storage cell. |
| 523 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 524 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * Creates a persistent handle for the same storage cell as the |
| 528 | * specified handle. This constructor allows you to pass persistent |
| 529 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 530 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 532 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | * between compatible persistent handles, for instance assigning a |
| 534 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 535 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 537 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 539 | /** |
| 540 | * This check fails when trying to convert between incompatible |
| 541 | * handles. For example, converting from a Handle<String> to a |
| 542 | * Handle<Number>. |
| 543 | */ |
| 544 | TYPE_CHECK(T, S); |
| 545 | } |
| 546 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 547 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 549 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 550 | * A constructor that creates a new global cell pointing to that. In contrast |
| 551 | * to the copy constructor, this creates a new persistent handle which needs |
| 552 | * to be separately disposed. |
| 553 | */ |
| 554 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 555 | : Handle<T>(New(isolate, that)) { } |
| 556 | |
| 557 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 558 | * "Casts" a plain handle which is known to be a persistent handle |
| 559 | * to a persistent handle. |
| 560 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 561 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | : Handle<T>(*that) { } |
| 563 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 564 | #endif |
| 565 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 566 | 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] | 567 | #ifdef V8_ENABLE_CHECKS |
| 568 | // If we're going to perform the type check then we have to check |
| 569 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 571 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | return Persistent<T>(T::Cast(*that)); |
| 573 | } |
| 574 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 575 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 576 | return Persistent<S>::Cast(*this); |
| 577 | } |
| 578 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 579 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 580 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 581 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 582 | * 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] | 583 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 584 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 585 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 586 | #ifndef V8_USE_UNSAFE_HANDLES |
| 587 | // TODO(dcarney): remove before cutover |
| 588 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 589 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 590 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 591 | #ifndef V8_USE_UNSAFE_HANDLES |
| 592 | template <class S> V8_INLINE( |
| 593 | bool operator==(const Persistent<S>& that) const) { |
| 594 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 595 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 596 | if (a == 0) return b == 0; |
| 597 | if (b == 0) return false; |
| 598 | return *a == *b; |
| 599 | } |
| 600 | |
| 601 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 602 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 603 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 604 | if (a == 0) return b == 0; |
| 605 | if (b == 0) return false; |
| 606 | return *a == *b; |
| 607 | } |
| 608 | #endif |
| 609 | |
| 610 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * Releases the storage cell referenced by this persistent handle. |
| 614 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 615 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | * cell remain and IsEmpty will still return false. |
| 617 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 618 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 619 | V8_INLINE(void Dispose(Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 620 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 621 | template<typename S, typename P> |
| 622 | V8_INLINE(void MakeWeak( |
| 623 | Isolate* isolate, |
| 624 | P* parameters, |
| 625 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 626 | |
| 627 | template<typename P> |
| 628 | V8_INLINE(void MakeWeak( |
| 629 | Isolate* isolate, |
| 630 | P* parameters, |
| 631 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 632 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | /** |
| 634 | * Make the reference to this object weak. When only weak handles |
| 635 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 636 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | * it the object reference and the given parameters. |
| 638 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 639 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 640 | V8_INLINE(void MakeWeak(Isolate* isolate, |
| 641 | void* parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 642 | NearDeathCallback callback)); |
| 643 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 644 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 645 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 646 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 647 | V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 648 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 649 | V8_INLINE(void MarkIndependent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 650 | |
| 651 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 652 | * Marks the reference to this object independent. Garbage collector is free |
| 653 | * to ignore any object groups containing this object. Weak callback for an |
| 654 | * independent handle should not assume that it will be preceded by a global |
| 655 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 656 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 657 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 658 | V8_INLINE(void MarkIndependent(Isolate* isolate)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 659 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 660 | V8_INLINE(void MarkPartiallyDependent()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 661 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 662 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 663 | * Marks the reference to this object partially dependent. Partially dependent |
| 664 | * handles only depend on other partially dependent handles and these |
| 665 | * dependencies are provided through object groups. It provides a way to build |
| 666 | * smaller object groups for young objects that represent only a subset of all |
| 667 | * external dependencies. This mark is automatically cleared after each |
| 668 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 669 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 670 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 671 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 672 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 673 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 674 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 675 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 676 | V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 677 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 678 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 679 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 680 | /** Checks if the handle holds the only reference to an object. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 681 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 682 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 683 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 684 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 685 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 686 | /** Returns true if the handle's reference is weak. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 687 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 688 | V8_INLINE(bool IsWeak(Isolate* isolate) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 690 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 691 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 692 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 693 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 694 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 695 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 696 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 697 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 698 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 699 | V8_INLINE(uint16_t WrapperClassId() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 700 | |
| 701 | /** |
| 702 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 703 | * was previously assigned. |
| 704 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 705 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 706 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 707 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 708 | /** |
| 709 | * Disposes the current contents of the handle and replaces it. |
| 710 | */ |
| 711 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 712 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 713 | /** |
| 714 | * Returns the underlying raw pointer and clears the handle. The caller is |
| 715 | * responsible of eventually destroying the underlying object (by creating a |
| 716 | * Persistent handle which points to it and Disposing it). In the future, |
| 717 | * destructing a Persistent will also Dispose it. With this function, the |
| 718 | * embedder can let the Persistent go out of scope without it getting |
| 719 | * disposed. |
| 720 | */ |
| 721 | V8_INLINE(T* ClearAndLeak()); |
| 722 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 723 | #ifndef V8_USE_UNSAFE_HANDLES |
| 724 | |
| 725 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 726 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 727 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 728 | #endif |
| 729 | // TODO(dcarney): make unlinkable before cutover |
| 730 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 731 | // TODO(dcarney): make unlinkable before cutover |
| 732 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 733 | this->val_ = that.val_; |
| 734 | return *this; |
| 735 | } |
| 736 | |
| 737 | public: |
| 738 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 739 | |
| 740 | private: |
| 741 | #endif |
| 742 | // TODO(dcarney): remove before cutover |
| 743 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 744 | // TODO(dcarney): remove before cutover |
| 745 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 746 | : val_(*that) { |
| 747 | TYPE_CHECK(T, S); |
| 748 | } |
| 749 | // TODO(dcarney): remove before cutover |
| 750 | V8_INLINE(T* operator*() const) { return val_; } |
| 751 | public: |
| 752 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 753 | |
| 754 | private: |
| 755 | #endif |
| 756 | // TODO(dcarney): remove before cutover |
| 757 | V8_INLINE(T* operator->() const) { return val_; } |
| 758 | public: |
| 759 | #endif |
| 760 | |
| 761 | private: |
| 762 | template<class F> |
| 763 | friend class Handle; |
| 764 | template<class F> |
| 765 | friend class Local; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | friend class ImplementationUtilities; |
| 767 | friend class ObjectTemplate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 768 | friend class Context; |
| 769 | friend class InternalHandleHelper; |
| 770 | friend class LocalContext; |
| 771 | |
| 772 | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 773 | |
| 774 | #ifndef V8_USE_UNSAFE_HANDLES |
| 775 | T* val_; |
| 776 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | }; |
| 778 | |
| 779 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 780 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | * A stack-allocated class that governs a number of local handles. |
| 782 | * After a handle scope has been created, all local handles will be |
| 783 | * allocated within that handle scope until either the handle scope is |
| 784 | * deleted or another handle scope is created. If there is already a |
| 785 | * 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] | 786 | * 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] | 787 | * new handles will again be allocated in the original handle scope. |
| 788 | * |
| 789 | * After the handle scope of a local handle has been deleted the |
| 790 | * garbage collector will no longer track the object stored in the |
| 791 | * handle and may deallocate it. The behavior of accessing a handle |
| 792 | * for which the handle scope has been deleted is undefined. |
| 793 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 794 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 796 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 797 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 798 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 799 | HandleScope(Isolate* isolate); |
| 800 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 801 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 802 | |
| 803 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | * Closes the handle scope and returns the value as a handle in the |
| 805 | * previous scope, which is the new current scope after the call. |
| 806 | */ |
| 807 | template <class T> Local<T> Close(Handle<T> value); |
| 808 | |
| 809 | /** |
| 810 | * Counts the number of allocated handles. |
| 811 | */ |
| 812 | static int NumberOfHandles(); |
| 813 | |
| 814 | /** |
| 815 | * Creates a new handle with the given value. |
| 816 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 817 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 818 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 819 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 820 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 821 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | |
| 823 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 824 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 825 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | HandleScope(const HandleScope&); |
| 827 | void operator=(const HandleScope&); |
| 828 | void* operator new(size_t size); |
| 829 | void operator delete(void*, size_t); |
| 830 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 831 | // This Data class is accessible internally as HandleScopeData through a |
| 832 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 833 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 834 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 835 | internal::Object** next; |
| 836 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 837 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 838 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 840 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 841 | } |
| 842 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 843 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 844 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 845 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 847 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 848 | internal::Object** prev_next_; |
| 849 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 851 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 852 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 854 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | friend class ImplementationUtilities; |
| 857 | }; |
| 858 | |
| 859 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 860 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 861 | |
| 862 | |
| 863 | /** |
| 864 | * The superclass of values and API object templates. |
| 865 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 866 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | private: |
| 868 | Data(); |
| 869 | }; |
| 870 | |
| 871 | |
| 872 | /** |
| 873 | * Pre-compilation data that can be associated with a script. This |
| 874 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 875 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 876 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 877 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 878 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 879 | public: |
| 880 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 881 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 882 | /** |
| 883 | * Pre-compiles the specified script (context-independent). |
| 884 | * |
| 885 | * \param input Pointer to UTF-8 script source code. |
| 886 | * \param length Length of UTF-8 script source code. |
| 887 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 890 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 891 | * Pre-compiles the specified script (context-independent). |
| 892 | * |
| 893 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 894 | * without using Lockers. |
| 895 | * |
| 896 | * \param source Script source code. |
| 897 | */ |
| 898 | static ScriptData* PreCompile(Handle<String> source); |
| 899 | |
| 900 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 901 | * Load previous pre-compilation data. |
| 902 | * |
| 903 | * \param data Pointer to data returned by a call to Data() of a previous |
| 904 | * ScriptData. Ownership is not transferred. |
| 905 | * \param length Length of data. |
| 906 | */ |
| 907 | static ScriptData* New(const char* data, int length); |
| 908 | |
| 909 | /** |
| 910 | * Returns the length of Data(). |
| 911 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 912 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 913 | |
| 914 | /** |
| 915 | * Returns a serialized representation of this ScriptData that can later be |
| 916 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 917 | */ |
| 918 | virtual const char* Data() = 0; |
| 919 | |
| 920 | /** |
| 921 | * Returns true if the source code could not be parsed. |
| 922 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 923 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | }; |
| 925 | |
| 926 | |
| 927 | /** |
| 928 | * The origin, within a file, of a script. |
| 929 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 930 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 932 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 933 | Handle<Value> resource_name, |
| 934 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 935 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | : resource_name_(resource_name), |
| 937 | resource_line_offset_(resource_line_offset), |
| 938 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 939 | V8_INLINE(Handle<Value> ResourceName() const); |
| 940 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 941 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 943 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 944 | Handle<Integer> resource_line_offset_; |
| 945 | Handle<Integer> resource_column_offset_; |
| 946 | }; |
| 947 | |
| 948 | |
| 949 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 950 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 951 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 952 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 953 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 955 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 956 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 957 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 958 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 959 | * when New() returns |
| 960 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 961 | * using pre_data speeds compilation if it's done multiple times. |
| 962 | * Owned by caller, no references are kept when New() returns. |
| 963 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 964 | * 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] | 965 | * available to compile event handlers. |
| 966 | * \return Compiled script object (context independent; when run it |
| 967 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 969 | static Local<Script> New(Handle<String> source, |
| 970 | ScriptOrigin* origin = NULL, |
| 971 | ScriptData* pre_data = NULL, |
| 972 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 974 | /** |
| 975 | * Compiles the specified script using the specified file name |
| 976 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 977 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 978 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 979 | * \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] | 980 | * as the script's origin. |
| 981 | * \return Compiled script object (context independent; when run it |
| 982 | * will use the currently entered context). |
| 983 | */ |
| 984 | static Local<Script> New(Handle<String> source, |
| 985 | Handle<Value> file_name); |
| 986 | |
| 987 | /** |
| 988 | * Compiles the specified script (bound to current context). |
| 989 | * |
| 990 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 991 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 992 | * when Compile() returns |
| 993 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 994 | * using pre_data speeds compilation if it's done multiple times. |
| 995 | * Owned by caller, no references are kept when Compile() returns. |
| 996 | * \param script_data Arbitrary data associated with script. Using |
| 997 | * this has same effect as calling SetData(), but makes data available |
| 998 | * earlier (i.e. to compile event handlers). |
| 999 | * \return Compiled script object, bound to the context that was active |
| 1000 | * when this function was called. When run it will always use this |
| 1001 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1002 | */ |
| 1003 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1004 | ScriptOrigin* origin = NULL, |
| 1005 | ScriptData* pre_data = NULL, |
| 1006 | Handle<String> script_data = Handle<String>()); |
| 1007 | |
| 1008 | /** |
| 1009 | * Compiles the specified script using the specified file name |
| 1010 | * object (typically a string) as the script's origin. |
| 1011 | * |
| 1012 | * \param source Script source code. |
| 1013 | * \param file_name File name to use as script's origin |
| 1014 | * \param script_data Arbitrary data associated with script. Using |
| 1015 | * this has same effect as calling SetData(), but makes data available |
| 1016 | * earlier (i.e. to compile event handlers). |
| 1017 | * \return Compiled script object, bound to the context that was active |
| 1018 | * when this function was called. When run it will always use this |
| 1019 | * context. |
| 1020 | */ |
| 1021 | static Local<Script> Compile(Handle<String> source, |
| 1022 | Handle<Value> file_name, |
| 1023 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1024 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1025 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1026 | * Runs the script returning the resulting value. If the script is |
| 1027 | * context independent (created using ::New) it will be run in the |
| 1028 | * currently entered context. If it is context specific (created |
| 1029 | * using ::Compile) it will be run in the context in which it was |
| 1030 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1031 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1032 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1033 | |
| 1034 | /** |
| 1035 | * Returns the script id value. |
| 1036 | */ |
| 1037 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1038 | |
| 1039 | /** |
| 1040 | * Associate an additional data object with the script. This is mainly used |
| 1041 | * with the debugger as this data object is only available through the |
| 1042 | * debugger API. |
| 1043 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1044 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1045 | |
| 1046 | /** |
| 1047 | * Returns the name value of one Script. |
| 1048 | */ |
| 1049 | Handle<Value> GetScriptName(); |
| 1050 | |
| 1051 | /** |
| 1052 | * Returns zero based line number of the code_pos location in the script. |
| 1053 | * -1 will be returned if no information available. |
| 1054 | */ |
| 1055 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | }; |
| 1057 | |
| 1058 | |
| 1059 | /** |
| 1060 | * An error message. |
| 1061 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1062 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1063 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1064 | Local<String> Get() const; |
| 1065 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1067 | /** |
| 1068 | * Returns the resource name for the script from where the function causing |
| 1069 | * the error originates. |
| 1070 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1071 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1072 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1073 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1074 | * Returns the resource data for the script from where the function causing |
| 1075 | * the error originates. |
| 1076 | */ |
| 1077 | Handle<Value> GetScriptData() const; |
| 1078 | |
| 1079 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1080 | * Exception stack trace. By default stack traces are not captured for |
| 1081 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1082 | * to change this option. |
| 1083 | */ |
| 1084 | Handle<StackTrace> GetStackTrace() const; |
| 1085 | |
| 1086 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1087 | * Returns the number, 1-based, of the line where the error occurred. |
| 1088 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1089 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1091 | /** |
| 1092 | * Returns the index within the script of the first character where |
| 1093 | * the error occurred. |
| 1094 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1095 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1096 | |
| 1097 | /** |
| 1098 | * Returns the index within the script of the last character where |
| 1099 | * the error occurred. |
| 1100 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1101 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1102 | |
| 1103 | /** |
| 1104 | * Returns the index within the line of the first character where |
| 1105 | * the error occurred. |
| 1106 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1107 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1108 | |
| 1109 | /** |
| 1110 | * Returns the index within the line of the last character where |
| 1111 | * the error occurred. |
| 1112 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1113 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1114 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1115 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1116 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1117 | |
| 1118 | static const int kNoLineNumberInfo = 0; |
| 1119 | static const int kNoColumnInfo = 0; |
| 1120 | }; |
| 1121 | |
| 1122 | |
| 1123 | /** |
| 1124 | * Representation of a JavaScript stack trace. The information collected is a |
| 1125 | * snapshot of the execution stack and the information remains valid after |
| 1126 | * execution continues. |
| 1127 | */ |
| 1128 | class V8EXPORT StackTrace { |
| 1129 | public: |
| 1130 | /** |
| 1131 | * Flags that determine what information is placed captured for each |
| 1132 | * StackFrame when grabbing the current stack trace. |
| 1133 | */ |
| 1134 | enum StackTraceOptions { |
| 1135 | kLineNumber = 1, |
| 1136 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1137 | kScriptName = 1 << 2, |
| 1138 | kFunctionName = 1 << 3, |
| 1139 | kIsEval = 1 << 4, |
| 1140 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1141 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1142 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1143 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1144 | }; |
| 1145 | |
| 1146 | /** |
| 1147 | * Returns a StackFrame at a particular index. |
| 1148 | */ |
| 1149 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1150 | |
| 1151 | /** |
| 1152 | * Returns the number of StackFrames. |
| 1153 | */ |
| 1154 | int GetFrameCount() const; |
| 1155 | |
| 1156 | /** |
| 1157 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1158 | */ |
| 1159 | Local<Array> AsArray(); |
| 1160 | |
| 1161 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1162 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1163 | * |
| 1164 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1165 | * \param options Enumerates the set of things we will capture for each |
| 1166 | * StackFrame. |
| 1167 | */ |
| 1168 | static Local<StackTrace> CurrentStackTrace( |
| 1169 | int frame_limit, |
| 1170 | StackTraceOptions options = kOverview); |
| 1171 | }; |
| 1172 | |
| 1173 | |
| 1174 | /** |
| 1175 | * A single JavaScript stack frame. |
| 1176 | */ |
| 1177 | class V8EXPORT StackFrame { |
| 1178 | public: |
| 1179 | /** |
| 1180 | * Returns the number, 1-based, of the line for the associate function call. |
| 1181 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1182 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1183 | * when capturing the StackTrace. |
| 1184 | */ |
| 1185 | int GetLineNumber() const; |
| 1186 | |
| 1187 | /** |
| 1188 | * Returns the 1-based column offset on the line for the associated function |
| 1189 | * call. |
| 1190 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1191 | * the column number, or if kColumnOffset was not passed as an option when |
| 1192 | * capturing the StackTrace. |
| 1193 | */ |
| 1194 | int GetColumn() const; |
| 1195 | |
| 1196 | /** |
| 1197 | * Returns the name of the resource that contains the script for the |
| 1198 | * function for this StackFrame. |
| 1199 | */ |
| 1200 | Local<String> GetScriptName() const; |
| 1201 | |
| 1202 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1203 | * Returns the name of the resource that contains the script for the |
| 1204 | * function for this StackFrame or sourceURL value if the script name |
| 1205 | * is undefined and its source ends with //@ sourceURL=... string. |
| 1206 | */ |
| 1207 | Local<String> GetScriptNameOrSourceURL() const; |
| 1208 | |
| 1209 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1210 | * Returns the name of the function associated with this stack frame. |
| 1211 | */ |
| 1212 | Local<String> GetFunctionName() const; |
| 1213 | |
| 1214 | /** |
| 1215 | * Returns whether or not the associated function is compiled via a call to |
| 1216 | * eval(). |
| 1217 | */ |
| 1218 | bool IsEval() const; |
| 1219 | |
| 1220 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1221 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1222 | * constructor via "new". |
| 1223 | */ |
| 1224 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1225 | }; |
| 1226 | |
| 1227 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1228 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1229 | |
| 1230 | |
| 1231 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1232 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1233 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1234 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | /** |
| 1237 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1238 | * 4.3.10. |
| 1239 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1240 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1241 | |
| 1242 | /** |
| 1243 | * Returns true if this value is the null value. See ECMA-262 |
| 1244 | * 4.3.11. |
| 1245 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1246 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1247 | |
| 1248 | /** |
| 1249 | * Returns true if this value is true. |
| 1250 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1251 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1252 | |
| 1253 | /** |
| 1254 | * Returns true if this value is false. |
| 1255 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1256 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1257 | |
| 1258 | /** |
| 1259 | * Returns true if this value is an instance of the String type. |
| 1260 | * See ECMA-262 8.4. |
| 1261 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1262 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1263 | |
| 1264 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1265 | * Returns true if this value is a symbol. |
| 1266 | * This is an experimental feature. |
| 1267 | */ |
| 1268 | bool IsSymbol() const; |
| 1269 | |
| 1270 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | * Returns true if this value is a function. |
| 1272 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1273 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | |
| 1275 | /** |
| 1276 | * Returns true if this value is an array. |
| 1277 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1278 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1279 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1280 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | * Returns true if this value is an object. |
| 1282 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1283 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1285 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1286 | * Returns true if this value is boolean. |
| 1287 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1288 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1289 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1290 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1291 | * Returns true if this value is a number. |
| 1292 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1293 | bool IsNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1294 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1295 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | * Returns true if this value is external. |
| 1297 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1298 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1299 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1300 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | * Returns true if this value is a 32-bit signed integer. |
| 1302 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1303 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1305 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1306 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1307 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1308 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1309 | |
| 1310 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1311 | * Returns true if this value is a Date. |
| 1312 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1313 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1314 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1315 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1316 | * Returns true if this value is a Boolean object. |
| 1317 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1318 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1319 | |
| 1320 | /** |
| 1321 | * Returns true if this value is a Number object. |
| 1322 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1323 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1324 | |
| 1325 | /** |
| 1326 | * Returns true if this value is a String object. |
| 1327 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1328 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1329 | |
| 1330 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1331 | * Returns true if this value is a Symbol object. |
| 1332 | * This is an experimental feature. |
| 1333 | */ |
| 1334 | bool IsSymbolObject() const; |
| 1335 | |
| 1336 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1337 | * Returns true if this value is a NativeError. |
| 1338 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1339 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1340 | |
| 1341 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1342 | * Returns true if this value is a RegExp. |
| 1343 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1344 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1345 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1346 | |
| 1347 | /** |
| 1348 | * Returns true if this value is an ArrayBuffer. |
| 1349 | * This is an experimental feature. |
| 1350 | */ |
| 1351 | bool IsArrayBuffer() const; |
| 1352 | |
| 1353 | /** |
| 1354 | * Returns true if this value is one of TypedArrays. |
| 1355 | * This is an experimental feature. |
| 1356 | */ |
| 1357 | bool IsTypedArray() const; |
| 1358 | |
| 1359 | /** |
| 1360 | * Returns true if this value is an Uint8Array. |
| 1361 | * This is an experimental feature. |
| 1362 | */ |
| 1363 | bool IsUint8Array() const; |
| 1364 | |
| 1365 | /** |
| 1366 | * Returns true if this value is an Uint8ClampedArray. |
| 1367 | * This is an experimental feature. |
| 1368 | */ |
| 1369 | bool IsUint8ClampedArray() const; |
| 1370 | |
| 1371 | /** |
| 1372 | * Returns true if this value is an Int8Array. |
| 1373 | * This is an experimental feature. |
| 1374 | */ |
| 1375 | bool IsInt8Array() const; |
| 1376 | |
| 1377 | /** |
| 1378 | * Returns true if this value is an Uint16Array. |
| 1379 | * This is an experimental feature. |
| 1380 | */ |
| 1381 | bool IsUint16Array() const; |
| 1382 | |
| 1383 | /** |
| 1384 | * Returns true if this value is an Int16Array. |
| 1385 | * This is an experimental feature. |
| 1386 | */ |
| 1387 | bool IsInt16Array() const; |
| 1388 | |
| 1389 | /** |
| 1390 | * Returns true if this value is an Uint32Array. |
| 1391 | * This is an experimental feature. |
| 1392 | */ |
| 1393 | bool IsUint32Array() const; |
| 1394 | |
| 1395 | /** |
| 1396 | * Returns true if this value is an Int32Array. |
| 1397 | * This is an experimental feature. |
| 1398 | */ |
| 1399 | bool IsInt32Array() const; |
| 1400 | |
| 1401 | /** |
| 1402 | * Returns true if this value is a Float32Array. |
| 1403 | * This is an experimental feature. |
| 1404 | */ |
| 1405 | bool IsFloat32Array() const; |
| 1406 | |
| 1407 | /** |
| 1408 | * Returns true if this value is a Float64Array. |
| 1409 | * This is an experimental feature. |
| 1410 | */ |
| 1411 | bool IsFloat64Array() const; |
| 1412 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1413 | Local<Boolean> ToBoolean() const; |
| 1414 | Local<Number> ToNumber() const; |
| 1415 | Local<String> ToString() const; |
| 1416 | Local<String> ToDetailString() const; |
| 1417 | Local<Object> ToObject() const; |
| 1418 | Local<Integer> ToInteger() const; |
| 1419 | Local<Uint32> ToUint32() const; |
| 1420 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1421 | |
| 1422 | /** |
| 1423 | * Attempts to convert a string to an array index. |
| 1424 | * Returns an empty handle if the conversion fails. |
| 1425 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1426 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1427 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1428 | bool BooleanValue() const; |
| 1429 | double NumberValue() const; |
| 1430 | int64_t IntegerValue() const; |
| 1431 | uint32_t Uint32Value() const; |
| 1432 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1433 | |
| 1434 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1435 | bool Equals(Handle<Value> that) const; |
| 1436 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1437 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1438 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1439 | V8_INLINE(bool QuickIsUndefined() const); |
| 1440 | V8_INLINE(bool QuickIsNull() const); |
| 1441 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1442 | bool FullIsUndefined() const; |
| 1443 | bool FullIsNull() const; |
| 1444 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1445 | }; |
| 1446 | |
| 1447 | |
| 1448 | /** |
| 1449 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1450 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1451 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | |
| 1453 | |
| 1454 | /** |
| 1455 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1456 | * or false value. |
| 1457 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1458 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1459 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1460 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1461 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | }; |
| 1463 | |
| 1464 | |
| 1465 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1466 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1467 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1468 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1470 | enum Encoding { |
| 1471 | UNKNOWN_ENCODING = 0x1, |
| 1472 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1473 | ASCII_ENCODING = 0x4, |
| 1474 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1475 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1476 | /** |
| 1477 | * Returns the number of characters in this string. |
| 1478 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1479 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1480 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1481 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1482 | * Returns the number of bytes in the UTF-8 encoded |
| 1483 | * representation of this string. |
| 1484 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1485 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1486 | |
| 1487 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1488 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1489 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1490 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1491 | |
| 1492 | /** |
| 1493 | * Returns whether this string contains only one byte data. |
| 1494 | */ |
| 1495 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1496 | |
| 1497 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1498 | * Write the contents of the string to an external buffer. |
| 1499 | * If no arguments are given, expects the buffer to be large |
| 1500 | * enough to hold the entire string and NULL terminator. Copies |
| 1501 | * the contents of the string and the NULL terminator into the |
| 1502 | * buffer. |
| 1503 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1504 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1505 | * before the end of the buffer. |
| 1506 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1507 | * Copies up to length characters into the output buffer. |
| 1508 | * Only null-terminates if there is enough space in the buffer. |
| 1509 | * |
| 1510 | * \param buffer The buffer into which the string will be copied. |
| 1511 | * \param start The starting position within the string at which |
| 1512 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1513 | * \param length The number of characters to copy from the string. For |
| 1514 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1515 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1516 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1517 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1518 | * \return The number of characters copied to the buffer excluding the null |
| 1519 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1520 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1521 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1522 | enum WriteOptions { |
| 1523 | NO_OPTIONS = 0, |
| 1524 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1525 | NO_NULL_TERMINATION = 2, |
| 1526 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1527 | }; |
| 1528 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1529 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1530 | int Write(uint16_t* buffer, |
| 1531 | int start = 0, |
| 1532 | int length = -1, |
| 1533 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1534 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1535 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1536 | int start = 0, |
| 1537 | int length = -1, |
| 1538 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1539 | // One byte characters. |
| 1540 | int WriteOneByte(uint8_t* buffer, |
| 1541 | int start = 0, |
| 1542 | int length = -1, |
| 1543 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1544 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1545 | int WriteUtf8(char* buffer, |
| 1546 | int length = -1, |
| 1547 | int* nchars_ref = NULL, |
| 1548 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1549 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1550 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1551 | * A zero length string. |
| 1552 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1553 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1554 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1555 | |
| 1556 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1557 | * Returns true if the string is external |
| 1558 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1559 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1560 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1561 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1562 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1563 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1564 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1565 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1566 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1567 | public: |
| 1568 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1569 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1570 | protected: |
| 1571 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1572 | |
| 1573 | /** |
| 1574 | * Internally V8 will call this Dispose method when the external string |
| 1575 | * resource is no longer needed. The default implementation will use the |
| 1576 | * delete operator. This method can be overridden in subclasses to |
| 1577 | * control how allocated external string resources are disposed. |
| 1578 | */ |
| 1579 | virtual void Dispose() { delete this; } |
| 1580 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1581 | private: |
| 1582 | // Disallow copying and assigning. |
| 1583 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1584 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1585 | |
| 1586 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1587 | }; |
| 1588 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1589 | /** |
| 1590 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1591 | * buffer that resides outside V8's heap. Implement an |
| 1592 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1593 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1594 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1595 | class V8EXPORT ExternalStringResource |
| 1596 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1597 | public: |
| 1598 | /** |
| 1599 | * Override the destructor to manage the life cycle of the underlying |
| 1600 | * buffer. |
| 1601 | */ |
| 1602 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1603 | |
| 1604 | /** |
| 1605 | * The string data from the underlying buffer. |
| 1606 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1607 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1608 | |
| 1609 | /** |
| 1610 | * The length of the string. That is, the number of two-byte characters. |
| 1611 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1613 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1614 | protected: |
| 1615 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1616 | }; |
| 1617 | |
| 1618 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1619 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1620 | * string buffer that resides outside V8's heap. Implement an |
| 1621 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1622 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1623 | * 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] | 1624 | * UTF-8, which would require special treatment internally in the |
| 1625 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1626 | * 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] | 1627 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1628 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1629 | class V8EXPORT ExternalAsciiStringResource |
| 1630 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1631 | public: |
| 1632 | /** |
| 1633 | * Override the destructor to manage the life cycle of the underlying |
| 1634 | * buffer. |
| 1635 | */ |
| 1636 | virtual ~ExternalAsciiStringResource() {} |
| 1637 | /** The string data from the underlying buffer.*/ |
| 1638 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1639 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1640 | virtual size_t length() const = 0; |
| 1641 | protected: |
| 1642 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1643 | }; |
| 1644 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1645 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1646 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1647 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1648 | * If the string is an external string, return the ExternalStringResourceBase |
| 1649 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1650 | * string is returned in encoding_out. |
| 1651 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1652 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1653 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1654 | |
| 1655 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1656 | * Get the ExternalStringResource for an external string. Returns |
| 1657 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1658 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1659 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | |
| 1661 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1662 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1663 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1664 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1665 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1666 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1667 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1668 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1669 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1670 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1671 | * 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] | 1672 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1673 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1674 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1675 | 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] | 1676 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1677 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1678 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1679 | 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] | 1680 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1681 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1682 | /** |
| 1683 | * Creates an internalized string (historically called a "symbol", |
| 1684 | * 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] | 1685 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1686 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1687 | |
| 1688 | enum NewStringType { |
| 1689 | kNormalString, kInternalizedString, kUndetectableString |
| 1690 | }; |
| 1691 | |
| 1692 | /** Allocates a new string from UTF-8 data.*/ |
| 1693 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1694 | const char* data, |
| 1695 | NewStringType type = kNormalString, |
| 1696 | int length = -1); |
| 1697 | |
| 1698 | /** Allocates a new string from Latin-1 data.*/ |
| 1699 | static Local<String> NewFromOneByte( |
| 1700 | Isolate* isolate, |
| 1701 | const uint8_t* data, |
| 1702 | NewStringType type = kNormalString, |
| 1703 | int length = -1); |
| 1704 | |
| 1705 | /** Allocates a new string from UTF-16 data.*/ |
| 1706 | static Local<String> NewFromTwoByte( |
| 1707 | Isolate* isolate, |
| 1708 | const uint16_t* data, |
| 1709 | NewStringType type = kNormalString, |
| 1710 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1711 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1712 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1713 | * Creates a new string by concatenating the left and the right strings |
| 1714 | * passed in as parameters. |
| 1715 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1716 | 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] | 1717 | |
| 1718 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1719 | * 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] | 1720 | * 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] | 1721 | * resource will be disposed by calling its Dispose method. The caller of |
| 1722 | * this function should not otherwise delete or modify the resource. Neither |
| 1723 | * should the underlying buffer be deallocated or modified except through the |
| 1724 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1725 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1726 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1727 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1728 | /** |
| 1729 | * Associate an external string resource with this string by transforming it |
| 1730 | * in place so that existing references to this string in the JavaScript heap |
| 1731 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1732 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1733 | * 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] | 1734 | * The string is not modified if the operation fails. See NewExternal for |
| 1735 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1736 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1737 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1738 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1739 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1740 | * 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] | 1741 | * 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] | 1742 | * resource will be disposed by calling its Dispose method. The caller of |
| 1743 | * this function should not otherwise delete or modify the resource. Neither |
| 1744 | * should the underlying buffer be deallocated or modified except through the |
| 1745 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1746 | */ |
| 1747 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1748 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1749 | /** |
| 1750 | * Associate an external string resource with this string by transforming it |
| 1751 | * in place so that existing references to this string in the JavaScript heap |
| 1752 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1753 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1754 | * 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] | 1755 | * The string is not modified if the operation fails. See NewExternal for |
| 1756 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1757 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1758 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1759 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1760 | /** |
| 1761 | * Returns true if this string can be made external. |
| 1762 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1763 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1764 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1765 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1766 | /** 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] | 1767 | V8_INLINE( |
| 1768 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1770 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1771 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1772 | V8_INLINE(static Local<String> NewUndetectable( |
| 1773 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1774 | |
| 1775 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1776 | * 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] | 1777 | * 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] | 1778 | * (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] | 1779 | * then the length() method returns 0 and the * operator returns |
| 1780 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1781 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1782 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1783 | public: |
| 1784 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1785 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1786 | char* operator*() { return str_; } |
| 1787 | const char* operator*() const { return str_; } |
| 1788 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1789 | private: |
| 1790 | char* str_; |
| 1791 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Disallow copying and assigning. |
| 1794 | Utf8Value(const Utf8Value&); |
| 1795 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1796 | }; |
| 1797 | |
| 1798 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1799 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1800 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1801 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1802 | * method of the object) then the length() method returns 0 and the * operator |
| 1803 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1805 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1806 | public: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1807 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1809 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1810 | char* operator*() { return str_; } |
| 1811 | const char* operator*() const { return str_; } |
| 1812 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1813 | private: |
| 1814 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1815 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Disallow copying and assigning. |
| 1818 | AsciiValue(const AsciiValue&); |
| 1819 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | }; |
| 1821 | |
| 1822 | /** |
| 1823 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1824 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1825 | * method of the object) then the length() method returns 0 and the * operator |
| 1826 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1828 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1829 | public: |
| 1830 | explicit Value(Handle<v8::Value> obj); |
| 1831 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1832 | uint16_t* operator*() { return str_; } |
| 1833 | const uint16_t* operator*() const { return str_; } |
| 1834 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1835 | private: |
| 1836 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1837 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1838 | |
| 1839 | // Disallow copying and assigning. |
| 1840 | Value(const Value&); |
| 1841 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1842 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1843 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1844 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1845 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1846 | Encoding encoding) const; |
| 1847 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1848 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | }; |
| 1850 | |
| 1851 | |
| 1852 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1853 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1854 | * |
| 1855 | * This is an experimental feature. Use at your own risk. |
| 1856 | */ |
| 1857 | class V8EXPORT Symbol : public Primitive { |
| 1858 | public: |
| 1859 | // Returns the print name string of the symbol, or undefined if none. |
| 1860 | Local<Value> Name() const; |
| 1861 | |
| 1862 | // Create a symbol without a print name. |
| 1863 | static Local<Symbol> New(Isolate* isolate); |
| 1864 | |
| 1865 | // Create a symbol with a print name. |
| 1866 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1867 | |
| 1868 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1869 | private: |
| 1870 | Symbol(); |
| 1871 | static void CheckCast(v8::Value* obj); |
| 1872 | }; |
| 1873 | |
| 1874 | |
| 1875 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1876 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1877 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1878 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1879 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1880 | double Value() const; |
| 1881 | static Local<Number> New(double value); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1882 | static Local<Number> New(Isolate* isolate, double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1883 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1885 | Number(); |
| 1886 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | }; |
| 1888 | |
| 1889 | |
| 1890 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1891 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1892 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1893 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1895 | static Local<Integer> New(int32_t value); |
| 1896 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1897 | static Local<Integer> New(int32_t value, Isolate*); |
| 1898 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1899 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1900 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1901 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1902 | Integer(); |
| 1903 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | }; |
| 1905 | |
| 1906 | |
| 1907 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1908 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1909 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1910 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1912 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1913 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1914 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1915 | }; |
| 1916 | |
| 1917 | |
| 1918 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1919 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1920 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1921 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1922 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1923 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1925 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1926 | }; |
| 1927 | |
| 1928 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | enum PropertyAttribute { |
| 1930 | None = 0, |
| 1931 | ReadOnly = 1 << 0, |
| 1932 | DontEnum = 1 << 1, |
| 1933 | DontDelete = 1 << 2 |
| 1934 | }; |
| 1935 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1936 | enum ExternalArrayType { |
| 1937 | kExternalByteArray = 1, |
| 1938 | kExternalUnsignedByteArray, |
| 1939 | kExternalShortArray, |
| 1940 | kExternalUnsignedShortArray, |
| 1941 | kExternalIntArray, |
| 1942 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1943 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1944 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1945 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1946 | }; |
| 1947 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1949 | * Accessor[Getter|Setter] are used as callback functions when |
| 1950 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1951 | * method SetAccessor. |
| 1952 | */ |
| 1953 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1954 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1955 | typedef void (*AccessorGetterCallback)( |
| 1956 | Local<String> property, |
| 1957 | const PropertyCallbackInfo<Value>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1958 | |
| 1959 | |
| 1960 | typedef void (*AccessorSetter)(Local<String> property, |
| 1961 | Local<Value> value, |
| 1962 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1963 | typedef void (*AccessorSetterCallback)( |
| 1964 | Local<String> property, |
| 1965 | Local<Value> value, |
| 1966 | const PropertyCallbackInfo<void>& info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1967 | |
| 1968 | |
| 1969 | /** |
| 1970 | * Access control specifications. |
| 1971 | * |
| 1972 | * Some accessors should be accessible across contexts. These |
| 1973 | * accessors have an explicit access control parameter which specifies |
| 1974 | * the kind of cross-context access that should be allowed. |
| 1975 | * |
| 1976 | * Additionally, for security, accessors can prohibit overwriting by |
| 1977 | * accessors defined in JavaScript. For objects that have such |
| 1978 | * accessors either locally or in their prototype chain it is not |
| 1979 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1980 | * __defineSetter__ from JavaScript code. |
| 1981 | */ |
| 1982 | enum AccessControl { |
| 1983 | DEFAULT = 0, |
| 1984 | ALL_CAN_READ = 1, |
| 1985 | ALL_CAN_WRITE = 1 << 1, |
| 1986 | PROHIBITS_OVERWRITING = 1 << 2 |
| 1987 | }; |
| 1988 | |
| 1989 | |
| 1990 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1991 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1992 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1993 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1994 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1995 | bool Set(Handle<Value> key, |
| 1996 | Handle<Value> value, |
| 1997 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1998 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1999 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2000 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2001 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2002 | // overriding accessors or read-only properties. |
| 2003 | // |
| 2004 | // Note that if the object has an interceptor the property will be set |
| 2005 | // locally, but since the interceptor takes precedence the local property |
| 2006 | // will only be returned if the interceptor doesn't return a value. |
| 2007 | // |
| 2008 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2009 | bool ForceSet(Handle<Value> key, |
| 2010 | Handle<Value> value, |
| 2011 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2012 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2013 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2014 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2015 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2016 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2017 | /** |
| 2018 | * Gets the property attributes of a property which can be None or |
| 2019 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 2020 | * None when the property doesn't exist. |
| 2021 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2022 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2023 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2024 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2025 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2026 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2027 | |
| 2028 | // Delete a property on this object bypassing interceptors and |
| 2029 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2030 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2031 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2032 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2033 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2034 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2035 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2036 | // TODO(dcarney): deprecate |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2037 | bool SetAccessor(Handle<String> name, |
| 2038 | AccessorGetter getter, |
| 2039 | AccessorSetter setter = 0, |
| 2040 | Handle<Value> data = Handle<Value>(), |
| 2041 | AccessControl settings = DEFAULT, |
| 2042 | PropertyAttribute attribute = None); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2043 | bool SetAccessor(Handle<String> name, |
| 2044 | AccessorGetterCallback getter, |
| 2045 | AccessorSetterCallback setter = 0, |
| 2046 | Handle<Value> data = Handle<Value>(), |
| 2047 | AccessControl settings = DEFAULT, |
| 2048 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2049 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2050 | // This function is not yet stable and should not be used at this time. |
| 2051 | bool SetAccessor(Handle<String> name, |
| 2052 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2053 | AccessControl settings = DEFAULT, |
| 2054 | PropertyAttribute attribute = None); |
| 2055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2057 | * Returns an array containing the names of the enumerable properties |
| 2058 | * of this object, including properties from prototype objects. The |
| 2059 | * array returned by this method contains the same values as would |
| 2060 | * be enumerated by a for-in statement over this object. |
| 2061 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2062 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2063 | |
| 2064 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2065 | * This function has the same functionality as GetPropertyNames but |
| 2066 | * the returned array doesn't contain the names of properties from |
| 2067 | * prototype objects. |
| 2068 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2069 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2070 | |
| 2071 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2072 | * Get the prototype object. This does not skip objects marked to |
| 2073 | * be skipped by __proto__ and it does not consult the security |
| 2074 | * handler. |
| 2075 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2076 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | |
| 2078 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2079 | * Set the prototype object. This does not skip objects marked to |
| 2080 | * be skipped by __proto__ and it does not consult the security |
| 2081 | * handler. |
| 2082 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2083 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2084 | |
| 2085 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2086 | * Finds an instance of the given function template in the prototype |
| 2087 | * chain. |
| 2088 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2089 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2090 | |
| 2091 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | * Call builtin Object.prototype.toString on this object. |
| 2093 | * This is different from Value::ToString() that may call |
| 2094 | * user-defined toString function. This one does not. |
| 2095 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2096 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2097 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2098 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2099 | * Returns the function invoked as a constructor for this object. |
| 2100 | * May be the null value. |
| 2101 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2102 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2103 | |
| 2104 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2105 | * Returns the name of the function invoked as a constructor for this object. |
| 2106 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2107 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2108 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2109 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2110 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2111 | |
| 2112 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2113 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2114 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2115 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2116 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2117 | |
| 2118 | /** |
| 2119 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2120 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2121 | * leads to undefined behavior. |
| 2122 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2123 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2124 | |
| 2125 | /** |
| 2126 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2127 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2128 | * leads to undefined behavior. |
| 2129 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2130 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2132 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2133 | bool HasOwnProperty(Handle<String> key); |
| 2134 | bool HasRealNamedProperty(Handle<String> key); |
| 2135 | bool HasRealIndexedProperty(uint32_t index); |
| 2136 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2137 | |
| 2138 | /** |
| 2139 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2140 | * This means interceptors in the prototype chain are not called. |
| 2141 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2142 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2143 | |
| 2144 | /** |
| 2145 | * If result.IsEmpty() no real property was located on the object or |
| 2146 | * in the prototype chain. |
| 2147 | * This means interceptors in the prototype chain are not called. |
| 2148 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2149 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2150 | |
| 2151 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2152 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2153 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2154 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2155 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2156 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2157 | /** |
| 2158 | * Turns on access check on the object if the object is an instance of |
| 2159 | * a template that has access check callbacks. If an object has no |
| 2160 | * access check info, the object cannot be accessed by anyone. |
| 2161 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2162 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2163 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2164 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2165 | * Returns the identity hash for this object. The current implementation |
| 2166 | * 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] | 2167 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2168 | * 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] | 2169 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2170 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2171 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2172 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2173 | /** |
| 2174 | * Access hidden properties on JavaScript objects. These properties are |
| 2175 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2176 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2177 | * identity hash) are prefixed with "v8::". |
| 2178 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2179 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2180 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2181 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2182 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2183 | /** |
| 2184 | * Returns true if this is an instance of an api function (one |
| 2185 | * created from a function created from a function template) and has |
| 2186 | * been modified since it was created. Note that this method is |
| 2187 | * conservative and may return true for objects that haven't actually |
| 2188 | * been modified. |
| 2189 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2190 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2191 | |
| 2192 | /** |
| 2193 | * Clone this object with a fast but shallow copy. Values will point |
| 2194 | * to the same values as the original object. |
| 2195 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2196 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2197 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2198 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2199 | * Returns the context in which the object was created. |
| 2200 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2201 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2202 | |
| 2203 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2204 | * Set the backing store of the indexed properties to be managed by the |
| 2205 | * embedding layer. Access to the indexed properties will follow the rules |
| 2206 | * spelled out in CanvasPixelArray. |
| 2207 | * Note: The embedding program still owns the data and needs to ensure that |
| 2208 | * the backing store is preserved while V8 has a reference. |
| 2209 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2210 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2211 | bool HasIndexedPropertiesInPixelData(); |
| 2212 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2213 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2214 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2215 | /** |
| 2216 | * Set the backing store of the indexed properties to be managed by the |
| 2217 | * embedding layer. Access to the indexed properties will follow the rules |
| 2218 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2219 | * Note: The embedding program still owns the data and needs to ensure that |
| 2220 | * the backing store is preserved while V8 has a reference. |
| 2221 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2222 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2223 | ExternalArrayType array_type, |
| 2224 | int number_of_elements); |
| 2225 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2226 | void* GetIndexedPropertiesExternalArrayData(); |
| 2227 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2228 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2229 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2230 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2231 | * Checks whether a callback is set by the |
| 2232 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2233 | * When an Object is callable this method returns true. |
| 2234 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2235 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2236 | |
| 2237 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2238 | * 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] | 2239 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2240 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2241 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2242 | int argc, |
| 2243 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2244 | |
| 2245 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2246 | * 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] | 2247 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2248 | * Note: This method behaves like the Function::NewInstance method. |
| 2249 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2250 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2251 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2252 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2253 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2255 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2256 | Object(); |
| 2257 | static void CheckCast(Value* obj); |
| 2258 | Local<Value> SlowGetInternalField(int index); |
| 2259 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2260 | }; |
| 2261 | |
| 2262 | |
| 2263 | /** |
| 2264 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2265 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2266 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2267 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2268 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2270 | /** |
| 2271 | * Clones an element at index |index|. Returns an empty |
| 2272 | * handle if cloning fails (for any reason). |
| 2273 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2274 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2275 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2276 | /** |
| 2277 | * Creates a JavaScript array with the given length. If the length |
| 2278 | * is negative the returned array will have length 0. |
| 2279 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2280 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2281 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2282 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2283 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2284 | Array(); |
| 2285 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | }; |
| 2287 | |
| 2288 | |
| 2289 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2290 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2291 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2292 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2293 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2294 | Local<Object> NewInstance() const; |
| 2295 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2296 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2297 | void SetName(Handle<String> name); |
| 2298 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2299 | |
| 2300 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2301 | * Name inferred from variable or property assignment of this function. |
| 2302 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2303 | * in an OO style, where many functions are anonymous but are assigned |
| 2304 | * to object properties. |
| 2305 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2306 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2307 | |
| 2308 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2309 | * Returns zero based line number of function body and |
| 2310 | * kLineOffsetNotFound if no information available. |
| 2311 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2312 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2313 | /** |
| 2314 | * Returns zero based column number of function body and |
| 2315 | * kLineOffsetNotFound if no information available. |
| 2316 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2317 | int GetScriptColumnNumber() const; |
| 2318 | Handle<Value> GetScriptId() const; |
| 2319 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2320 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2321 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2322 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2323 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2324 | Function(); |
| 2325 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2326 | }; |
| 2327 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 2328 | /** |
| 2329 | * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 2330 | * populates an instance of this class with a pointer to data and byte length. |
| 2331 | * |
| 2332 | * |ArrayBufferContents| is the owner of its data. When an instance of |
| 2333 | * this class is destructed, the |Data| is freed. |
| 2334 | * |
| 2335 | * This API is experimental and may change significantly. |
| 2336 | */ |
| 2337 | class V8EXPORT ArrayBufferContents { |
| 2338 | public: |
| 2339 | ArrayBufferContents() : data_(NULL), byte_length_(0) {} |
| 2340 | ~ArrayBufferContents(); |
| 2341 | |
| 2342 | void* Data() const { return data_; } |
| 2343 | size_t ByteLength() const { return byte_length_; } |
| 2344 | |
| 2345 | private: |
| 2346 | void* data_; |
| 2347 | size_t byte_length_; |
| 2348 | |
| 2349 | friend class ArrayBuffer; |
| 2350 | }; |
| 2351 | |
| 2352 | #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
| 2353 | #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
| 2354 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | |
| 2356 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2357 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2358 | * This API is experimental and may change significantly. |
| 2359 | */ |
| 2360 | class V8EXPORT ArrayBuffer : public Object { |
| 2361 | public: |
| 2362 | /** |
| 2363 | * Data length in bytes. |
| 2364 | */ |
| 2365 | size_t ByteLength() const; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2366 | |
| 2367 | /** |
| 2368 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2369 | * Allocated memory will be owned by a created ArrayBuffer and |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 2370 | * will be deallocated when it is garbage-collected, |
| 2371 | * unless the object is externalized. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2372 | */ |
| 2373 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2374 | |
| 2375 | /** |
| 2376 | * Create a new ArrayBuffer over an existing memory block. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 2377 | * The created array buffer is immediately in externalized state. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2378 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2379 | * is garbage-collected. |
| 2380 | */ |
| 2381 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2382 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 2383 | /** |
| 2384 | * Returns true if ArrayBuffer is extrenalized, that is, does not |
| 2385 | * own its memory block. |
| 2386 | */ |
| 2387 | bool IsExternal() const; |
| 2388 | |
| 2389 | /** |
| 2390 | * Pass the ownership of this ArrayBuffer's backing store to |
| 2391 | * a given ArrayBufferContents. |
| 2392 | */ |
| 2393 | void Externalize(ArrayBufferContents* contents); |
| 2394 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2395 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2396 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 2397 | |
| 2398 | static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
| 2399 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2400 | private: |
| 2401 | ArrayBuffer(); |
| 2402 | static void CheckCast(Value* obj); |
| 2403 | }; |
| 2404 | |
| 2405 | |
| 2406 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2407 | * A base class for an instance of TypedArray series of constructors |
| 2408 | * (ES6 draft 15.13.6). |
| 2409 | * This API is experimental and may change significantly. |
| 2410 | */ |
| 2411 | class V8EXPORT TypedArray : public Object { |
| 2412 | public: |
| 2413 | /** |
| 2414 | * Returns underlying ArrayBuffer. |
| 2415 | */ |
| 2416 | Local<ArrayBuffer> Buffer(); |
| 2417 | /** |
| 2418 | * Byte offset in |Buffer| |
| 2419 | */ |
| 2420 | size_t ByteOffset(); |
| 2421 | /** |
| 2422 | * Numbe of elements in this typed array. |
| 2423 | */ |
| 2424 | size_t Length(); |
| 2425 | /** |
| 2426 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2427 | */ |
| 2428 | size_t ByteLength(); |
| 2429 | /** |
| 2430 | * Base address of typed array. |
| 2431 | */ |
| 2432 | void* BaseAddress(); |
| 2433 | |
| 2434 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2435 | |
| 2436 | private: |
| 2437 | TypedArray(); |
| 2438 | static void CheckCast(Value* obj); |
| 2439 | }; |
| 2440 | |
| 2441 | |
| 2442 | /** |
| 2443 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2444 | * This API is experimental and may change significantly. |
| 2445 | */ |
| 2446 | class V8EXPORT Uint8Array : public TypedArray { |
| 2447 | public: |
| 2448 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2449 | size_t byte_offset, size_t length); |
| 2450 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2451 | |
| 2452 | private: |
| 2453 | Uint8Array(); |
| 2454 | static void CheckCast(Value* obj); |
| 2455 | }; |
| 2456 | |
| 2457 | |
| 2458 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2459 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2460 | * This API is experimental and may change significantly. |
| 2461 | */ |
| 2462 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2463 | public: |
| 2464 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2465 | size_t byte_offset, size_t length); |
| 2466 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2467 | |
| 2468 | private: |
| 2469 | Uint8ClampedArray(); |
| 2470 | static void CheckCast(Value* obj); |
| 2471 | }; |
| 2472 | |
| 2473 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2474 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2475 | * This API is experimental and may change significantly. |
| 2476 | */ |
| 2477 | class V8EXPORT Int8Array : public TypedArray { |
| 2478 | public: |
| 2479 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2480 | size_t byte_offset, size_t length); |
| 2481 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2482 | |
| 2483 | private: |
| 2484 | Int8Array(); |
| 2485 | static void CheckCast(Value* obj); |
| 2486 | }; |
| 2487 | |
| 2488 | |
| 2489 | /** |
| 2490 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2491 | * This API is experimental and may change significantly. |
| 2492 | */ |
| 2493 | class V8EXPORT Uint16Array : public TypedArray { |
| 2494 | public: |
| 2495 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2496 | size_t byte_offset, size_t length); |
| 2497 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2498 | |
| 2499 | private: |
| 2500 | Uint16Array(); |
| 2501 | static void CheckCast(Value* obj); |
| 2502 | }; |
| 2503 | |
| 2504 | |
| 2505 | /** |
| 2506 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2507 | * This API is experimental and may change significantly. |
| 2508 | */ |
| 2509 | class V8EXPORT Int16Array : public TypedArray { |
| 2510 | public: |
| 2511 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2512 | size_t byte_offset, size_t length); |
| 2513 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2514 | |
| 2515 | private: |
| 2516 | Int16Array(); |
| 2517 | static void CheckCast(Value* obj); |
| 2518 | }; |
| 2519 | |
| 2520 | |
| 2521 | /** |
| 2522 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2523 | * This API is experimental and may change significantly. |
| 2524 | */ |
| 2525 | class V8EXPORT Uint32Array : public TypedArray { |
| 2526 | public: |
| 2527 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2528 | size_t byte_offset, size_t length); |
| 2529 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2530 | |
| 2531 | private: |
| 2532 | Uint32Array(); |
| 2533 | static void CheckCast(Value* obj); |
| 2534 | }; |
| 2535 | |
| 2536 | |
| 2537 | /** |
| 2538 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2539 | * This API is experimental and may change significantly. |
| 2540 | */ |
| 2541 | class V8EXPORT Int32Array : public TypedArray { |
| 2542 | public: |
| 2543 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2544 | size_t byte_offset, size_t length); |
| 2545 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2546 | |
| 2547 | private: |
| 2548 | Int32Array(); |
| 2549 | static void CheckCast(Value* obj); |
| 2550 | }; |
| 2551 | |
| 2552 | |
| 2553 | /** |
| 2554 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2555 | * This API is experimental and may change significantly. |
| 2556 | */ |
| 2557 | class V8EXPORT Float32Array : public TypedArray { |
| 2558 | public: |
| 2559 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2560 | size_t byte_offset, size_t length); |
| 2561 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2562 | |
| 2563 | private: |
| 2564 | Float32Array(); |
| 2565 | static void CheckCast(Value* obj); |
| 2566 | }; |
| 2567 | |
| 2568 | |
| 2569 | /** |
| 2570 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2571 | * This API is experimental and may change significantly. |
| 2572 | */ |
| 2573 | class V8EXPORT Float64Array : public TypedArray { |
| 2574 | public: |
| 2575 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2576 | size_t byte_offset, size_t length); |
| 2577 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2578 | |
| 2579 | private: |
| 2580 | Float64Array(); |
| 2581 | static void CheckCast(Value* obj); |
| 2582 | }; |
| 2583 | |
| 2584 | |
| 2585 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2586 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2587 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2588 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2589 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2590 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2591 | |
| 2592 | /** |
| 2593 | * A specialization of Value::NumberValue that is more efficient |
| 2594 | * because we know the structure of this object. |
| 2595 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2596 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2597 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2598 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2599 | |
| 2600 | /** |
| 2601 | * Notification that the embedder has changed the time zone, |
| 2602 | * daylight savings time, or other date / time configuration |
| 2603 | * parameters. V8 keeps a cache of various values used for |
| 2604 | * date / time computation. This notification will reset |
| 2605 | * those cached values for the current context so that date / |
| 2606 | * time configuration changes would be reflected in the Date |
| 2607 | * object. |
| 2608 | * |
| 2609 | * This API should not be called more than needed as it will |
| 2610 | * negatively impact the performance of date operations. |
| 2611 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2612 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2613 | |
| 2614 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2615 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2616 | }; |
| 2617 | |
| 2618 | |
| 2619 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2620 | * A Number object (ECMA-262, 4.3.21). |
| 2621 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2622 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2623 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2624 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2625 | |
| 2626 | /** |
| 2627 | * Returns the Number held by the object. |
| 2628 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2629 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2630 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2631 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2632 | |
| 2633 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2634 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2635 | }; |
| 2636 | |
| 2637 | |
| 2638 | /** |
| 2639 | * A Boolean object (ECMA-262, 4.3.15). |
| 2640 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2641 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2642 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2643 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2644 | |
| 2645 | /** |
| 2646 | * Returns the Boolean held by the object. |
| 2647 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2648 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2649 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2650 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2651 | |
| 2652 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2653 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2654 | }; |
| 2655 | |
| 2656 | |
| 2657 | /** |
| 2658 | * A String object (ECMA-262, 4.3.18). |
| 2659 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2660 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2661 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2662 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2663 | |
| 2664 | /** |
| 2665 | * Returns the String held by the object. |
| 2666 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2667 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2668 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2669 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2670 | |
| 2671 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2672 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2673 | }; |
| 2674 | |
| 2675 | |
| 2676 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2677 | * A Symbol object (ECMA-262 edition 6). |
| 2678 | * |
| 2679 | * This is an experimental feature. Use at your own risk. |
| 2680 | */ |
| 2681 | class V8EXPORT SymbolObject : public Object { |
| 2682 | public: |
| 2683 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2684 | |
| 2685 | /** |
| 2686 | * Returns the Symbol held by the object. |
| 2687 | */ |
| 2688 | Local<Symbol> SymbolValue() const; |
| 2689 | |
| 2690 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2691 | |
| 2692 | private: |
| 2693 | static void CheckCast(v8::Value* obj); |
| 2694 | }; |
| 2695 | |
| 2696 | |
| 2697 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2698 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2699 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2700 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2701 | public: |
| 2702 | /** |
| 2703 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2704 | * of flags. |
| 2705 | */ |
| 2706 | enum Flags { |
| 2707 | kNone = 0, |
| 2708 | kGlobal = 1, |
| 2709 | kIgnoreCase = 2, |
| 2710 | kMultiline = 4 |
| 2711 | }; |
| 2712 | |
| 2713 | /** |
| 2714 | * Creates a regular expression from the given pattern string and |
| 2715 | * the flags bit field. May throw a JavaScript exception as |
| 2716 | * described in ECMA-262, 15.10.4.1. |
| 2717 | * |
| 2718 | * For example, |
| 2719 | * RegExp::New(v8::String::New("foo"), |
| 2720 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2721 | * is equivalent to evaluating "/foo/gm". |
| 2722 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2723 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2724 | |
| 2725 | /** |
| 2726 | * Returns the value of the source property: a string representing |
| 2727 | * the regular expression. |
| 2728 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2729 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2730 | |
| 2731 | /** |
| 2732 | * Returns the flags bit field. |
| 2733 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2734 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2735 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2736 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2737 | |
| 2738 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2739 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2740 | }; |
| 2741 | |
| 2742 | |
| 2743 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2744 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2745 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2746 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2747 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2748 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2749 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2750 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2751 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2752 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2753 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2754 | }; |
| 2755 | |
| 2756 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2757 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2758 | |
| 2759 | |
| 2760 | /** |
| 2761 | * The superclass of object and function templates. |
| 2762 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2763 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | public: |
| 2765 | /** Adds a property to each instance created by this template.*/ |
| 2766 | void Set(Handle<String> name, Handle<Data> value, |
| 2767 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2768 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2769 | private: |
| 2770 | Template(); |
| 2771 | |
| 2772 | friend class ObjectTemplate; |
| 2773 | friend class FunctionTemplate; |
| 2774 | }; |
| 2775 | |
| 2776 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2777 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2778 | class ReturnValue { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2779 | public: |
| 2780 | V8_INLINE(explicit ReturnValue(internal::Object** slot)); |
| 2781 | // Handle setters |
| 2782 | V8_INLINE(void Set(const Persistent<T>& handle)); |
| 2783 | V8_INLINE(void Set(const Handle<T> handle)); |
| 2784 | // Fast primitive setters |
| 2785 | V8_INLINE(void Set(Isolate* isolate, bool value)); |
| 2786 | V8_INLINE(void Set(Isolate* isolate, double i)); |
| 2787 | V8_INLINE(void Set(Isolate* isolate, int32_t i)); |
| 2788 | V8_INLINE(void Set(Isolate* isolate, uint32_t i)); |
| 2789 | // Fast JS primitive setters |
| 2790 | V8_INLINE(void SetNull(Isolate* isolate)); |
| 2791 | V8_INLINE(void SetUndefined(Isolate* isolate)); |
| 2792 | private: |
| 2793 | V8_INLINE(void SetTrue(Isolate* isolate)); |
| 2794 | V8_INLINE(void SetFalse(Isolate* isolate)); |
| 2795 | internal::Object** value_; |
| 2796 | }; |
| 2797 | |
| 2798 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2799 | /** |
| 2800 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2801 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | * including the receiver, the number and values of arguments, and |
| 2803 | * the holder of the function. |
| 2804 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2805 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2806 | class FunctionCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2807 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2808 | V8_INLINE(int Length() const); |
| 2809 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2810 | V8_INLINE(Local<Function> Callee() const); |
| 2811 | V8_INLINE(Local<Object> This() const); |
| 2812 | V8_INLINE(Local<Object> Holder() const); |
| 2813 | V8_INLINE(bool IsConstructCall() const); |
| 2814 | V8_INLINE(Local<Value> Data() const); |
| 2815 | V8_INLINE(Isolate* GetIsolate() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2816 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2817 | // This shouldn't be public, but the arm compiler needs it. |
| 2818 | static const int kArgsLength = 5; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2819 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2820 | protected: |
| 2821 | friend class internal::FunctionCallbackArguments; |
| 2822 | friend class internal::CustomArguments<FunctionCallbackInfo>; |
| 2823 | static const int kReturnValueIndex = 0; |
| 2824 | static const int kIsolateIndex = -1; |
| 2825 | static const int kDataIndex = -2; |
| 2826 | static const int kCalleeIndex = -3; |
| 2827 | static const int kHolderIndex = -4; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2828 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2829 | V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2830 | internal::Object** values, |
| 2831 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2832 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2833 | internal::Object** implicit_args_; |
| 2834 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2835 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2836 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2837 | }; |
| 2838 | |
| 2839 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2840 | class V8EXPORT Arguments : public FunctionCallbackInfo<Value> { |
| 2841 | private: |
| 2842 | friend class internal::FunctionCallbackArguments; |
| 2843 | V8_INLINE(Arguments(internal::Object** implicit_args, |
| 2844 | internal::Object** values, |
| 2845 | int length, |
| 2846 | bool is_construct_call)); |
| 2847 | }; |
| 2848 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2849 | /** |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2850 | * The information passed to a property callback about the context |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2851 | * of the property access. |
| 2852 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2853 | template<typename T> |
ulan@chromium.org | 867c3b0 | 2013-05-22 15:42:42 +0000 | [diff] [blame] | 2854 | class PropertyCallbackInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2855 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2856 | V8_INLINE(Isolate* GetIsolate() const); |
| 2857 | V8_INLINE(Local<Value> Data() const); |
| 2858 | V8_INLINE(Local<Object> This() const); |
| 2859 | V8_INLINE(Local<Object> Holder() const); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2860 | V8_INLINE(ReturnValue<T> GetReturnValue() const); |
| 2861 | // This shouldn't be public, but the arm compiler needs it. |
| 2862 | static const int kArgsLength = 5; |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2863 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2864 | protected: |
| 2865 | friend class MacroAssembler; |
| 2866 | friend class internal::PropertyCallbackArguments; |
| 2867 | friend class internal::CustomArguments<PropertyCallbackInfo>; |
| 2868 | static const int kThisIndex = 0; |
| 2869 | static const int kHolderIndex = -1; |
| 2870 | static const int kDataIndex = -2; |
| 2871 | static const int kIsolateIndex = -3; |
| 2872 | static const int kReturnValueIndex = -4; |
| 2873 | |
| 2874 | V8_INLINE(PropertyCallbackInfo(internal::Object** args)) |
| 2875 | : args_(args) { } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2876 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2877 | }; |
| 2878 | |
| 2879 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2880 | class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> { |
| 2881 | private: |
| 2882 | friend class internal::PropertyCallbackArguments; |
| 2883 | V8_INLINE(AccessorInfo(internal::Object** args)) |
| 2884 | : PropertyCallbackInfo<Value>(args) { } |
| 2885 | }; |
| 2886 | |
| 2887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2889 | typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2890 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2891 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2892 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2893 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2894 | */ |
| 2895 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2896 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2897 | typedef void (*NamedPropertyGetterCallback)( |
| 2898 | Local<String> property, |
| 2899 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | |
| 2901 | |
| 2902 | /** |
| 2903 | * Returns the value if the setter intercepts the request. |
| 2904 | * Otherwise, returns an empty handle. |
| 2905 | */ |
| 2906 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2907 | Local<Value> value, |
| 2908 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2909 | typedef void (*NamedPropertySetterCallback)( |
| 2910 | Local<String> property, |
| 2911 | Local<Value> value, |
| 2912 | const PropertyCallbackInfo<Value>& info); |
| 2913 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2914 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2915 | /** |
| 2916 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2917 | * The result is an integer encoding property attributes (like v8::None, |
| 2918 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2919 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2920 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2921 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2922 | typedef void (*NamedPropertyQueryCallback)( |
| 2923 | Local<String> property, |
| 2924 | const PropertyCallbackInfo<Integer>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2925 | |
| 2926 | |
| 2927 | /** |
| 2928 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2929 | * The return value is true if the property could be deleted and false |
| 2930 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2931 | */ |
| 2932 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2933 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2934 | typedef void (*NamedPropertyDeleterCallback)( |
| 2935 | Local<String> property, |
| 2936 | const PropertyCallbackInfo<Boolean>& info); |
| 2937 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2938 | |
| 2939 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2940 | * Returns an array containing the names of the properties the named |
| 2941 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2942 | */ |
| 2943 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2944 | typedef void (*NamedPropertyEnumeratorCallback)( |
| 2945 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2946 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2947 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2949 | * Returns the value of the property if the getter intercepts the |
| 2950 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2951 | */ |
| 2952 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 2953 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2954 | typedef void (*IndexedPropertyGetterCallback)( |
| 2955 | uint32_t index, |
| 2956 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2957 | |
| 2958 | |
| 2959 | /** |
| 2960 | * Returns the value if the setter intercepts the request. |
| 2961 | * Otherwise, returns an empty handle. |
| 2962 | */ |
| 2963 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 2964 | Local<Value> value, |
| 2965 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2966 | typedef void (*IndexedPropertySetterCallback)( |
| 2967 | uint32_t index, |
| 2968 | Local<Value> value, |
| 2969 | const PropertyCallbackInfo<Value>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | |
| 2971 | |
| 2972 | /** |
| 2973 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2974 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2975 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2976 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 2977 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2978 | typedef void (*IndexedPropertyQueryCallback)( |
| 2979 | uint32_t index, |
| 2980 | const PropertyCallbackInfo<Integer>& info); |
| 2981 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2982 | |
| 2983 | /** |
| 2984 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2985 | * The return value is true if the property could be deleted and false |
| 2986 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2987 | */ |
| 2988 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 2989 | const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2990 | typedef void (*IndexedPropertyDeleterCallback)( |
| 2991 | uint32_t index, |
| 2992 | const PropertyCallbackInfo<Boolean>& info); |
| 2993 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2994 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2995 | /** |
| 2996 | * Returns an array containing the indices of the properties the |
| 2997 | * indexed property getter intercepts. |
| 2998 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2999 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3000 | typedef void (*IndexedPropertyEnumeratorCallback)( |
| 3001 | const PropertyCallbackInfo<Array>& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3002 | |
| 3003 | |
| 3004 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3005 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3006 | */ |
| 3007 | enum AccessType { |
| 3008 | ACCESS_GET, |
| 3009 | ACCESS_SET, |
| 3010 | ACCESS_HAS, |
| 3011 | ACCESS_DELETE, |
| 3012 | ACCESS_KEYS |
| 3013 | }; |
| 3014 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3015 | |
| 3016 | /** |
| 3017 | * 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] | 3018 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3019 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3020 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3021 | Local<Value> key, |
| 3022 | AccessType type, |
| 3023 | Local<Value> data); |
| 3024 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3025 | |
| 3026 | /** |
| 3027 | * 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] | 3028 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3029 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3030 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3031 | uint32_t index, |
| 3032 | AccessType type, |
| 3033 | Local<Value> data); |
| 3034 | |
| 3035 | |
| 3036 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3037 | * A FunctionTemplate is used to create functions at runtime. There |
| 3038 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3039 | * context. The lifetime of the created function is equal to the |
| 3040 | * lifetime of the context. So in case the embedder needs to create |
| 3041 | * temporary functions that can be collected using Scripts is |
| 3042 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3043 | * |
| 3044 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3045 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3046 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3047 | * A FunctionTemplate has a corresponding instance template which is |
| 3048 | * used to create object instances when the function is used as a |
| 3049 | * constructor. Properties added to the instance template are added to |
| 3050 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3051 | * |
| 3052 | * A FunctionTemplate can have a prototype template. The prototype template |
| 3053 | * is used to create the prototype object of the function. |
| 3054 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3055 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3056 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3057 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3058 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 3059 | * t->Set("func_property", v8::Number::New(1)); |
| 3060 | * |
| 3061 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 3062 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 3063 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 3064 | * |
| 3065 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 3066 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 3067 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 3068 | * instance_t->Set("instance_property", Number::New(3)); |
| 3069 | * |
| 3070 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 3071 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3072 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | * |
| 3074 | * 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] | 3075 | * and "instance" for the instance object created above. The function |
| 3076 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3077 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3078 | * \code |
| 3079 | * func_property in function == true; |
| 3080 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3081 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3082 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 3083 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3084 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3085 | * instance instanceof function == true; |
| 3086 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 3087 | * instance.instance_property == 3; |
| 3088 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3089 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3090 | * A FunctionTemplate can inherit from another one by calling the |
| 3091 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 3092 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3093 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3094 | * \code |
| 3095 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 3096 | * ^ ^ |
| 3097 | * | Inherit(Parent) | .__proto__ |
| 3098 | * | | |
| 3099 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 3100 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3101 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3102 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 3103 | * object of the Child() function has __proto__ pointing to the |
| 3104 | * Parent() function's prototype object. An instance of the Child |
| 3105 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3106 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3107 | * Let Parent be the FunctionTemplate initialized in the previous |
| 3108 | * section and create a Child FunctionTemplate by: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3109 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3110 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3111 | * Local<FunctionTemplate> parent = t; |
| 3112 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 3113 | * child->Inherit(parent); |
| 3114 | * |
| 3115 | * Local<Function> child_function = child->GetFunction(); |
| 3116 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3117 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3118 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3119 | * The Child function and Child instance will have the following |
| 3120 | * properties: |
| 3121 | * |
| 3122 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3123 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3124 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3125 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3126 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3127 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3128 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3129 | public: |
| 3130 | /** Creates a function template.*/ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3131 | // TODO(dcarney): deprecate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3132 | static Local<FunctionTemplate> New( |
| 3133 | InvocationCallback callback = 0, |
| 3134 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3135 | Handle<Signature> signature = Handle<Signature>(), |
| 3136 | int length = 0); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3137 | static Local<FunctionTemplate> New( |
| 3138 | FunctionCallback callback, // TODO(dcarney): add back default param. |
| 3139 | Handle<Value> data = Handle<Value>(), |
| 3140 | Handle<Signature> signature = Handle<Signature>(), |
| 3141 | int length = 0); |
| 3142 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3143 | /** Returns the unique function instance in the current execution context.*/ |
| 3144 | Local<Function> GetFunction(); |
| 3145 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3146 | /** |
| 3147 | * Set the call-handler callback for a FunctionTemplate. This |
| 3148 | * callback is called whenever the function created from this |
| 3149 | * FunctionTemplate is called. |
| 3150 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3151 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3152 | void SetCallHandler(InvocationCallback callback, |
| 3153 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3154 | void SetCallHandler(FunctionCallback callback, |
| 3155 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3156 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3157 | /** Set the predefined length property for the FunctionTemplate. */ |
| 3158 | void SetLength(int length); |
| 3159 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3160 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3161 | Local<ObjectTemplate> InstanceTemplate(); |
| 3162 | |
| 3163 | /** Causes the function template to inherit from a parent function template.*/ |
| 3164 | void Inherit(Handle<FunctionTemplate> parent); |
| 3165 | |
| 3166 | /** |
| 3167 | * A PrototypeTemplate is the template used to create the prototype object |
| 3168 | * of the function created by this template. |
| 3169 | */ |
| 3170 | Local<ObjectTemplate> PrototypeTemplate(); |
| 3171 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3172 | /** |
| 3173 | * Set the class name of the FunctionTemplate. This is used for |
| 3174 | * printing objects created with the function created from the |
| 3175 | * FunctionTemplate as its constructor. |
| 3176 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3177 | void SetClassName(Handle<String> name); |
| 3178 | |
| 3179 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3180 | * Determines whether the __proto__ accessor ignores instances of |
| 3181 | * the function template. If instances of the function template are |
| 3182 | * ignored, __proto__ skips all instances and instead returns the |
| 3183 | * next object in the prototype chain. |
| 3184 | * |
| 3185 | * Call with a value of true to make the __proto__ accessor ignore |
| 3186 | * instances of the function template. Call with a value of false |
| 3187 | * to make the __proto__ accessor not ignore instances of the |
| 3188 | * function template. By default, instances of a function template |
| 3189 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3190 | */ |
| 3191 | void SetHiddenPrototype(bool value); |
| 3192 | |
| 3193 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3194 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3195 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3196 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3197 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3198 | |
| 3199 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3200 | * Returns true if the given object is an instance of this function |
| 3201 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3202 | */ |
| 3203 | bool HasInstance(Handle<Value> object); |
| 3204 | |
| 3205 | private: |
| 3206 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | friend class Context; |
| 3208 | friend class ObjectTemplate; |
| 3209 | }; |
| 3210 | |
| 3211 | |
| 3212 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3213 | * An ObjectTemplate is used to create objects at runtime. |
| 3214 | * |
| 3215 | * Properties added to an ObjectTemplate are added to each object |
| 3216 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3217 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3218 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3219 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3220 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3221 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3223 | /** Creates a new instance of this template.*/ |
| 3224 | Local<Object> NewInstance(); |
| 3225 | |
| 3226 | /** |
| 3227 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3228 | * |
| 3229 | * Whenever the property with the given name is accessed on objects |
| 3230 | * created from this ObjectTemplate the getter and setter callbacks |
| 3231 | * are called instead of getting and setting the property directly |
| 3232 | * on the JavaScript object. |
| 3233 | * |
| 3234 | * \param name The name of the property for which an accessor is added. |
| 3235 | * \param getter The callback to invoke when getting the property. |
| 3236 | * \param setter The callback to invoke when setting the property. |
| 3237 | * \param data A piece of data that will be passed to the getter and setter |
| 3238 | * callbacks whenever they are invoked. |
| 3239 | * \param settings Access control settings for the accessor. This is a bit |
| 3240 | * field consisting of one of more of |
| 3241 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3242 | * The default is to not allow cross-context access. |
| 3243 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3244 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3245 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3246 | * cross-context access. |
| 3247 | * \param attribute The attributes of the property for which an accessor |
| 3248 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3249 | * \param signature The signature describes valid receivers for the accessor |
| 3250 | * and is used to perform implicit instance checks against them. If the |
| 3251 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3252 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3253 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3254 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3255 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3256 | void SetAccessor(Handle<String> name, |
| 3257 | AccessorGetter getter, |
| 3258 | AccessorSetter setter = 0, |
| 3259 | Handle<Value> data = Handle<Value>(), |
| 3260 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3261 | PropertyAttribute attribute = None, |
| 3262 | Handle<AccessorSignature> signature = |
| 3263 | Handle<AccessorSignature>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3264 | void SetAccessor(Handle<String> name, |
| 3265 | AccessorGetterCallback getter, |
| 3266 | AccessorSetterCallback setter = 0, |
| 3267 | Handle<Value> data = Handle<Value>(), |
| 3268 | AccessControl settings = DEFAULT, |
| 3269 | PropertyAttribute attribute = None, |
| 3270 | Handle<AccessorSignature> signature = |
| 3271 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3272 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3273 | // This function is not yet stable and should not be used at this time. |
| 3274 | bool SetAccessor(Handle<String> name, |
| 3275 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3276 | AccessControl settings = DEFAULT, |
| 3277 | PropertyAttribute attribute = None, |
| 3278 | Handle<AccessorSignature> signature = |
| 3279 | Handle<AccessorSignature>()); |
| 3280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3281 | /** |
| 3282 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3283 | * |
| 3284 | * Whenever a named property is accessed on objects created from |
| 3285 | * this object template, the provided callback is invoked instead of |
| 3286 | * accessing the property directly on the JavaScript object. |
| 3287 | * |
| 3288 | * \param getter The callback to invoke when getting a property. |
| 3289 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3290 | * \param query The callback to invoke to check if a property is present, |
| 3291 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3292 | * \param deleter The callback to invoke when deleting a property. |
| 3293 | * \param enumerator The callback to invoke to enumerate all the named |
| 3294 | * properties of an object. |
| 3295 | * \param data A piece of data that will be passed to the callbacks |
| 3296 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3297 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3298 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3299 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3300 | NamedPropertySetter setter = 0, |
| 3301 | NamedPropertyQuery query = 0, |
| 3302 | NamedPropertyDeleter deleter = 0, |
| 3303 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3304 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3305 | void SetNamedPropertyHandler( |
| 3306 | NamedPropertyGetterCallback getter, |
| 3307 | NamedPropertySetterCallback setter = 0, |
| 3308 | NamedPropertyQueryCallback query = 0, |
| 3309 | NamedPropertyDeleterCallback deleter = 0, |
| 3310 | NamedPropertyEnumeratorCallback enumerator = 0, |
| 3311 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3312 | |
| 3313 | /** |
| 3314 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3315 | * |
| 3316 | * Whenever an indexed property is accessed on objects created from |
| 3317 | * this object template, the provided callback is invoked instead of |
| 3318 | * accessing the property directly on the JavaScript object. |
| 3319 | * |
| 3320 | * \param getter The callback to invoke when getting a property. |
| 3321 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3322 | * \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] | 3323 | * \param deleter The callback to invoke when deleting a property. |
| 3324 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3325 | * properties of an object. |
| 3326 | * \param data A piece of data that will be passed to the callbacks |
| 3327 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3328 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3329 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3330 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3331 | IndexedPropertySetter setter = 0, |
| 3332 | IndexedPropertyQuery query = 0, |
| 3333 | IndexedPropertyDeleter deleter = 0, |
| 3334 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3335 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3336 | void SetIndexedPropertyHandler( |
| 3337 | IndexedPropertyGetterCallback getter, |
| 3338 | IndexedPropertySetterCallback setter = 0, |
| 3339 | IndexedPropertyQueryCallback query = 0, |
| 3340 | IndexedPropertyDeleterCallback deleter = 0, |
| 3341 | IndexedPropertyEnumeratorCallback enumerator = 0, |
| 3342 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3343 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3344 | /** |
| 3345 | * Sets the callback to be used when calling instances created from |
| 3346 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3347 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3348 | * function. |
| 3349 | */ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3350 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3351 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3352 | Handle<Value> data = Handle<Value>()); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3353 | void SetCallAsFunctionHandler(FunctionCallback callback, |
| 3354 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3355 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3356 | /** |
| 3357 | * Mark object instances of the template as undetectable. |
| 3358 | * |
| 3359 | * In many ways, undetectable objects behave as though they are not |
| 3360 | * there. They behave like 'undefined' in conditionals and when |
| 3361 | * printed. However, properties can be accessed and called as on |
| 3362 | * normal objects. |
| 3363 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3364 | void MarkAsUndetectable(); |
| 3365 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3366 | /** |
| 3367 | * Sets access check callbacks on the object template. |
| 3368 | * |
| 3369 | * When accessing properties on instances of this object template, |
| 3370 | * the access check callback will be called to determine whether or |
| 3371 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3372 | * The last parameter specifies whether access checks are turned |
| 3373 | * on by default on instances. If access checks are off by default, |
| 3374 | * they can be turned on on individual instances by calling |
| 3375 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3376 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3377 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3378 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3379 | Handle<Value> data = Handle<Value>(), |
| 3380 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3381 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3382 | /** |
| 3383 | * Gets the number of internal fields for objects generated from |
| 3384 | * this template. |
| 3385 | */ |
| 3386 | int InternalFieldCount(); |
| 3387 | |
| 3388 | /** |
| 3389 | * Sets the number of internal fields for objects generated from |
| 3390 | * this template. |
| 3391 | */ |
| 3392 | void SetInternalFieldCount(int value); |
| 3393 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | private: |
| 3395 | ObjectTemplate(); |
| 3396 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3397 | friend class FunctionTemplate; |
| 3398 | }; |
| 3399 | |
| 3400 | |
| 3401 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3402 | * A Signature specifies which receivers and arguments are valid |
| 3403 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3404 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3405 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3406 | public: |
| 3407 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3408 | Handle<FunctionTemplate>(), |
| 3409 | int argc = 0, |
| 3410 | Handle<FunctionTemplate> argv[] = 0); |
| 3411 | private: |
| 3412 | Signature(); |
| 3413 | }; |
| 3414 | |
| 3415 | |
| 3416 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3417 | * An AccessorSignature specifies which receivers are valid parameters |
| 3418 | * to an accessor callback. |
| 3419 | */ |
| 3420 | class V8EXPORT AccessorSignature : public Data { |
| 3421 | public: |
| 3422 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3423 | Handle<FunctionTemplate>()); |
| 3424 | private: |
| 3425 | AccessorSignature(); |
| 3426 | }; |
| 3427 | |
| 3428 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3429 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3430 | private: |
| 3431 | DeclaredAccessorDescriptor(); |
| 3432 | }; |
| 3433 | |
| 3434 | |
| 3435 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3436 | public: |
| 3437 | // This function is not yet stable and should not be used at this time. |
| 3438 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3439 | Isolate* isolate, |
| 3440 | int internal_field); |
| 3441 | private: |
| 3442 | ObjectOperationDescriptor(); |
| 3443 | }; |
| 3444 | |
| 3445 | |
| 3446 | enum DeclaredAccessorDescriptorDataType { |
| 3447 | kDescriptorBoolType, |
| 3448 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3449 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3450 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3451 | kDescriptorFloatType, kDescriptorDoubleType |
| 3452 | }; |
| 3453 | |
| 3454 | |
| 3455 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3456 | public: |
| 3457 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3458 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3459 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3460 | int16_t byte_offset); |
| 3461 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3462 | void* compare_value); |
| 3463 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3464 | Isolate* isolate, |
| 3465 | DeclaredAccessorDescriptorDataType data_type, |
| 3466 | uint8_t bool_offset = 0); |
| 3467 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3468 | uint8_t bitmask, |
| 3469 | uint8_t compare_value); |
| 3470 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3471 | Isolate* isolate, |
| 3472 | uint16_t bitmask, |
| 3473 | uint16_t compare_value); |
| 3474 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3475 | Isolate* isolate, |
| 3476 | uint32_t bitmask, |
| 3477 | uint32_t compare_value); |
| 3478 | |
| 3479 | private: |
| 3480 | RawOperationDescriptor(); |
| 3481 | }; |
| 3482 | |
| 3483 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3484 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3485 | * A utility for determining the type of objects based on the template |
| 3486 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3487 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3488 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3489 | public: |
| 3490 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3491 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3492 | int match(Handle<Value> value); |
| 3493 | private: |
| 3494 | TypeSwitch(); |
| 3495 | }; |
| 3496 | |
| 3497 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3498 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3499 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3500 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3501 | : public String::ExternalAsciiStringResource { |
| 3502 | public: |
| 3503 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3504 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3505 | : data_(data), length_(length) {} |
| 3506 | const char* data() const { return data_; } |
| 3507 | size_t length() const { return length_; } |
| 3508 | |
| 3509 | private: |
| 3510 | const char* data_; |
| 3511 | size_t length_; |
| 3512 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3513 | |
| 3514 | /** |
| 3515 | * Ignore |
| 3516 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3517 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3518 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3519 | // Note that the strings passed into this constructor must live as long |
| 3520 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3521 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3522 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3523 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3524 | const char** deps = 0, |
| 3525 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3526 | virtual ~Extension() { } |
| 3527 | virtual v8::Handle<v8::FunctionTemplate> |
| 3528 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3529 | return v8::Handle<v8::FunctionTemplate>(); |
| 3530 | } |
| 3531 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3532 | const char* name() const { return name_; } |
| 3533 | size_t source_length() const { return source_length_; } |
| 3534 | const String::ExternalAsciiStringResource* source() const { |
| 3535 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3536 | int dependency_count() { return dep_count_; } |
| 3537 | const char** dependencies() { return deps_; } |
| 3538 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3539 | bool auto_enable() { return auto_enable_; } |
| 3540 | |
| 3541 | private: |
| 3542 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3543 | size_t source_length_; // expected to initialize before source_ |
| 3544 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3545 | int dep_count_; |
| 3546 | const char** deps_; |
| 3547 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3548 | |
| 3549 | // Disallow copying and assigning. |
| 3550 | Extension(const Extension&); |
| 3551 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3552 | }; |
| 3553 | |
| 3554 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3555 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3556 | |
| 3557 | |
| 3558 | /** |
| 3559 | * Ignore |
| 3560 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3561 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3562 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3563 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3564 | RegisterExtension(extension); |
| 3565 | } |
| 3566 | }; |
| 3567 | |
| 3568 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3569 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3570 | |
| 3571 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3572 | Handle<Primitive> V8EXPORT Undefined(); |
| 3573 | Handle<Primitive> V8EXPORT Null(); |
| 3574 | Handle<Boolean> V8EXPORT True(); |
| 3575 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3576 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3577 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3578 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3579 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3580 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3581 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3582 | |
| 3583 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3584 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3585 | * You must set the heap size before initializing the VM - the size cannot be |
| 3586 | * adjusted after the VM is initialized. |
| 3587 | * |
| 3588 | * If you are using threads then you should hold the V8::Locker lock while |
| 3589 | * setting the stack limit and you must set a non-default stack limit separately |
| 3590 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3591 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3592 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3593 | public: |
| 3594 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3595 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3596 | 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] | 3597 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3598 | 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] | 3599 | int max_executable_size() { return max_executable_size_; } |
| 3600 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3601 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3602 | // 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] | 3603 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3604 | private: |
| 3605 | int max_young_space_size_; |
| 3606 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3607 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3608 | uint32_t* stack_limit_; |
| 3609 | }; |
| 3610 | |
| 3611 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3612 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3613 | |
| 3614 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3615 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3616 | |
| 3617 | |
| 3618 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3619 | |
| 3620 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3621 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3622 | |
| 3623 | |
| 3624 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3625 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3626 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3627 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3628 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3629 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3630 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3631 | |
| 3632 | /** |
| 3633 | * Create new error objects by calling the corresponding error object |
| 3634 | * constructor with the message. |
| 3635 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3636 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3637 | public: |
| 3638 | static Local<Value> RangeError(Handle<String> message); |
| 3639 | static Local<Value> ReferenceError(Handle<String> message); |
| 3640 | static Local<Value> SyntaxError(Handle<String> message); |
| 3641 | static Local<Value> TypeError(Handle<String> message); |
| 3642 | static Local<Value> Error(Handle<String> message); |
| 3643 | }; |
| 3644 | |
| 3645 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3646 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3647 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3648 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3649 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3650 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3651 | int min, |
| 3652 | int max, |
| 3653 | size_t buckets); |
| 3654 | |
| 3655 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3656 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3657 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3658 | enum ObjectSpace { |
| 3659 | kObjectSpaceNewSpace = 1 << 0, |
| 3660 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3661 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3662 | kObjectSpaceCodeSpace = 1 << 3, |
| 3663 | kObjectSpaceMapSpace = 1 << 4, |
| 3664 | kObjectSpaceLoSpace = 1 << 5, |
| 3665 | |
| 3666 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3667 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3668 | kObjectSpaceLoSpace |
| 3669 | }; |
| 3670 | |
| 3671 | enum AllocationAction { |
| 3672 | kAllocationActionAllocate = 1 << 0, |
| 3673 | kAllocationActionFree = 1 << 1, |
| 3674 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3675 | }; |
| 3676 | |
| 3677 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3678 | AllocationAction action, |
| 3679 | int size); |
| 3680 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3681 | // --- Leave Script Callback --- |
| 3682 | typedef void (*CallCompletedCallback)(); |
| 3683 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3684 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3685 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3686 | AccessType type, |
| 3687 | Local<Value> data); |
| 3688 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3689 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3690 | |
| 3691 | /** |
| 3692 | * Callback to check if code generation from strings is allowed. See |
| 3693 | * Context::AllowCodeGenerationFromStrings. |
| 3694 | */ |
| 3695 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3696 | |
| 3697 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3698 | |
| 3699 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3700 | * Applications can register callback functions which will be called |
| 3701 | * before and after a garbage collection. Allocations are not |
| 3702 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3703 | * objects (set or delete properties for example) since it is possible |
| 3704 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3705 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3706 | enum GCType { |
| 3707 | kGCTypeScavenge = 1 << 0, |
| 3708 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3709 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3710 | }; |
| 3711 | |
| 3712 | enum GCCallbackFlags { |
| 3713 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3714 | kGCCallbackFlagCompacted = 1 << 0, |
| 3715 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3716 | }; |
| 3717 | |
| 3718 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3719 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3720 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3721 | typedef void (*GCCallback)(); |
| 3722 | |
| 3723 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3724 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3725 | * Collection of V8 heap information. |
| 3726 | * |
| 3727 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3728 | * get heap statistics from V8. |
| 3729 | */ |
| 3730 | class V8EXPORT HeapStatistics { |
| 3731 | public: |
| 3732 | HeapStatistics(); |
| 3733 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3734 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3735 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3736 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3737 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3738 | |
| 3739 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3740 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3741 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3742 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3743 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3744 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3745 | |
| 3746 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3747 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3748 | }; |
| 3749 | |
| 3750 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3751 | class RetainedObjectInfo; |
| 3752 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3753 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3754 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3755 | * isolates have completely separate states. Objects from one isolate |
| 3756 | * must not be used in other isolates. When V8 is initialized a |
| 3757 | * default isolate is implicitly created and entered. The embedder |
| 3758 | * can create additional isolates and use them in parallel in multiple |
| 3759 | * 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] | 3760 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3761 | */ |
| 3762 | class V8EXPORT Isolate { |
| 3763 | public: |
| 3764 | /** |
| 3765 | * Stack-allocated class which sets the isolate for all operations |
| 3766 | * executed within a local scope. |
| 3767 | */ |
| 3768 | class V8EXPORT Scope { |
| 3769 | public: |
| 3770 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3771 | isolate->Enter(); |
| 3772 | } |
| 3773 | |
| 3774 | ~Scope() { isolate_->Exit(); } |
| 3775 | |
| 3776 | private: |
| 3777 | Isolate* const isolate_; |
| 3778 | |
| 3779 | // Prevent copying of Scope objects. |
| 3780 | Scope(const Scope&); |
| 3781 | Scope& operator=(const Scope&); |
| 3782 | }; |
| 3783 | |
| 3784 | /** |
| 3785 | * Creates a new isolate. Does not change the currently entered |
| 3786 | * isolate. |
| 3787 | * |
| 3788 | * When an isolate is no longer used its resources should be freed |
| 3789 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3790 | */ |
| 3791 | static Isolate* New(); |
| 3792 | |
| 3793 | /** |
| 3794 | * Returns the entered isolate for the current thread or NULL in |
| 3795 | * case there is no current isolate. |
| 3796 | */ |
| 3797 | static Isolate* GetCurrent(); |
| 3798 | |
| 3799 | /** |
| 3800 | * Methods below this point require holding a lock (using Locker) in |
| 3801 | * a multi-threaded environment. |
| 3802 | */ |
| 3803 | |
| 3804 | /** |
| 3805 | * Sets this isolate as the entered one for the current thread. |
| 3806 | * Saves the previously entered one (if any), so that it can be |
| 3807 | * restored when exiting. Re-entering an isolate is allowed. |
| 3808 | */ |
| 3809 | void Enter(); |
| 3810 | |
| 3811 | /** |
| 3812 | * Exits this isolate by restoring the previously entered one in the |
| 3813 | * current thread. The isolate may still stay the same, if it was |
| 3814 | * entered more than once. |
| 3815 | * |
| 3816 | * Requires: this == Isolate::GetCurrent(). |
| 3817 | */ |
| 3818 | void Exit(); |
| 3819 | |
| 3820 | /** |
| 3821 | * Disposes the isolate. The isolate must not be entered by any |
| 3822 | * thread to be disposable. |
| 3823 | */ |
| 3824 | void Dispose(); |
| 3825 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3826 | /** |
| 3827 | * Associate embedder-specific data with the isolate |
| 3828 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3829 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3830 | |
| 3831 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3832 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3833 | * Returns NULL if SetData has never been called. |
| 3834 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3835 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3836 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3837 | /** |
| 3838 | * Get statistics about the heap memory usage. |
| 3839 | */ |
| 3840 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3841 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3842 | /** |
| 3843 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3844 | * indication of the amount of externally allocated memory that is kept alive |
| 3845 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3846 | * garbage collections. Registering externally allocated memory will trigger |
| 3847 | * global garbage collections more often than it would otherwise in an attempt |
| 3848 | * to garbage collect the JavaScript objects that keep the externally |
| 3849 | * allocated memory alive. |
| 3850 | * |
| 3851 | * \param change_in_bytes the change in externally allocated memory that is |
| 3852 | * kept alive by JavaScript objects. |
| 3853 | * \returns the adjusted value. |
| 3854 | */ |
| 3855 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3856 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3857 | /** |
| 3858 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3859 | * is initialized. |
| 3860 | */ |
| 3861 | HeapProfiler* GetHeapProfiler(); |
| 3862 | |
| 3863 | /** |
| 3864 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3865 | * is initialized. |
| 3866 | */ |
| 3867 | CpuProfiler* GetCpuProfiler(); |
| 3868 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3869 | /** Returns the context that is on the top of the stack. */ |
| 3870 | Local<Context> GetCurrentContext(); |
| 3871 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3872 | /** |
| 3873 | * Allows the host application to group objects together. If one |
| 3874 | * object in the group is alive, all objects in the group are alive. |
| 3875 | * After each garbage collection, object groups are removed. It is |
| 3876 | * intended to be used in the before-garbage-collection callback |
| 3877 | * function, for instance to simulate DOM tree connections among JS |
| 3878 | * wrapper objects. Object groups for all dependent handles need to |
| 3879 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3880 | * garbage collection types it is sufficient to provide object groups |
| 3881 | * for partially dependent handles only. |
| 3882 | */ |
| 3883 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3884 | UniqueId id); |
| 3885 | |
| 3886 | /** |
| 3887 | * Allows the host application to declare implicit references from an object |
| 3888 | * group to an object. If the objects of the object group are alive, the child |
| 3889 | * object is alive too. After each garbage collection, all implicit references |
| 3890 | * are removed. It is intended to be used in the before-garbage-collection |
| 3891 | * callback function. |
| 3892 | */ |
| 3893 | void SetReferenceFromGroup(UniqueId id, |
| 3894 | const Persistent<Value>& child); |
| 3895 | |
| 3896 | /** |
| 3897 | * Allows the host application to declare implicit references from an object |
| 3898 | * to another object. If the parent object is alive, the child object is alive |
| 3899 | * too. After each garbage collection, all implicit references are removed. It |
| 3900 | * is intended to be used in the before-garbage-collection callback function. |
| 3901 | */ |
| 3902 | void SetReference(const Persistent<Object>& parent, |
| 3903 | const Persistent<Value>& child); |
| 3904 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3905 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3906 | Isolate(); |
| 3907 | Isolate(const Isolate&); |
| 3908 | ~Isolate(); |
| 3909 | Isolate& operator=(const Isolate&); |
| 3910 | void* operator new(size_t size); |
| 3911 | void operator delete(void*, size_t); |
| 3912 | }; |
| 3913 | |
| 3914 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3915 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3916 | public: |
| 3917 | enum CompressionAlgorithm { |
| 3918 | kUncompressed, |
| 3919 | kBZip2 |
| 3920 | }; |
| 3921 | |
| 3922 | const char* data; |
| 3923 | int compressed_size; |
| 3924 | int raw_size; |
| 3925 | }; |
| 3926 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3927 | |
| 3928 | /** |
| 3929 | * A helper class for driving V8 startup data decompression. It is based on |
| 3930 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3931 | * for an embedder to use this class, instead, API functions can be used |
| 3932 | * directly. |
| 3933 | * |
| 3934 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3935 | */ |
| 3936 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 3937 | public: |
| 3938 | StartupDataDecompressor(); |
| 3939 | virtual ~StartupDataDecompressor(); |
| 3940 | int Decompress(); |
| 3941 | |
| 3942 | protected: |
| 3943 | virtual int DecompressData(char* raw_data, |
| 3944 | int* raw_data_size, |
| 3945 | const char* compressed_data, |
| 3946 | int compressed_data_size) = 0; |
| 3947 | |
| 3948 | private: |
| 3949 | char** raw_data; |
| 3950 | }; |
| 3951 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3952 | |
| 3953 | /** |
| 3954 | * EntropySource is used as a callback function when v8 needs a source |
| 3955 | * of entropy. |
| 3956 | */ |
| 3957 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 3958 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3959 | |
| 3960 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3961 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 3962 | * resolving the location of a return address on the stack. Profilers that |
| 3963 | * change the return address on the stack can use this to resolve the stack |
| 3964 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3965 | * |
| 3966 | * \param return_addr_location points to a location on stack where a machine |
| 3967 | * return address resides. |
| 3968 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 3969 | * copy of the original return address. |
| 3970 | * |
| 3971 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3972 | */ |
| 3973 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 3974 | uintptr_t return_addr_location); |
| 3975 | |
| 3976 | |
| 3977 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3978 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 3979 | * any generated function when function-level profiling is enabled. |
| 3980 | * |
| 3981 | * \param function the address of the function that's being entered. |
| 3982 | * \param return_addr_location points to a location on stack where the machine |
| 3983 | * return address resides. This can be used to identify the caller of |
| 3984 | * \p function, and/or modified to divert execution when \p function exits. |
| 3985 | * |
| 3986 | * \note the entry hook must not cause garbage collection. |
| 3987 | */ |
| 3988 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 3989 | uintptr_t return_addr_location); |
| 3990 | |
| 3991 | |
| 3992 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3993 | * A JIT code event is issued each time code is added, moved or removed. |
| 3994 | * |
| 3995 | * \note removal events are not currently issued. |
| 3996 | */ |
| 3997 | struct JitCodeEvent { |
| 3998 | enum EventType { |
| 3999 | CODE_ADDED, |
| 4000 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4001 | CODE_REMOVED, |
| 4002 | CODE_ADD_LINE_POS_INFO, |
| 4003 | CODE_START_LINE_INFO_RECORDING, |
| 4004 | CODE_END_LINE_INFO_RECORDING |
| 4005 | }; |
| 4006 | // Definition of the code position type. The "POSITION" type means the place |
| 4007 | // in the source code which are of interest when making stack traces to |
| 4008 | // pin-point the source location of a stack frame as close as possible. |
| 4009 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 4010 | // statement, and is used to indicate possible break locations. |
| 4011 | enum PositionType { |
| 4012 | POSITION, |
| 4013 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4014 | }; |
| 4015 | |
| 4016 | // Type of event. |
| 4017 | EventType type; |
| 4018 | // Start of the instructions. |
| 4019 | void* code_start; |
| 4020 | // Size of the instructions. |
| 4021 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4022 | // Script info for CODE_ADDED event. |
| 4023 | Handle<Script> script; |
| 4024 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 4025 | // code line information which is returned from the |
| 4026 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 4027 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 4028 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4029 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4030 | struct name_t { |
| 4031 | // Name of the object associated with the code, note that the string is not |
| 4032 | // zero-terminated. |
| 4033 | const char* str; |
| 4034 | // Number of chars in str. |
| 4035 | size_t len; |
| 4036 | }; |
| 4037 | |
| 4038 | struct line_info_t { |
| 4039 | // PC offset |
| 4040 | size_t offset; |
| 4041 | // Code postion |
| 4042 | size_t pos; |
| 4043 | // The position type. |
| 4044 | PositionType position_type; |
| 4045 | }; |
| 4046 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4047 | union { |
| 4048 | // Only valid for CODE_ADDED. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4049 | struct name_t name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4050 | |
| 4051 | // Only valid for CODE_ADD_LINE_POS_INFO |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4052 | struct line_info_t line_info; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 4053 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4054 | // New location of instructions. Only valid for CODE_MOVED. |
| 4055 | void* new_code_start; |
| 4056 | }; |
| 4057 | }; |
| 4058 | |
| 4059 | /** |
| 4060 | * Option flags passed to the SetJitCodeEventHandler function. |
| 4061 | */ |
| 4062 | enum JitCodeEventOptions { |
| 4063 | kJitCodeEventDefault = 0, |
| 4064 | // Generate callbacks for already existent code. |
| 4065 | kJitCodeEventEnumExisting = 1 |
| 4066 | }; |
| 4067 | |
| 4068 | |
| 4069 | /** |
| 4070 | * Callback function passed to SetJitCodeEventHandler. |
| 4071 | * |
| 4072 | * \param event code add, move or removal event. |
| 4073 | */ |
| 4074 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 4075 | |
| 4076 | |
| 4077 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4078 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4079 | */ |
| 4080 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 4081 | public: |
| 4082 | virtual ~ExternalResourceVisitor() {} |
| 4083 | virtual void VisitExternalString(Handle<String> string) {} |
| 4084 | }; |
| 4085 | |
| 4086 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4087 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4088 | * Interface for iterating through all the persistent handles in the heap. |
| 4089 | */ |
| 4090 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 4091 | public: |
| 4092 | virtual ~PersistentHandleVisitor() {} |
| 4093 | virtual void VisitPersistentHandle(Persistent<Value> value, |
| 4094 | uint16_t class_id) {} |
| 4095 | }; |
| 4096 | |
| 4097 | |
| 4098 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4099 | * Asserts that no action is performed that could cause a handle's value |
| 4100 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 4101 | * be performed. |
| 4102 | */ |
| 4103 | class V8EXPORT AssertNoGCScope { |
| 4104 | #ifndef DEBUG |
| 4105 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} |
| 4106 | #else |
| 4107 | AssertNoGCScope(Isolate* isolate); |
| 4108 | ~AssertNoGCScope(); |
| 4109 | private: |
| 4110 | Isolate* isolate_; |
| 4111 | bool last_state_; |
| 4112 | #endif |
| 4113 | }; |
| 4114 | |
| 4115 | |
| 4116 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4117 | * Container class for static utility functions. |
| 4118 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4119 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4120 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4121 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4122 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 4123 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4124 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4125 | * Set the callback to invoke to check if code generation from |
| 4126 | * strings should be allowed. |
| 4127 | */ |
| 4128 | static void SetAllowCodeGenerationFromStringsCallback( |
| 4129 | AllowCodeGenerationFromStringsCallback that); |
| 4130 | |
| 4131 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4132 | * Ignore out-of-memory exceptions. |
| 4133 | * |
| 4134 | * V8 running out of memory is treated as a fatal error by default. |
| 4135 | * This means that the fatal error handler is called and that V8 is |
| 4136 | * terminated. |
| 4137 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4138 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4139 | * out-of-memory situation as a fatal error. This way, the contexts |
| 4140 | * that did not cause the out of memory problem might be able to |
| 4141 | * continue execution. |
| 4142 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4143 | static void IgnoreOutOfMemoryException(); |
| 4144 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4145 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4146 | * 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] | 4147 | * fatal errors such as out-of-memory situations. |
| 4148 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4149 | static bool IsDead(); |
| 4150 | |
| 4151 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4152 | * The following 4 functions are to be used when V8 is built with |
| 4153 | * the 'compress_startup_data' flag enabled. In this case, the |
| 4154 | * embedder must decompress startup data prior to initializing V8. |
| 4155 | * |
| 4156 | * This is how interaction with V8 should look like: |
| 4157 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 4158 | * v8::StartupData* compressed_data = |
| 4159 | * new v8::StartupData[compressed_data_count]; |
| 4160 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 4161 | * ... decompress data (compressed_data can be updated in-place) ... |
| 4162 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 4163 | * ... now V8 can be initialized |
| 4164 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4165 | * |
| 4166 | * A helper class StartupDataDecompressor is provided. It implements |
| 4167 | * the protocol of the interaction described above, and can be used in |
| 4168 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4169 | */ |
| 4170 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 4171 | static int GetCompressedStartupDataCount(); |
| 4172 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 4173 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 4174 | |
| 4175 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4176 | * Adds a message listener. |
| 4177 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4178 | * 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] | 4179 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4180 | * |
| 4181 | * If data is specified, it will be passed to the callback when it is called. |
| 4182 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4183 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4184 | static bool AddMessageListener(MessageCallback that, |
| 4185 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4186 | |
| 4187 | /** |
| 4188 | * Remove all message listeners from the specified callback function. |
| 4189 | */ |
| 4190 | static void RemoveMessageListeners(MessageCallback that); |
| 4191 | |
| 4192 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4193 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 4194 | * and report it to the message listeners. The option is off by default. |
| 4195 | */ |
| 4196 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 4197 | bool capture, |
| 4198 | int frame_limit = 10, |
| 4199 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 4200 | |
| 4201 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4202 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4203 | */ |
| 4204 | static void SetFlagsFromString(const char* str, int length); |
| 4205 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4206 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4207 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4208 | */ |
| 4209 | static void SetFlagsFromCommandLine(int* argc, |
| 4210 | char** argv, |
| 4211 | bool remove_flags); |
| 4212 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4213 | /** Get the version string. */ |
| 4214 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4215 | |
| 4216 | /** |
| 4217 | * Enables the host application to provide a mechanism for recording |
| 4218 | * statistics counters. |
| 4219 | */ |
| 4220 | static void SetCounterFunction(CounterLookupCallback); |
| 4221 | |
| 4222 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4223 | * Enables the host application to provide a mechanism for recording |
| 4224 | * histograms. The CreateHistogram function returns a |
| 4225 | * histogram which will later be passed to the AddHistogramSample |
| 4226 | * function. |
| 4227 | */ |
| 4228 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4229 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4231 | /** Callback function for reporting failed access checks.*/ |
| 4232 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4233 | |
| 4234 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4235 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4236 | * garbage collection. Allocations are not allowed in the |
| 4237 | * callback function, you therefore cannot manipulate objects (set |
| 4238 | * or delete properties for example) since it is possible such |
| 4239 | * operations will result in the allocation of objects. It is possible |
| 4240 | * to specify the GCType filter for your callback. But it is not possible to |
| 4241 | * register the same callback function two times with different |
| 4242 | * GCType filters. |
| 4243 | */ |
| 4244 | static void AddGCPrologueCallback( |
| 4245 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4246 | |
| 4247 | /** |
| 4248 | * This function removes callback which was installed by |
| 4249 | * AddGCPrologueCallback function. |
| 4250 | */ |
| 4251 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4252 | |
| 4253 | /** |
| 4254 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4255 | * Enables the host application to receive a notification before a |
| 4256 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4257 | * callback function, you therefore cannot manipulate objects (set |
| 4258 | * or delete properties for example) since it is possible such |
| 4259 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4260 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4261 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4262 | |
| 4263 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4264 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4265 | * garbage collection. Allocations are not allowed in the |
| 4266 | * callback function, you therefore cannot manipulate objects (set |
| 4267 | * or delete properties for example) since it is possible such |
| 4268 | * operations will result in the allocation of objects. It is possible |
| 4269 | * to specify the GCType filter for your callback. But it is not possible to |
| 4270 | * register the same callback function two times with different |
| 4271 | * GCType filters. |
| 4272 | */ |
| 4273 | static void AddGCEpilogueCallback( |
| 4274 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4275 | |
| 4276 | /** |
| 4277 | * This function removes callback which was installed by |
| 4278 | * AddGCEpilogueCallback function. |
| 4279 | */ |
| 4280 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4281 | |
| 4282 | /** |
| 4283 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4284 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4285 | * major garbage collection. Allocations are not allowed in the |
| 4286 | * callback function, you therefore cannot manipulate objects (set |
| 4287 | * or delete properties for example) since it is possible such |
| 4288 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4289 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4290 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4291 | |
| 4292 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4293 | * Enables the host application to provide a mechanism to be notified |
| 4294 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4295 | */ |
| 4296 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4297 | ObjectSpace space, |
| 4298 | AllocationAction action); |
| 4299 | |
| 4300 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4301 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4302 | */ |
| 4303 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4304 | |
| 4305 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4306 | * Adds a callback to notify the host application when a script finished |
| 4307 | * running. If a script re-enters the runtime during executing, the |
| 4308 | * CallCompletedCallback is only invoked when the outer-most script |
| 4309 | * execution ends. Executing scripts inside the callback do not trigger |
| 4310 | * further callbacks. |
| 4311 | */ |
| 4312 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4313 | |
| 4314 | /** |
| 4315 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4316 | */ |
| 4317 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4318 | |
| 4319 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4320 | * Allows the host application to group objects together. If one |
| 4321 | * object in the group is alive, all objects in the group are alive. |
| 4322 | * After each garbage collection, object groups are removed. It is |
| 4323 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4324 | * function, for instance to simulate DOM tree connections among JS |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4325 | * wrapper objects. Object groups for all dependent handles need to |
| 4326 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 4327 | * garbage collection types it is sufficient to provide object groups |
| 4328 | * for partially dependent handles only. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4329 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4330 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4331 | // TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId and |
| 4332 | // HeapProfiler::SetRetainedObjectInfo instead. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4333 | static void AddObjectGroup(Persistent<Value>* objects, |
| 4334 | size_t length, |
| 4335 | RetainedObjectInfo* info = NULL); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4336 | static void AddObjectGroup(Isolate* isolate, |
| 4337 | Persistent<Value>* objects, |
| 4338 | size_t length, |
| 4339 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4340 | |
| 4341 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4342 | * Allows the host application to declare implicit references between |
| 4343 | * the objects: if |parent| is alive, all |children| are alive too. |
| 4344 | * After each garbage collection, all implicit references |
| 4345 | * are removed. It is intended to be used in the before-garbage-collection |
| 4346 | * callback function. |
| 4347 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4348 | // TODO(marja): Deprecate AddImplicitReferences. Use |
| 4349 | // Isolate::SetReferenceFromGroup instead. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4350 | static void AddImplicitReferences(Persistent<Object> parent, |
| 4351 | Persistent<Value>* children, |
| 4352 | size_t length); |
| 4353 | |
| 4354 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4355 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4356 | * initialize from scratch. This function is called implicitly if |
| 4357 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4358 | */ |
| 4359 | static bool Initialize(); |
| 4360 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4361 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4362 | * Allows the host application to provide a callback which can be used |
| 4363 | * as a source of entropy for random number generators. |
| 4364 | */ |
| 4365 | static void SetEntropySource(EntropySource source); |
| 4366 | |
| 4367 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4368 | * Allows the host application to provide a callback that allows v8 to |
| 4369 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4370 | */ |
| 4371 | static void SetReturnAddressLocationResolver( |
| 4372 | ReturnAddressLocationResolver return_address_resolver); |
| 4373 | |
| 4374 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4375 | * Allows the host application to provide the address of a function that's |
| 4376 | * invoked on entry to every V8-generated function. |
| 4377 | * Note that \p entry_hook is invoked at the very start of each |
| 4378 | * generated function. |
| 4379 | * |
| 4380 | * \param entry_hook a function that will be invoked on entry to every |
| 4381 | * V8-generated function. |
| 4382 | * \returns true on success on supported platforms, false on failure. |
| 4383 | * \note Setting a new entry hook function when one is already active will |
| 4384 | * fail. |
| 4385 | */ |
| 4386 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4387 | |
| 4388 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4389 | * Allows the host application to provide the address of a function that is |
| 4390 | * notified each time code is added, moved or removed. |
| 4391 | * |
| 4392 | * \param options options for the JIT code event handler. |
| 4393 | * \param event_handler the JIT code event handler, which will be invoked |
| 4394 | * each time code is added, moved or removed. |
| 4395 | * \note \p event_handler won't get notified of existent code. |
| 4396 | * \note since code removal notifications are not currently issued, the |
| 4397 | * \p event_handler may get notifications of code that overlaps earlier |
| 4398 | * code notifications. This happens when code areas are reused, and the |
| 4399 | * earlier overlapping code areas should therefore be discarded. |
| 4400 | * \note the events passed to \p event_handler and the strings they point to |
| 4401 | * are not guaranteed to live past each call. The \p event_handler must |
| 4402 | * copy strings and other parameters it needs to keep around. |
| 4403 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4404 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4405 | * new members. The \p event_handler function must ignore event codes |
| 4406 | * it does not recognize to maintain future compatibility. |
| 4407 | */ |
| 4408 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4409 | JitCodeEventHandler event_handler); |
| 4410 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4411 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4412 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4413 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4414 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4415 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4416 | /** |
| 4417 | * Suspends recording of tick samples in the profiler. |
| 4418 | * When the V8 profiling mode is enabled (usually via command line |
| 4419 | * switches) this function suspends recording of tick samples. |
| 4420 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4421 | * |
| 4422 | * See also the --prof and --prof_auto command line switches to |
| 4423 | * enable V8 profiling. |
| 4424 | */ |
| 4425 | static void PauseProfiler(); |
| 4426 | |
| 4427 | /** |
| 4428 | * Resumes recording of tick samples in the profiler. |
| 4429 | * See also PauseProfiler(). |
| 4430 | */ |
| 4431 | static void ResumeProfiler(); |
| 4432 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4433 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4434 | * Return whether profiler is currently paused. |
| 4435 | */ |
| 4436 | static bool IsProfilerPaused(); |
| 4437 | |
| 4438 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4439 | * Retrieve the V8 thread id of the calling thread. |
| 4440 | * |
| 4441 | * The thread id for a thread should only be retrieved after the V8 |
| 4442 | * lock has been acquired with a Locker object with that thread. |
| 4443 | */ |
| 4444 | static int GetCurrentThreadId(); |
| 4445 | |
| 4446 | /** |
| 4447 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4448 | * be used to terminate long-running scripts. |
| 4449 | * |
| 4450 | * TerminateExecution should only be called when then V8 lock has |
| 4451 | * been acquired with a Locker object. Therefore, in order to be |
| 4452 | * able to terminate long-running threads, preemption must be |
| 4453 | * enabled to allow the user of TerminateExecution to acquire the |
| 4454 | * lock. |
| 4455 | * |
| 4456 | * The termination is achieved by throwing an exception that is |
| 4457 | * uncatchable by JavaScript exception handlers. Termination |
| 4458 | * 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] | 4459 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4460 | * exception handler that catches an exception should check if that |
| 4461 | * exception is a termination exception and immediately return if |
| 4462 | * that is the case. Returning immediately in that case will |
| 4463 | * continue the propagation of the termination exception if needed. |
| 4464 | * |
| 4465 | * The thread id passed to TerminateExecution must have been |
| 4466 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4467 | * |
| 4468 | * \param thread_id The thread id of the thread to terminate. |
| 4469 | */ |
| 4470 | static void TerminateExecution(int thread_id); |
| 4471 | |
| 4472 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4473 | * Forcefully terminate the current thread of JavaScript execution |
| 4474 | * in the given isolate. If no isolate is provided, the default |
| 4475 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4476 | * |
| 4477 | * This method can be used by any thread even if that thread has not |
| 4478 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4479 | * |
| 4480 | * \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] | 4481 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4482 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4483 | |
| 4484 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4485 | * Is V8 terminating JavaScript execution. |
| 4486 | * |
| 4487 | * Returns true if JavaScript execution is currently terminating |
| 4488 | * because of a call to TerminateExecution. In that case there are |
| 4489 | * still JavaScript frames on the stack and the termination |
| 4490 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4491 | * |
| 4492 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4493 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4494 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4495 | |
| 4496 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4497 | * Resume execution capability in the given isolate, whose execution |
| 4498 | * was previously forcefully terminated using TerminateExecution(). |
| 4499 | * |
| 4500 | * When execution is forcefully terminated using TerminateExecution(), |
| 4501 | * the isolate can not resume execution until all JavaScript frames |
| 4502 | * have propagated the uncatchable exception which is generated. This |
| 4503 | * method allows the program embedding the engine to handle the |
| 4504 | * termination event and resume execution capability, even if |
| 4505 | * JavaScript frames remain on the stack. |
| 4506 | * |
| 4507 | * This method can be used by any thread even if that thread has not |
| 4508 | * acquired the V8 lock with a Locker object. |
| 4509 | * |
| 4510 | * \param isolate The isolate in which to resume execution capability. |
| 4511 | */ |
| 4512 | static void CancelTerminateExecution(Isolate* isolate); |
| 4513 | |
| 4514 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4515 | * Releases any resources used by v8 and stops any utility threads |
| 4516 | * that may be running. Note that disposing v8 is permanent, it |
| 4517 | * cannot be reinitialized. |
| 4518 | * |
| 4519 | * It should generally not be necessary to dispose v8 before exiting |
| 4520 | * a process, this should happen automatically. It is only necessary |
| 4521 | * to use if the process needs the resources taken up by v8. |
| 4522 | */ |
| 4523 | static bool Dispose(); |
| 4524 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4525 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4526 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4527 | |
| 4528 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4529 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4530 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4531 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4532 | */ |
| 4533 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4534 | |
| 4535 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4536 | * Iterates through all the persistent handles in the current isolate's heap |
| 4537 | * that have class_ids. |
| 4538 | */ |
| 4539 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4540 | |
| 4541 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4542 | * Iterates through all the persistent handles in the current isolate's heap |
| 4543 | * that have class_ids and are candidates to be marked as partially dependent |
| 4544 | * handles. This will visit handles to young objects created since the last |
| 4545 | * garbage collection but is free to visit an arbitrary superset of these |
| 4546 | * objects. |
| 4547 | */ |
| 4548 | static void VisitHandlesForPartialDependence( |
| 4549 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4550 | |
| 4551 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4552 | * Optional notification that the embedder is idle. |
| 4553 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4554 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4555 | * Returns true if the embedder should stop calling IdleNotification |
| 4556 | * until real work has been done. This indicates that V8 has done |
| 4557 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4558 | * |
| 4559 | * The hint argument specifies the amount of work to be done in the function |
| 4560 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4561 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4562 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4563 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4564 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4565 | /** |
| 4566 | * Optional notification that the system is running low on memory. |
| 4567 | * V8 uses these notifications to attempt to free memory. |
| 4568 | */ |
| 4569 | static void LowMemoryNotification(); |
| 4570 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4571 | /** |
| 4572 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4573 | * these notifications to guide the GC heuristic. Returns the number |
| 4574 | * of context disposals - including this one - since the last time |
| 4575 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4576 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4577 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4578 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4579 | private: |
| 4580 | V8(); |
| 4581 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4582 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4583 | internal::Object** handle); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 4584 | static void DisposeGlobal(internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4585 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4586 | static void MakeWeak(internal::Isolate* isolate, |
| 4587 | internal::Object** global_handle, |
| 4588 | void* data, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4589 | RevivableCallback weak_reference_callback, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4590 | NearDeathCallback near_death_callback); |
| 4591 | static void ClearWeak(internal::Isolate* isolate, |
| 4592 | internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4593 | |
| 4594 | template <class T> friend class Handle; |
| 4595 | template <class T> friend class Local; |
| 4596 | template <class T> friend class Persistent; |
| 4597 | friend class Context; |
| 4598 | }; |
| 4599 | |
| 4600 | |
| 4601 | /** |
| 4602 | * An external exception handler. |
| 4603 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4604 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4605 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4606 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4607 | * Creates a new try/catch block and registers it with v8. Note that |
| 4608 | * all TryCatch blocks should be stack allocated because the memory |
| 4609 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4610 | */ |
| 4611 | TryCatch(); |
| 4612 | |
| 4613 | /** |
| 4614 | * Unregisters and deletes this try/catch block. |
| 4615 | */ |
| 4616 | ~TryCatch(); |
| 4617 | |
| 4618 | /** |
| 4619 | * Returns true if an exception has been caught by this try/catch block. |
| 4620 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4621 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4622 | |
| 4623 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4624 | * 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] | 4625 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4626 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4627 | * cleanup needed and then return. If CanContinue returns false and |
| 4628 | * HasTerminated returns true, it is possible to call |
| 4629 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4630 | */ |
| 4631 | bool CanContinue() const; |
| 4632 | |
| 4633 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4634 | * Returns true if an exception has been caught due to script execution |
| 4635 | * being terminated. |
| 4636 | * |
| 4637 | * There is no JavaScript representation of an execution termination |
| 4638 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4639 | * methods are called to terminate a long-running script. |
| 4640 | * |
| 4641 | * If such an exception has been thrown, HasTerminated will return true, |
| 4642 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4643 | * to continue calling into the engine. |
| 4644 | */ |
| 4645 | bool HasTerminated() const; |
| 4646 | |
| 4647 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4648 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4649 | * it being caught again by this same TryCatch. As with ThrowException |
| 4650 | * it is illegal to execute any JavaScript operations after calling |
| 4651 | * ReThrow; the caller must return immediately to where the exception |
| 4652 | * is caught. |
| 4653 | */ |
| 4654 | Handle<Value> ReThrow(); |
| 4655 | |
| 4656 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4657 | * Returns the exception caught by this try/catch block. If no exception has |
| 4658 | * been caught an empty handle is returned. |
| 4659 | * |
| 4660 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4661 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4662 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4663 | |
| 4664 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4665 | * Returns the .stack property of the thrown object. If no .stack |
| 4666 | * property is present an empty handle is returned. |
| 4667 | */ |
| 4668 | Local<Value> StackTrace() const; |
| 4669 | |
| 4670 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4671 | * Returns the message associated with this exception. If there is |
| 4672 | * no message associated an empty handle is returned. |
| 4673 | * |
| 4674 | * The returned handle is valid until this TryCatch block has been |
| 4675 | * destroyed. |
| 4676 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4677 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4678 | |
| 4679 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4680 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4681 | * After this method has been called, HasCaught() will return false. |
| 4682 | * |
| 4683 | * It is not necessary to clear a try/catch block before using it again; if |
| 4684 | * another exception is thrown the previously caught exception will just be |
| 4685 | * overwritten. However, it is often a good idea since it makes it easier |
| 4686 | * to determine which operation threw a given exception. |
| 4687 | */ |
| 4688 | void Reset(); |
| 4689 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4690 | /** |
| 4691 | * Set verbosity of the external exception handler. |
| 4692 | * |
| 4693 | * By default, exceptions that are caught by an external exception |
| 4694 | * handler are not reported. Call SetVerbose with true on an |
| 4695 | * external exception handler to have exceptions caught by the |
| 4696 | * handler reported as if they were not caught. |
| 4697 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4698 | void SetVerbose(bool value); |
| 4699 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4700 | /** |
| 4701 | * Set whether or not this TryCatch should capture a Message object |
| 4702 | * which holds source information about where the exception |
| 4703 | * occurred. True by default. |
| 4704 | */ |
| 4705 | void SetCaptureMessage(bool value); |
| 4706 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4707 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4708 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4709 | TryCatch(const TryCatch&); |
| 4710 | void operator=(const TryCatch&); |
| 4711 | void* operator new(size_t size); |
| 4712 | void operator delete(void*, size_t); |
| 4713 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4714 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4715 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4716 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4717 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4718 | bool is_verbose_ : 1; |
| 4719 | bool can_continue_ : 1; |
| 4720 | bool capture_message_ : 1; |
| 4721 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4722 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4723 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4724 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4725 | }; |
| 4726 | |
| 4727 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4728 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4729 | |
| 4730 | |
| 4731 | /** |
| 4732 | * Ignore |
| 4733 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4734 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4735 | public: |
| 4736 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4737 | : name_count_(name_count), names_(names) { } |
| 4738 | private: |
| 4739 | friend class ImplementationUtilities; |
| 4740 | int name_count_; |
| 4741 | const char** names_; |
| 4742 | }; |
| 4743 | |
| 4744 | |
| 4745 | /** |
| 4746 | * A sandboxed execution context with its own set of built-in objects |
| 4747 | * and functions. |
| 4748 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4749 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4750 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4751 | /** |
| 4752 | * Returns the global proxy object or global object itself for |
| 4753 | * detached contexts. |
| 4754 | * |
| 4755 | * Global proxy object is a thin wrapper whose prototype points to |
| 4756 | * actual context's global object with the properties like Object, etc. |
| 4757 | * This is done that way for security reasons (for more details see |
| 4758 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4759 | * |
| 4760 | * Please note that changes to global proxy object prototype most probably |
| 4761 | * would break VM---v8 expects only global object as a prototype of |
| 4762 | * global proxy object. |
| 4763 | * |
| 4764 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4765 | * object until global is reattached with ReattachGlobal(). |
| 4766 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4767 | Local<Object> Global(); |
| 4768 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4769 | /** |
| 4770 | * Detaches the global object from its context before |
| 4771 | * the global object can be reused to create a new context. |
| 4772 | */ |
| 4773 | void DetachGlobal(); |
| 4774 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4775 | /** |
| 4776 | * Reattaches a global object to a context. This can be used to |
| 4777 | * restore the connection between a global object and a context |
| 4778 | * after DetachGlobal has been called. |
| 4779 | * |
| 4780 | * \param global_object The global object to reattach to the |
| 4781 | * context. For this to work, the global object must be the global |
| 4782 | * object that was associated with this context before a call to |
| 4783 | * DetachGlobal. |
| 4784 | */ |
| 4785 | void ReattachGlobal(Handle<Object> global_object); |
| 4786 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4787 | /** |
| 4788 | * Creates a new context and returns a handle to the newly allocated |
| 4789 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4790 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4791 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4792 | * |
| 4793 | * \param extensions An optional extension configuration containing |
| 4794 | * the extensions to be installed in the newly created context. |
| 4795 | * |
| 4796 | * \param global_template An optional object template from which the |
| 4797 | * global object for the newly created context will be created. |
| 4798 | * |
| 4799 | * \param global_object An optional global object to be reused for |
| 4800 | * the newly created context. This global object must have been |
| 4801 | * created by a previous call to Context::New with the same global |
| 4802 | * template. The state of the global object will be completely reset |
| 4803 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4804 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4805 | static Local<Context> New( |
| 4806 | Isolate* isolate, |
| 4807 | ExtensionConfiguration* extensions = NULL, |
| 4808 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4809 | Handle<Value> global_object = Handle<Value>()); |
| 4810 | |
| 4811 | /** Deprecated. Use Isolate version instead. */ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4812 | V8_DEPRECATED(static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4813 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4814 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4815 | Handle<Value> global_object = Handle<Value>())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4816 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4817 | /** Returns the last entered context. */ |
| 4818 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4819 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4820 | // TODO(svenpanne) Actually deprecate this. |
| 4821 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4822 | static Local<Context> GetCurrent(); |
| 4823 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4824 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4825 | * Returns the context of the calling JavaScript code. That is the |
| 4826 | * context of the top-most JavaScript frame. If there are no |
| 4827 | * JavaScript frames an empty handle is returned. |
| 4828 | */ |
| 4829 | static Local<Context> GetCalling(); |
| 4830 | |
| 4831 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4832 | * Sets the security token for the context. To access an object in |
| 4833 | * another context, the security tokens must match. |
| 4834 | */ |
| 4835 | void SetSecurityToken(Handle<Value> token); |
| 4836 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4837 | /** Restores the security token to the default value. */ |
| 4838 | void UseDefaultSecurityToken(); |
| 4839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4840 | /** Returns the security token of this context.*/ |
| 4841 | Handle<Value> GetSecurityToken(); |
| 4842 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4843 | /** |
| 4844 | * Enter this context. After entering a context, all code compiled |
| 4845 | * and run is compiled and run in this context. If another context |
| 4846 | * is already entered, this old context is saved so it can be |
| 4847 | * restored when the new context is exited. |
| 4848 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4849 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4850 | |
| 4851 | /** |
| 4852 | * Exit this context. Exiting the current context restores the |
| 4853 | * context that was in place when entering the current context. |
| 4854 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4855 | void Exit(); |
| 4856 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4857 | /** 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] | 4858 | bool HasOutOfMemoryException(); |
| 4859 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4860 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4861 | static bool InContext(); |
| 4862 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4863 | /** Returns an isolate associated with a current context. */ |
| 4864 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4865 | |
| 4866 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4867 | * Gets the embedder data with the given index, which must have been set by a |
| 4868 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4869 | * currently has a special meaning for Chrome's debugger. |
| 4870 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4871 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4872 | |
| 4873 | /** |
| 4874 | * Sets the embedder data with the given index, growing the data as |
| 4875 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4876 | * debugger. |
| 4877 | */ |
| 4878 | void SetEmbedderData(int index, Handle<Value> value); |
| 4879 | |
| 4880 | /** |
| 4881 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4882 | * index, which must have bees set by a previous call to |
| 4883 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4884 | * currently has a special meaning for Chrome's debugger. |
| 4885 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4886 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4887 | |
| 4888 | /** |
| 4889 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4890 | * index, growing the data as needed. Note that index 0 currently has a |
| 4891 | * special meaning for Chrome's debugger. |
| 4892 | */ |
| 4893 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4894 | |
| 4895 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4896 | * Control whether code generation from strings is allowed. Calling |
| 4897 | * this method with false will disable 'eval' and the 'Function' |
| 4898 | * constructor for code running in this context. If 'eval' or the |
| 4899 | * 'Function' constructor are used an exception will be thrown. |
| 4900 | * |
| 4901 | * If code generation from strings is not allowed the |
| 4902 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4903 | * set before blocking the call to 'eval' or the 'Function' |
| 4904 | * constructor. If that callback returns true, the call will be |
| 4905 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4906 | * set an exception will be thrown. |
| 4907 | */ |
| 4908 | void AllowCodeGenerationFromStrings(bool allow); |
| 4909 | |
| 4910 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4911 | * Returns true if code generation from strings is allowed for the context. |
| 4912 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4913 | */ |
| 4914 | bool IsCodeGenerationFromStringsAllowed(); |
| 4915 | |
| 4916 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4917 | * Sets the error description for the exception that is thrown when |
| 4918 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4919 | * constructor are called. |
| 4920 | */ |
| 4921 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4922 | |
| 4923 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4924 | * Stack-allocated class which sets the execution context for all |
| 4925 | * operations executed within a local scope. |
| 4926 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4927 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4928 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4929 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4930 | context_->Enter(); |
| 4931 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4932 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4933 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4934 | : context_(Handle<Context>::New(isolate, context)) { |
| 4935 | #else |
| 4936 | : context_(Local<Context>::New(isolate, context)) { |
| 4937 | #endif |
| 4938 | context_->Enter(); |
| 4939 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4940 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4941 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4942 | private: |
| 4943 | Handle<Context> context_; |
| 4944 | }; |
| 4945 | |
| 4946 | private: |
| 4947 | friend class Value; |
| 4948 | friend class Script; |
| 4949 | friend class Object; |
| 4950 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4951 | |
| 4952 | Local<Value> SlowGetEmbedderData(int index); |
| 4953 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4954 | }; |
| 4955 | |
| 4956 | |
| 4957 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4958 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4959 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4960 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4961 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4962 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4963 | * constraint is not violated. In addition to any other synchronization |
| 4964 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4965 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4966 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4967 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4968 | * construction and destruction, the current thread is allowed to use the locked |
| 4969 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4970 | * 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] | 4971 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4972 | * Sample usage: |
| 4973 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4974 | * ... |
| 4975 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4976 | * v8::Locker locker(isolate); |
| 4977 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4978 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4979 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4980 | * ... |
| 4981 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4982 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4983 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4984 | * If you wish to stop using V8 in a thread A you can do this either by |
| 4985 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 4986 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4987 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4988 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4989 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4990 | * isolate->Exit(); |
| 4991 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4992 | * ... |
| 4993 | * // Code not using V8 goes here while V8 can run in another thread. |
| 4994 | * ... |
| 4995 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4996 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4997 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4998 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4999 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 5000 | * 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] | 5001 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5002 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 5003 | * given thread. This can be useful if you have code that can be called either |
| 5004 | * from code that holds the lock or from code that does not. The Unlocker is |
| 5005 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 5006 | * 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] | 5007 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5008 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 5009 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5010 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5011 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5012 | * // V8 not locked. |
| 5013 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5014 | * v8::Locker locker(isolate); |
| 5015 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | * // V8 locked. |
| 5017 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5018 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | * // V8 still locked (2 levels). |
| 5020 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5021 | * isolate->Exit(); |
| 5022 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5023 | * // V8 not locked. |
| 5024 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5025 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5026 | * // V8 locked again (2 levels). |
| 5027 | * } |
| 5028 | * // V8 still locked (1 level). |
| 5029 | * } |
| 5030 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5031 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5032 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5033 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5034 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5035 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5036 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5037 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5038 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 5039 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5040 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5041 | V8_DEPRECATED(Unlocker()); |
| 5042 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5043 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5044 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5045 | void Initialize(Isolate* isolate); |
| 5046 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5047 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5048 | }; |
| 5049 | |
| 5050 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5051 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5052 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5053 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5054 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5055 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5056 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 5057 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5058 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5059 | V8_DEPRECATED(Locker()); |
| 5060 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5062 | |
| 5063 | /** |
| 5064 | * Start preemption. |
| 5065 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5066 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5067 | * that will switch between multiple threads that are in contention |
| 5068 | * for the V8 lock. |
| 5069 | */ |
| 5070 | static void StartPreemption(int every_n_ms); |
| 5071 | |
| 5072 | /** |
| 5073 | * Stop preemption. |
| 5074 | */ |
| 5075 | static void StopPreemption(); |
| 5076 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5077 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5078 | * Returns whether or not the locker for a given isolate, is locked by the |
| 5079 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5080 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5081 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5082 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5083 | /** |
| 5084 | * Returns whether v8::Locker is being used by this V8 instance. |
| 5085 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5086 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5088 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5089 | void Initialize(Isolate* isolate); |
| 5090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5091 | bool has_lock_; |
| 5092 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5093 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5094 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5095 | static bool active_; |
| 5096 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5097 | // Disallow copying and assigning. |
| 5098 | Locker(const Locker&); |
| 5099 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5100 | }; |
| 5101 | |
| 5102 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5103 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5104 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 5105 | */ |
| 5106 | struct HeapStatsUpdate; |
| 5107 | |
| 5108 | |
| 5109 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5110 | * An interface for exporting data from V8, using "push" model. |
| 5111 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5112 | class V8EXPORT OutputStream { // NOLINT |
| 5113 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5114 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5115 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5116 | }; |
| 5117 | enum WriteResult { |
| 5118 | kContinue = 0, |
| 5119 | kAbort = 1 |
| 5120 | }; |
| 5121 | virtual ~OutputStream() {} |
| 5122 | /** Notify about the end of stream. */ |
| 5123 | virtual void EndOfStream() = 0; |
| 5124 | /** Get preferred output chunk size. Called only once. */ |
| 5125 | virtual int GetChunkSize() { return 1024; } |
| 5126 | /** Get preferred output encoding. Called only once. */ |
| 5127 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 5128 | /** |
| 5129 | * Writes the next chunk of snapshot data into the stream. Writing |
| 5130 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5131 | * will not be called in case writing was aborted. |
| 5132 | */ |
| 5133 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5134 | /** |
| 5135 | * Writes the next chunk of heap stats data into the stream. Writing |
| 5136 | * can be stopped by returning kAbort as function result. EndOfStream |
| 5137 | * will not be called in case writing was aborted. |
| 5138 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5139 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 5140 | return kAbort; |
| 5141 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5142 | }; |
| 5143 | |
| 5144 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5145 | /** |
| 5146 | * An interface for reporting progress and controlling long-running |
| 5147 | * activities. |
| 5148 | */ |
| 5149 | class V8EXPORT ActivityControl { // NOLINT |
| 5150 | public: |
| 5151 | enum ControlOption { |
| 5152 | kContinue = 0, |
| 5153 | kAbort = 1 |
| 5154 | }; |
| 5155 | virtual ~ActivityControl() {} |
| 5156 | /** |
| 5157 | * Notify about current progress. The activity can be stopped by |
| 5158 | * returning kAbort as the callback result. |
| 5159 | */ |
| 5160 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 5161 | }; |
| 5162 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5163 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5164 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5165 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5166 | |
| 5167 | namespace internal { |
| 5168 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5169 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 5170 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5171 | |
| 5172 | // Tag information for HeapObject. |
| 5173 | const int kHeapObjectTag = 1; |
| 5174 | const int kHeapObjectTagSize = 2; |
| 5175 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 5176 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5177 | // Tag information for Smi. |
| 5178 | const int kSmiTag = 0; |
| 5179 | const int kSmiTagSize = 1; |
| 5180 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 5181 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5182 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5183 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5184 | template<int kSmiShiftSize> |
| 5185 | V8_INLINE(internal::Object* IntToSmi(int value)) { |
| 5186 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5187 | intptr_t tagged_value = |
| 5188 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
| 5189 | return reinterpret_cast<internal::Object*>(tagged_value); |
| 5190 | } |
| 5191 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5192 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5193 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5194 | static const int kSmiShiftSize = 0; |
| 5195 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5196 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5197 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5198 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 5199 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 5200 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5201 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5202 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5203 | } |
| 5204 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5205 | // To be representable as an tagged small integer, the two |
| 5206 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 5207 | // sign-extension. To check this we add 01 to the two |
| 5208 | // most-significant bits, and check if the most-significant bit is 0 |
| 5209 | // |
| 5210 | // CAUTION: The original code below: |
| 5211 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 5212 | // may lead to incorrect results according to the C language spec, and |
| 5213 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 5214 | // compiler may produce undefined results in case of signed integer |
| 5215 | // overflow. The computation must be done w/ unsigned ints. |
| 5216 | return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; |
| 5217 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5218 | }; |
| 5219 | |
| 5220 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5221 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5222 | static const int kSmiShiftSize = 31; |
| 5223 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5224 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5225 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5226 | // Shift down and throw away top 32 bits. |
| 5227 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5228 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5229 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5230 | return internal::IntToSmi<kSmiShiftSize>(value); |
| 5231 | } |
| 5232 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5233 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 5234 | return (value == static_cast<int32_t>(value)); |
| 5235 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5236 | }; |
| 5237 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5238 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5239 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5240 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5241 | |
| 5242 | /** |
| 5243 | * This class exports constants and functionality from within v8 that |
| 5244 | * is necessary to implement inline functions in the v8 api. Don't |
| 5245 | * depend on functions and constants defined here. |
| 5246 | */ |
| 5247 | class Internals { |
| 5248 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5249 | // These values match non-compiler-dependent values defined within |
| 5250 | // the implementation of v8. |
| 5251 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5252 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5253 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5254 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5255 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5256 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5257 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5258 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5259 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5260 | static const int kContextEmbedderDataIndex = 64; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5261 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5262 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5263 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5264 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5265 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5266 | static const int kIsolateStateOffset = 0; |
| 5267 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5268 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5269 | static const int kUndefinedValueRootIndex = 5; |
| 5270 | static const int kNullValueRootIndex = 7; |
| 5271 | static const int kTrueValueRootIndex = 8; |
| 5272 | static const int kFalseValueRootIndex = 9; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 5273 | static const int kEmptyStringRootIndex = 129; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5274 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5275 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5276 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5277 | static const int kNodeStateMask = 0xf; |
| 5278 | static const int kNodeStateIsWeakValue = 2; |
| 5279 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5280 | static const int kNodeIsIndependentShift = 4; |
| 5281 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5282 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5283 | static const int kJSObjectType = 0xae; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5284 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5285 | static const int kOddballType = 0x83; |
| 5286 | static const int kForeignType = 0x86; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5287 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5288 | static const int kUndefinedOddballKind = 5; |
| 5289 | static const int kNullOddballKind = 3; |
| 5290 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5291 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5292 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5293 | kHeapObjectTag); |
| 5294 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5295 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5296 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5297 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5300 | V8_INLINE(static internal::Object* IntToSmi(int value)) { |
| 5301 | return PlatformSmiTagging::IntToSmi(value); |
| 5302 | } |
| 5303 | |
| 5304 | V8_INLINE(static bool IsValidSmi(intptr_t value)) { |
| 5305 | return PlatformSmiTagging::IsValidSmi(value); |
| 5306 | } |
| 5307 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5308 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5309 | typedef internal::Object O; |
| 5310 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5311 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5312 | } |
| 5313 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5314 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5315 | typedef internal::Object O; |
| 5316 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5317 | } |
| 5318 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5319 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5320 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5321 | return representation == kExternalTwoByteRepresentationTag; |
| 5322 | } |
| 5323 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5324 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5325 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5326 | return *reinterpret_cast<int*>(addr) == 1; |
| 5327 | } |
| 5328 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5329 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5330 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5331 | return *addr & (1 << shift); |
| 5332 | } |
| 5333 | |
| 5334 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5335 | bool value, int shift)) { |
| 5336 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5337 | uint8_t mask = 1 << shift; |
| 5338 | *addr = (*addr & ~mask) | (value << shift); |
| 5339 | } |
| 5340 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5341 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5342 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5343 | return *addr & kNodeStateMask; |
| 5344 | } |
| 5345 | |
| 5346 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5347 | uint8_t value)) { |
| 5348 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5349 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5350 | } |
| 5351 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5352 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5353 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5354 | kIsolateEmbedderDataOffset; |
| 5355 | *reinterpret_cast<void**>(addr) = data; |
| 5356 | } |
| 5357 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5358 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5359 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5360 | kIsolateEmbedderDataOffset; |
| 5361 | return *reinterpret_cast<void**>(addr); |
| 5362 | } |
| 5363 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5364 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5365 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5366 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5367 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5368 | } |
| 5369 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5370 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5371 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5372 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5373 | return *reinterpret_cast<T*>(addr); |
| 5374 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5375 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5376 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5377 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5378 | typedef internal::Object O; |
| 5379 | typedef internal::Internals I; |
| 5380 | O* ctx = *reinterpret_cast<O**>(context); |
| 5381 | int embedder_data_offset = I::kContextHeaderSize + |
| 5382 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5383 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5384 | int value_offset = |
| 5385 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5386 | return I::ReadField<T>(embedder_data, value_offset); |
| 5387 | } |
| 5388 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5389 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5390 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5391 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5392 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5393 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5394 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5395 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5396 | }; |
| 5397 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5398 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5399 | |
| 5400 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5401 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5402 | Local<T>::Local() : Handle<T>() { } |
| 5403 | |
| 5404 | |
| 5405 | template <class T> |
| 5406 | Local<T> Local<T>::New(Handle<T> that) { |
| 5407 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5408 | T* that_ptr = *that; |
| 5409 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5410 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5411 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5412 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5413 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5414 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5415 | } |
| 5416 | |
| 5417 | |
| 5418 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5419 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5420 | return New(isolate, that.val_); |
| 5421 | } |
| 5422 | |
| 5423 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5424 | template <class T> |
| 5425 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5426 | return New(isolate, that.val_); |
| 5427 | } |
| 5428 | |
| 5429 | template <class T> |
| 5430 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5431 | if (that == NULL) return Handle<T>(); |
| 5432 | T* that_ptr = that; |
| 5433 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5434 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5435 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5436 | } |
| 5437 | #endif |
| 5438 | |
| 5439 | |
| 5440 | template <class T> |
| 5441 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5442 | if (that == NULL) return Local<T>(); |
| 5443 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5444 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5445 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5446 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5447 | } |
| 5448 | |
| 5449 | |
| 5450 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5451 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5452 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | |
| 5456 | template <class T> |
| 5457 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5458 | return New(Isolate::GetCurrent(), that.val_); |
| 5459 | } |
| 5460 | |
| 5461 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5462 | template <class T> |
| 5463 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5464 | return New(Isolate::GetCurrent(), that.val_); |
| 5465 | } |
| 5466 | #endif |
| 5467 | |
| 5468 | template <class T> |
| 5469 | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5470 | if (that == NULL) return Persistent<T>(); |
| 5471 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5472 | return Persistent<T>(reinterpret_cast<T*>( |
| 5473 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5474 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | |
| 5478 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5479 | bool Persistent<T>::IsIndependent() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5480 | return IsIndependent(Isolate::GetCurrent()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5485 | bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5486 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5487 | if (this->IsEmpty()) return false; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5488 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5489 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5490 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | |
| 5494 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5495 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5496 | return IsNearDeath(Isolate::GetCurrent()); |
| 5497 | } |
| 5498 | |
| 5499 | |
| 5500 | template <class T> |
| 5501 | bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 5502 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5503 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5504 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5505 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5506 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | |
| 5510 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5511 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5512 | return IsWeak(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | |
| 5516 | template <class T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5517 | bool Persistent<T>::IsWeak(Isolate* isolate) const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5518 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5519 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5520 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5521 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5522 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | |
| 5526 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5527 | void Persistent<T>::Dispose() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 5528 | if (this->IsEmpty()) return; |
| 5529 | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); |
| 5530 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5531 | val_ = 0; |
| 5532 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | |
| 5536 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5537 | void Persistent<T>::Dispose(Isolate* isolate) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame^] | 5538 | Dispose(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +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( |
| 5545 | Isolate* isolate, |
| 5546 | P* parameters, |
| 5547 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5548 | TYPE_CHECK(S, T); |
| 5549 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5550 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5551 | reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5552 | parameters, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5553 | reinterpret_cast<Revivable>(callback), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5554 | NULL); |
| 5555 | } |
| 5556 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5557 | |
| 5558 | template <class T> |
| 5559 | template <typename P> |
| 5560 | void Persistent<T>::MakeWeak( |
| 5561 | Isolate* isolate, |
| 5562 | P* parameters, |
| 5563 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5564 | MakeWeak<T, P>(isolate, parameters, callback); |
| 5565 | } |
| 5566 | |
| 5567 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5568 | template <class T> |
| 5569 | void Persistent<T>::MakeWeak(Isolate* isolate, |
| 5570 | void* parameters, |
| 5571 | NearDeathCallback callback) { |
| 5572 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5573 | reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5574 | parameters, |
| 5575 | NULL, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5576 | callback); |
| 5577 | } |
| 5578 | |
| 5579 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5580 | void Persistent<T>::ClearWeak() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5581 | ClearWeak(Isolate::GetCurrent()); |
| 5582 | } |
| 5583 | |
| 5584 | template <class T> |
| 5585 | void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 5586 | V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5587 | reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5590 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5591 | void Persistent<T>::MarkIndependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5592 | MarkIndependent(Isolate::GetCurrent()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | template <class T> |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5596 | void Persistent<T>::MarkIndependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5597 | typedef internal::Internals I; |
| 5598 | if (this->IsEmpty()) return; |
| 5599 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5600 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5601 | true, |
| 5602 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | template <class T> |
| 5606 | void Persistent<T>::MarkPartiallyDependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5607 | MarkPartiallyDependent(Isolate::GetCurrent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | template <class T> |
| 5611 | void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5612 | typedef internal::Internals I; |
| 5613 | if (this->IsEmpty()) return; |
| 5614 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5615 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5616 | true, |
| 5617 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5621 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5622 | SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 5623 | } |
| 5624 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5625 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5626 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5627 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5628 | Dispose(isolate); |
| 5629 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5630 | *this = *New(isolate, other); |
| 5631 | #else |
| 5632 | if (other.IsEmpty()) { |
| 5633 | this->val_ = NULL; |
| 5634 | return; |
| 5635 | } |
| 5636 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5637 | this->val_ = reinterpret_cast<T*>( |
| 5638 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5639 | #endif |
| 5640 | } |
| 5641 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5642 | |
| 5643 | template <class T> |
| 5644 | T* Persistent<T>::ClearAndLeak() { |
| 5645 | T* old; |
| 5646 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5647 | old = **this; |
| 5648 | *this = Persistent<T>(); |
| 5649 | #else |
| 5650 | old = val_; |
| 5651 | val_ = NULL; |
| 5652 | #endif |
| 5653 | return old; |
| 5654 | } |
| 5655 | |
| 5656 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5657 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5658 | void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5659 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5660 | if (this->IsEmpty()) return; |
| 5661 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5662 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5663 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5664 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5665 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5666 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5667 | template <class T> |
| 5668 | uint16_t Persistent<T>::WrapperClassId() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5669 | return WrapperClassId(Isolate::GetCurrent()); |
| 5670 | } |
| 5671 | |
| 5672 | template <class T> |
| 5673 | uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5674 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5675 | if (this->IsEmpty()) return 0; |
| 5676 | if (!I::IsInitialized(isolate)) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5677 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5678 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5679 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5682 | |
| 5683 | template<typename T> |
| 5684 | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} |
| 5685 | |
| 5686 | template<typename T> |
| 5687 | void ReturnValue<T>::Set(const Persistent<T>& handle) { |
| 5688 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5689 | } |
| 5690 | |
| 5691 | template<typename T> |
| 5692 | void ReturnValue<T>::Set(const Handle<T> handle) { |
| 5693 | *value_ = *reinterpret_cast<internal::Object**>(*handle); |
| 5694 | } |
| 5695 | |
| 5696 | template<typename T> |
| 5697 | void ReturnValue<T>::Set(Isolate* isolate, double i) { |
| 5698 | Set(Number::New(isolate, i)); |
| 5699 | } |
| 5700 | |
| 5701 | template<typename T> |
| 5702 | void ReturnValue<T>::Set(Isolate* isolate, int32_t i) { |
| 5703 | typedef internal::Internals I; |
| 5704 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5705 | *value_ = I::IntToSmi(i); |
| 5706 | return; |
| 5707 | } |
| 5708 | Set(Integer::New(i, isolate)); |
| 5709 | } |
| 5710 | |
| 5711 | template<typename T> |
| 5712 | void ReturnValue<T>::Set(Isolate* isolate, uint32_t i) { |
| 5713 | typedef internal::Internals I; |
| 5714 | if (V8_LIKELY(I::IsValidSmi(i))) { |
| 5715 | *value_ = I::IntToSmi(i); |
| 5716 | return; |
| 5717 | } |
| 5718 | Set(Integer::NewFromUnsigned(i, isolate)); |
| 5719 | } |
| 5720 | |
| 5721 | template<typename T> |
| 5722 | void ReturnValue<T>::Set(Isolate* isolate, bool value) { |
| 5723 | if (value) { |
| 5724 | SetTrue(isolate); |
| 5725 | } else { |
| 5726 | SetFalse(isolate); |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | template<typename T> |
| 5731 | void ReturnValue<T>::SetTrue(Isolate* isolate) { |
| 5732 | typedef internal::Internals I; |
| 5733 | *value_ = *I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 5734 | } |
| 5735 | |
| 5736 | template<typename T> |
| 5737 | void ReturnValue<T>::SetFalse(Isolate* isolate) { |
| 5738 | typedef internal::Internals I; |
| 5739 | *value_ = *I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 5740 | } |
| 5741 | |
| 5742 | template<typename T> |
| 5743 | void ReturnValue<T>::SetNull(Isolate* isolate) { |
| 5744 | typedef internal::Internals I; |
| 5745 | *value_ = *I::GetRoot(isolate, I::kNullValueRootIndex); |
| 5746 | } |
| 5747 | |
| 5748 | template<typename T> |
| 5749 | void ReturnValue<T>::SetUndefined(Isolate* isolate) { |
| 5750 | typedef internal::Internals I; |
| 5751 | *value_ = *I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 5752 | } |
| 5753 | |
| 5754 | |
| 5755 | template<typename T> |
| 5756 | FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, |
| 5757 | internal::Object** values, |
| 5758 | int length, |
| 5759 | bool is_construct_call) |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5760 | : implicit_args_(implicit_args), |
| 5761 | values_(values), |
| 5762 | length_(length), |
| 5763 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5764 | |
| 5765 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5766 | Arguments::Arguments(internal::Object** args, |
| 5767 | internal::Object** values, |
| 5768 | int length, |
| 5769 | bool is_construct_call) |
| 5770 | : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { } |
| 5771 | |
| 5772 | |
| 5773 | template<typename T> |
| 5774 | Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5775 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5776 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5777 | } |
| 5778 | |
| 5779 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5780 | template<typename T> |
| 5781 | Local<Function> FunctionCallbackInfo<T>::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5782 | return Local<Function>(reinterpret_cast<Function*>( |
| 5783 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5787 | template<typename T> |
| 5788 | Local<Object> FunctionCallbackInfo<T>::This() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5789 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5790 | } |
| 5791 | |
| 5792 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5793 | template<typename T> |
| 5794 | Local<Object> FunctionCallbackInfo<T>::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5795 | return Local<Object>(reinterpret_cast<Object*>( |
| 5796 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5800 | template<typename T> |
| 5801 | Local<Value> FunctionCallbackInfo<T>::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5802 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5806 | template<typename T> |
| 5807 | Isolate* FunctionCallbackInfo<T>::GetIsolate() const { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5808 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5809 | } |
| 5810 | |
| 5811 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5812 | template<typename T> |
| 5813 | ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const { |
| 5814 | return ReturnValue<T>(&implicit_args_[kReturnValueIndex]); |
| 5815 | } |
| 5816 | |
| 5817 | |
| 5818 | template<typename T> |
| 5819 | bool FunctionCallbackInfo<T>::IsConstructCall() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5820 | return is_construct_call_; |
| 5821 | } |
| 5822 | |
| 5823 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5824 | template<typename T> |
| 5825 | int FunctionCallbackInfo<T>::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5826 | return length_; |
| 5827 | } |
| 5828 | |
| 5829 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5830 | template <class T> |
| 5831 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5832 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5833 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5834 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5835 | } |
| 5836 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5837 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5838 | return resource_name_; |
| 5839 | } |
| 5840 | |
| 5841 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5842 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5843 | return resource_line_offset_; |
| 5844 | } |
| 5845 | |
| 5846 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5847 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5848 | return resource_column_offset_; |
| 5849 | } |
| 5850 | |
| 5851 | |
| 5852 | Handle<Boolean> Boolean::New(bool value) { |
| 5853 | return value ? True() : False(); |
| 5854 | } |
| 5855 | |
| 5856 | |
| 5857 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5858 | Set(v8::String::New(name), value); |
| 5859 | } |
| 5860 | |
| 5861 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5862 | Local<Value> Object::GetInternalField(int index) { |
| 5863 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5864 | typedef internal::Object O; |
| 5865 | typedef internal::Internals I; |
| 5866 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5867 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5868 | // 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] | 5869 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5870 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5871 | O* value = I::ReadField<O*>(obj, offset); |
| 5872 | O** result = HandleScope::CreateHandle(value); |
| 5873 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5874 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5875 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5876 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5880 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5881 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5882 | typedef internal::Object O; |
| 5883 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5884 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5885 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5886 | // 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] | 5887 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5888 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5889 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5890 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5891 | #endif |
| 5892 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | |
| 5896 | String* String::Cast(v8::Value* value) { |
| 5897 | #ifdef V8_ENABLE_CHECKS |
| 5898 | CheckCast(value); |
| 5899 | #endif |
| 5900 | return static_cast<String*>(value); |
| 5901 | } |
| 5902 | |
| 5903 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5904 | Local<String> String::Empty(Isolate* isolate) { |
| 5905 | typedef internal::Object* S; |
| 5906 | typedef internal::Internals I; |
| 5907 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5908 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5909 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5910 | } |
| 5911 | |
| 5912 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5913 | Local<String> String::New(const char* data, int length) { |
| 5914 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5915 | } |
| 5916 | |
| 5917 | |
| 5918 | Local<String> String::New(const uint16_t* data, int length) { |
| 5919 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5920 | } |
| 5921 | |
| 5922 | |
| 5923 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5924 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5925 | } |
| 5926 | |
| 5927 | |
| 5928 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5929 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5930 | } |
| 5931 | |
| 5932 | |
| 5933 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5934 | return NewFromTwoByte( |
| 5935 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5936 | } |
| 5937 | |
| 5938 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5939 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5940 | typedef internal::Object O; |
| 5941 | typedef internal::Internals I; |
| 5942 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5943 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5944 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5945 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5946 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5947 | } else { |
| 5948 | result = NULL; |
| 5949 | } |
| 5950 | #ifdef V8_ENABLE_CHECKS |
| 5951 | VerifyExternalStringResource(result); |
| 5952 | #endif |
| 5953 | return result; |
| 5954 | } |
| 5955 | |
| 5956 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5957 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5958 | String::Encoding* encoding_out) const { |
| 5959 | typedef internal::Object O; |
| 5960 | typedef internal::Internals I; |
| 5961 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5962 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5963 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5964 | ExternalStringResourceBase* resource = NULL; |
| 5965 | if (type == I::kExternalAsciiRepresentationTag || |
| 5966 | type == I::kExternalTwoByteRepresentationTag) { |
| 5967 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5968 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5969 | } |
| 5970 | #ifdef V8_ENABLE_CHECKS |
| 5971 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5972 | #endif |
| 5973 | return resource; |
| 5974 | } |
| 5975 | |
| 5976 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5977 | bool Value::IsUndefined() const { |
| 5978 | #ifdef V8_ENABLE_CHECKS |
| 5979 | return FullIsUndefined(); |
| 5980 | #else |
| 5981 | return QuickIsUndefined(); |
| 5982 | #endif |
| 5983 | } |
| 5984 | |
| 5985 | bool Value::QuickIsUndefined() const { |
| 5986 | typedef internal::Object O; |
| 5987 | typedef internal::Internals I; |
| 5988 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5989 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5990 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5991 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 5992 | } |
| 5993 | |
| 5994 | |
| 5995 | bool Value::IsNull() const { |
| 5996 | #ifdef V8_ENABLE_CHECKS |
| 5997 | return FullIsNull(); |
| 5998 | #else |
| 5999 | return QuickIsNull(); |
| 6000 | #endif |
| 6001 | } |
| 6002 | |
| 6003 | bool Value::QuickIsNull() const { |
| 6004 | typedef internal::Object O; |
| 6005 | typedef internal::Internals I; |
| 6006 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6007 | if (!I::HasHeapObjectTag(obj)) return false; |
| 6008 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 6009 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 6010 | } |
| 6011 | |
| 6012 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6013 | bool Value::IsString() const { |
| 6014 | #ifdef V8_ENABLE_CHECKS |
| 6015 | return FullIsString(); |
| 6016 | #else |
| 6017 | return QuickIsString(); |
| 6018 | #endif |
| 6019 | } |
| 6020 | |
| 6021 | bool Value::QuickIsString() const { |
| 6022 | typedef internal::Object O; |
| 6023 | typedef internal::Internals I; |
| 6024 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 6025 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6026 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6030 | Symbol* Symbol::Cast(v8::Value* value) { |
| 6031 | #ifdef V8_ENABLE_CHECKS |
| 6032 | CheckCast(value); |
| 6033 | #endif |
| 6034 | return static_cast<Symbol*>(value); |
| 6035 | } |
| 6036 | |
| 6037 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6038 | Number* Number::Cast(v8::Value* value) { |
| 6039 | #ifdef V8_ENABLE_CHECKS |
| 6040 | CheckCast(value); |
| 6041 | #endif |
| 6042 | return static_cast<Number*>(value); |
| 6043 | } |
| 6044 | |
| 6045 | |
| 6046 | Integer* Integer::Cast(v8::Value* value) { |
| 6047 | #ifdef V8_ENABLE_CHECKS |
| 6048 | CheckCast(value); |
| 6049 | #endif |
| 6050 | return static_cast<Integer*>(value); |
| 6051 | } |
| 6052 | |
| 6053 | |
| 6054 | Date* Date::Cast(v8::Value* value) { |
| 6055 | #ifdef V8_ENABLE_CHECKS |
| 6056 | CheckCast(value); |
| 6057 | #endif |
| 6058 | return static_cast<Date*>(value); |
| 6059 | } |
| 6060 | |
| 6061 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6062 | StringObject* StringObject::Cast(v8::Value* value) { |
| 6063 | #ifdef V8_ENABLE_CHECKS |
| 6064 | CheckCast(value); |
| 6065 | #endif |
| 6066 | return static_cast<StringObject*>(value); |
| 6067 | } |
| 6068 | |
| 6069 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6070 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 6071 | #ifdef V8_ENABLE_CHECKS |
| 6072 | CheckCast(value); |
| 6073 | #endif |
| 6074 | return static_cast<SymbolObject*>(value); |
| 6075 | } |
| 6076 | |
| 6077 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6078 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 6079 | #ifdef V8_ENABLE_CHECKS |
| 6080 | CheckCast(value); |
| 6081 | #endif |
| 6082 | return static_cast<NumberObject*>(value); |
| 6083 | } |
| 6084 | |
| 6085 | |
| 6086 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 6087 | #ifdef V8_ENABLE_CHECKS |
| 6088 | CheckCast(value); |
| 6089 | #endif |
| 6090 | return static_cast<BooleanObject*>(value); |
| 6091 | } |
| 6092 | |
| 6093 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 6094 | RegExp* RegExp::Cast(v8::Value* value) { |
| 6095 | #ifdef V8_ENABLE_CHECKS |
| 6096 | CheckCast(value); |
| 6097 | #endif |
| 6098 | return static_cast<RegExp*>(value); |
| 6099 | } |
| 6100 | |
| 6101 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6102 | Object* Object::Cast(v8::Value* value) { |
| 6103 | #ifdef V8_ENABLE_CHECKS |
| 6104 | CheckCast(value); |
| 6105 | #endif |
| 6106 | return static_cast<Object*>(value); |
| 6107 | } |
| 6108 | |
| 6109 | |
| 6110 | Array* Array::Cast(v8::Value* value) { |
| 6111 | #ifdef V8_ENABLE_CHECKS |
| 6112 | CheckCast(value); |
| 6113 | #endif |
| 6114 | return static_cast<Array*>(value); |
| 6115 | } |
| 6116 | |
| 6117 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6118 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 6119 | #ifdef V8_ENABLE_CHECKS |
| 6120 | CheckCast(value); |
| 6121 | #endif |
| 6122 | return static_cast<ArrayBuffer*>(value); |
| 6123 | } |
| 6124 | |
| 6125 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6126 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 6127 | #ifdef V8_ENABLE_CHECKS |
| 6128 | CheckCast(value); |
| 6129 | #endif |
| 6130 | return static_cast<TypedArray*>(value); |
| 6131 | } |
| 6132 | |
| 6133 | |
| 6134 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 6135 | #ifdef V8_ENABLE_CHECKS |
| 6136 | CheckCast(value); |
| 6137 | #endif |
| 6138 | return static_cast<Uint8Array*>(value); |
| 6139 | } |
| 6140 | |
| 6141 | |
| 6142 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 6143 | #ifdef V8_ENABLE_CHECKS |
| 6144 | CheckCast(value); |
| 6145 | #endif |
| 6146 | return static_cast<Int8Array*>(value); |
| 6147 | } |
| 6148 | |
| 6149 | |
| 6150 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 6151 | #ifdef V8_ENABLE_CHECKS |
| 6152 | CheckCast(value); |
| 6153 | #endif |
| 6154 | return static_cast<Uint16Array*>(value); |
| 6155 | } |
| 6156 | |
| 6157 | |
| 6158 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 6159 | #ifdef V8_ENABLE_CHECKS |
| 6160 | CheckCast(value); |
| 6161 | #endif |
| 6162 | return static_cast<Int16Array*>(value); |
| 6163 | } |
| 6164 | |
| 6165 | |
| 6166 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 6167 | #ifdef V8_ENABLE_CHECKS |
| 6168 | CheckCast(value); |
| 6169 | #endif |
| 6170 | return static_cast<Uint32Array*>(value); |
| 6171 | } |
| 6172 | |
| 6173 | |
| 6174 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 6175 | #ifdef V8_ENABLE_CHECKS |
| 6176 | CheckCast(value); |
| 6177 | #endif |
| 6178 | return static_cast<Int32Array*>(value); |
| 6179 | } |
| 6180 | |
| 6181 | |
| 6182 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 6183 | #ifdef V8_ENABLE_CHECKS |
| 6184 | CheckCast(value); |
| 6185 | #endif |
| 6186 | return static_cast<Float32Array*>(value); |
| 6187 | } |
| 6188 | |
| 6189 | |
| 6190 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 6191 | #ifdef V8_ENABLE_CHECKS |
| 6192 | CheckCast(value); |
| 6193 | #endif |
| 6194 | return static_cast<Float64Array*>(value); |
| 6195 | } |
| 6196 | |
| 6197 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6198 | Function* Function::Cast(v8::Value* value) { |
| 6199 | #ifdef V8_ENABLE_CHECKS |
| 6200 | CheckCast(value); |
| 6201 | #endif |
| 6202 | return static_cast<Function*>(value); |
| 6203 | } |
| 6204 | |
| 6205 | |
| 6206 | External* External::Cast(v8::Value* value) { |
| 6207 | #ifdef V8_ENABLE_CHECKS |
| 6208 | CheckCast(value); |
| 6209 | #endif |
| 6210 | return static_cast<External*>(value); |
| 6211 | } |
| 6212 | |
| 6213 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6214 | template<typename T> |
| 6215 | Isolate* PropertyCallbackInfo<T>::GetIsolate() const { |
| 6216 | return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6220 | template<typename T> |
| 6221 | Local<Value> PropertyCallbackInfo<T>::Data() const { |
| 6222 | return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6226 | template<typename T> |
| 6227 | Local<Object> PropertyCallbackInfo<T>::This() const { |
| 6228 | return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6232 | template<typename T> |
| 6233 | Local<Object> PropertyCallbackInfo<T>::Holder() const { |
| 6234 | return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex])); |
| 6235 | } |
| 6236 | |
| 6237 | |
| 6238 | template<typename T> |
| 6239 | ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { |
| 6240 | return ReturnValue<T>(&args_[kReturnValueIndex]); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 6244 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 6245 | typedef internal::Object* S; |
| 6246 | typedef internal::Internals I; |
| 6247 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 6248 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 6249 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6250 | } |
| 6251 | |
| 6252 | |
| 6253 | Handle<Primitive> Null(Isolate* isolate) { |
| 6254 | typedef internal::Object* S; |
| 6255 | typedef internal::Internals I; |
| 6256 | if (!I::IsInitialized(isolate)) return Null(); |
| 6257 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 6258 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 6259 | } |
| 6260 | |
| 6261 | |
| 6262 | Handle<Boolean> True(Isolate* isolate) { |
| 6263 | typedef internal::Object* S; |
| 6264 | typedef internal::Internals I; |
| 6265 | if (!I::IsInitialized(isolate)) return True(); |
| 6266 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 6267 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6268 | } |
| 6269 | |
| 6270 | |
| 6271 | Handle<Boolean> False(Isolate* isolate) { |
| 6272 | typedef internal::Object* S; |
| 6273 | typedef internal::Internals I; |
| 6274 | if (!I::IsInitialized(isolate)) return False(); |
| 6275 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 6276 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 6277 | } |
| 6278 | |
| 6279 | |
| 6280 | void Isolate::SetData(void* data) { |
| 6281 | typedef internal::Internals I; |
| 6282 | I::SetEmbedderData(this, data); |
| 6283 | } |
| 6284 | |
| 6285 | |
| 6286 | void* Isolate::GetData() { |
| 6287 | typedef internal::Internals I; |
| 6288 | return I::GetEmbedderData(this); |
| 6289 | } |
| 6290 | |
| 6291 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 6292 | Local<Value> Context::GetEmbedderData(int index) { |
| 6293 | #ifndef V8_ENABLE_CHECKS |
| 6294 | typedef internal::Object O; |
| 6295 | typedef internal::Internals I; |
| 6296 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 6297 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 6298 | #else |
| 6299 | return SlowGetEmbedderData(index); |
| 6300 | #endif |
| 6301 | } |
| 6302 | |
| 6303 | |
| 6304 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 6305 | #ifndef V8_ENABLE_CHECKS |
| 6306 | typedef internal::Internals I; |
| 6307 | return I::ReadEmbedderData<void*>(this, index); |
| 6308 | #else |
| 6309 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 6310 | #endif |
| 6311 | } |
| 6312 | |
| 6313 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6314 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 6315 | * \example shell.cc |
| 6316 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6317 | * command-line and executes them. |
| 6318 | */ |
| 6319 | |
| 6320 | |
| 6321 | /** |
| 6322 | * \example process.cc |
| 6323 | */ |
| 6324 | |
| 6325 | |
| 6326 | } // namespace v8 |
| 6327 | |
| 6328 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6329 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6330 | #undef TYPE_CHECK |
| 6331 | |
| 6332 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6333 | #endif // V8_H_ |