jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 28 | /** \mainpage V8 API Reference Guide |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 29 | * |
| 30 | * V8 is Google's open source JavaScript engine. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | * |
| 32 | * This set of documents provides reference material generated from the |
| 33 | * V8 header file, include/v8.h. |
| 34 | * |
| 35 | * For other documentation see http://code.google.com/apis/v8/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | */ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 37 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 38 | #ifndef V8_H_ |
| 39 | #define V8_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 41 | #include "v8stdint.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef _WIN32 |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 44 | |
| 45 | // Setup for Windows DLL export/import. When building the V8 DLL the |
| 46 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
| 47 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
| 48 | // static library or building a program which uses the V8 static library neither |
| 49 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 50 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
| 51 | #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ |
| 52 | build configuration to ensure that at most one of these is set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 56 | #define V8EXPORT __declspec(dllexport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | #elif USING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 58 | #define V8EXPORT __declspec(dllimport) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 59 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 60 | #define V8EXPORT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | #endif // BUILDING_V8_SHARED |
| 62 | |
| 63 | #else // _WIN32 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 64 | |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 65 | // Setup for Linux shared library export. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 66 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 67 | (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 68 | #ifdef BUILDING_V8_SHARED |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 69 | #define V8EXPORT __attribute__ ((visibility("default"))) |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 70 | #else |
| 71 | #define V8EXPORT |
| 72 | #endif |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 73 | #else |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 74 | #define V8EXPORT |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 75 | #endif |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // _WIN32 |
| 78 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 79 | #if defined(__GNUC__) && !defined(DEBUG) |
| 80 | #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator |
| 81 | #elif defined(_MSC_VER) && !defined(DEBUG) |
| 82 | #define V8_INLINE(declarator) __forceinline declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 83 | #else |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 84 | #define V8_INLINE(declarator) inline declarator |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS |
| 88 | #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated)) |
| 89 | #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS |
| 90 | #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator |
| 91 | #else |
| 92 | #define V8_DEPRECATED(declarator) declarator |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 95 | #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) |
| 96 | #define V8_UNLIKELY(condition) __builtin_expect((condition), 0) |
| 97 | #define V8_LIKELY(condition) __builtin_expect((condition), 1) |
| 98 | #else |
| 99 | #define V8_UNLIKELY(condition) (condition) |
| 100 | #define V8_LIKELY(condition) (condition) |
| 101 | #endif |
| 102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 104 | * The v8 JavaScript engine. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | */ |
| 106 | namespace v8 { |
| 107 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 108 | class AccessorInfo; |
| 109 | class AccessorSignature; |
| 110 | class Array; |
| 111 | class Boolean; |
| 112 | class BooleanObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | class Context; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 114 | class CpuProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 115 | class Data; |
| 116 | class Date; |
| 117 | class DeclaredAccessorDescriptor; |
| 118 | class External; |
| 119 | class Function; |
| 120 | class FunctionTemplate; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 121 | class HeapProfiler; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 122 | class ImplementationUtilities; |
| 123 | class Int32; |
| 124 | class Integer; |
| 125 | class Isolate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | class LocalContext; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | class Number; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 128 | class NumberObject; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | class Object; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 130 | class ObjectOperationDescriptor; |
| 131 | class ObjectTemplate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | class Primitive; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 133 | class RawOperationDescriptor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | class Signature; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 135 | class StackFrame; |
| 136 | class StackTrace; |
| 137 | class String; |
| 138 | class StringObject; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 139 | class Symbol; |
| 140 | class SymbolObject; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 141 | class Uint32; |
| 142 | class Utils; |
| 143 | class Value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | template <class T> class Handle; |
| 145 | template <class T> class Local; |
| 146 | template <class T> class Persistent; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 148 | namespace internal { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 149 | class Arguments; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 150 | class Heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | class HeapObject; |
| 152 | class Isolate; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 153 | class Object; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 154 | } |
| 155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 157 | /** |
| 158 | * General purpose unique identifier. |
| 159 | */ |
| 160 | class UniqueId { |
| 161 | public: |
| 162 | explicit UniqueId(intptr_t data) |
| 163 | : data_(data) {} |
| 164 | |
| 165 | bool operator==(const UniqueId& other) const { |
| 166 | return data_ == other.data_; |
| 167 | } |
| 168 | |
| 169 | bool operator!=(const UniqueId& other) const { |
| 170 | return data_ != other.data_; |
| 171 | } |
| 172 | |
| 173 | bool operator<(const UniqueId& other) const { |
| 174 | return data_ < other.data_; |
| 175 | } |
| 176 | |
| 177 | private: |
| 178 | intptr_t data_; |
| 179 | }; |
| 180 | |
| 181 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 182 | // --- Weak Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | |
| 184 | |
| 185 | /** |
| 186 | * A weak reference callback function. |
| 187 | * |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 188 | * This callback should either explicitly invoke Dispose on |object| if |
| 189 | * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| 190 | * |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | * \param object the weak global object to be reclaimed by the garbage collector |
| 192 | * \param parameter the value passed in when making the weak global object |
| 193 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 194 | template<typename T, typename P> |
| 195 | class WeakReferenceCallbacks { |
| 196 | public: |
| 197 | typedef void (*Revivable)(Isolate* isolate, |
| 198 | Persistent<T>* object, |
| 199 | P* parameter); |
| 200 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 202 | // TODO(svenpanne) Temporary definition until Chrome is in sync. |
| 203 | typedef void (*NearDeathCallback)(Isolate* isolate, |
| 204 | Persistent<Value> object, |
| 205 | void* parameter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 207 | // --- Handles --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 209 | #define TYPE_CHECK(T, S) \ |
| 210 | while (false) { \ |
| 211 | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | } |
| 213 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 214 | |
| 215 | #define V8_USE_UNSAFE_HANDLES |
| 216 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | /** |
| 218 | * An object reference managed by the v8 garbage collector. |
| 219 | * |
| 220 | * All objects returned from v8 have to be tracked by the garbage |
| 221 | * collector so that it knows that the objects are still alive. Also, |
| 222 | * because the garbage collector may move objects, it is unsafe to |
| 223 | * point directly to an object. Instead, all objects are stored in |
| 224 | * handles which are known by the garbage collector and updated |
| 225 | * whenever an object moves. Handles should always be passed by value |
| 226 | * (except in cases like out-parameters) and they should never be |
| 227 | * allocated on the heap. |
| 228 | * |
| 229 | * There are two types of handles: local and persistent handles. |
| 230 | * Local handles are light-weight and transient and typically used in |
| 231 | * local operations. They are managed by HandleScopes. Persistent |
| 232 | * handles can be used when storing objects across several independent |
| 233 | * operations and have to be explicitly deallocated when they're no |
| 234 | * longer used. |
| 235 | * |
| 236 | * It is safe to extract the object stored in the handle by |
| 237 | * dereferencing the handle (for instance, to extract the Object* from |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 238 | * a Handle<Object>); the value will still be governed by a handle |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | * behind the scenes and the same rules apply to these values as to |
| 240 | * their handles. |
| 241 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 242 | template <class T> class Handle { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | /** |
| 245 | * Creates an empty handle. |
| 246 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 247 | V8_INLINE(Handle()) : val_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 249 | #ifdef V8_USE_UNSAFE_HANDLES |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | /** |
| 251 | * Creates a new handle for the specified value. |
| 252 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 253 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 254 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Creates a handle for the contents of the specified handle. This |
| 258 | * constructor allows you to pass handles as arguments by value and |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 259 | * to assign between handles. However, if you try to assign between |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | * incompatible handles, for instance from a Handle<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 261 | * Handle<Number> it will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | * between compatible handles, for instance assigning a |
| 263 | * Handle<String> to a variable declared as Handle<Value>, is legal |
| 264 | * because String is a subclass of Value. |
| 265 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 266 | template <class S> V8_INLINE(Handle(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | : val_(reinterpret_cast<T*>(*that)) { |
| 268 | /** |
| 269 | * This check fails when trying to convert between incompatible |
| 270 | * handles. For example, converting from a Handle<String> to a |
| 271 | * Handle<Number>. |
| 272 | */ |
| 273 | TYPE_CHECK(T, S); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Returns true if the handle is empty. |
| 278 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 279 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | /** |
| 282 | * Sets the handle to be empty. IsEmpty() will then return true. |
| 283 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 284 | V8_INLINE(void Clear()) { val_ = 0; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 285 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 286 | V8_INLINE(T* operator->() const) { return val_; } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 287 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 288 | V8_INLINE(T* operator*() const) { return val_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * Checks whether two handles are the same. |
| 292 | * Returns true if both are empty, or if the objects |
| 293 | * to which they refer are identical. |
| 294 | * The handles' references are not checked. |
| 295 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 296 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 297 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 298 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | if (a == 0) return b == 0; |
| 300 | if (b == 0) return false; |
| 301 | return *a == *b; |
| 302 | } |
| 303 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 304 | #ifndef V8_USE_UNSAFE_HANDLES |
| 305 | template <class S> V8_INLINE( |
| 306 | bool operator==(const Persistent<S>& that) const) { |
| 307 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 308 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 309 | if (a == 0) return b == 0; |
| 310 | if (b == 0) return false; |
| 311 | return *a == *b; |
| 312 | } |
| 313 | #endif |
| 314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | /** |
| 316 | * Checks whether two handles are different. |
| 317 | * Returns true if only one of the handles is empty, or if |
| 318 | * the objects to which they refer are different. |
| 319 | * The handles' references are not checked. |
| 320 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 321 | template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | return !operator==(that); |
| 323 | } |
| 324 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 325 | template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 326 | #ifdef V8_ENABLE_CHECKS |
| 327 | // If we're going to perform the type check then we have to check |
| 328 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 329 | if (that.IsEmpty()) return Handle<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 330 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | return Handle<T>(T::Cast(*that)); |
| 332 | } |
| 333 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 334 | template <class S> V8_INLINE(Handle<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 335 | return Handle<S>::Cast(*this); |
| 336 | } |
| 337 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 338 | #ifndef V8_USE_UNSAFE_HANDLES |
| 339 | V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| 340 | return New(isolate, that.val_); |
| 341 | } |
| 342 | // TODO(dcarney): remove before cutover |
| 343 | V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| 344 | return New(isolate, that.val_); |
| 345 | } |
| 346 | |
| 347 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 350 | #endif |
| 351 | /** |
| 352 | * Creates a new handle for the specified value. |
| 353 | */ |
| 354 | V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| 355 | #endif |
| 356 | |
| 357 | private: |
| 358 | template<class F> |
| 359 | friend class Persistent; |
| 360 | template<class F> |
| 361 | friend class Local; |
| 362 | friend class Arguments; |
| 363 | friend class String; |
| 364 | friend class Object; |
| 365 | friend class AccessorInfo; |
| 366 | friend Handle<Primitive> Undefined(Isolate* isolate); |
| 367 | friend Handle<Primitive> Null(Isolate* isolate); |
| 368 | friend Handle<Boolean> True(Isolate* isolate); |
| 369 | friend Handle<Boolean> False(Isolate* isolate); |
| 370 | friend class Context; |
| 371 | friend class InternalHandleHelper; |
| 372 | friend class LocalContext; |
| 373 | |
| 374 | #ifndef V8_USE_UNSAFE_HANDLES |
| 375 | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| 376 | #endif |
| 377 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | T* val_; |
| 379 | }; |
| 380 | |
| 381 | |
| 382 | /** |
| 383 | * A light-weight stack-allocated object handle. All operations |
| 384 | * that return objects from within v8 return them in local handles. They |
| 385 | * are created within HandleScopes, and all local handles allocated within a |
| 386 | * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 387 | * is not necessary to explicitly deallocate local handles. |
| 388 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 389 | // TODO(dcarney): deprecate entire class |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 390 | template <class T> class Local : public Handle<T> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 392 | V8_INLINE(Local()); |
| 393 | template <class S> V8_INLINE(Local(Local<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 395 | /** |
| 396 | * This check fails when trying to convert between incompatible |
| 397 | * handles. For example, converting from a Handle<String> to a |
| 398 | * Handle<Number>. |
| 399 | */ |
| 400 | TYPE_CHECK(T, S); |
| 401 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 402 | |
| 403 | |
| 404 | #ifdef V8_USE_UNSAFE_HANDLES |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 405 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 406 | #endif |
| 407 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 408 | template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 409 | #ifdef V8_ENABLE_CHECKS |
| 410 | // If we're going to perform the type check then we have to check |
| 411 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | if (that.IsEmpty()) return Local<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 413 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | return Local<T>(T::Cast(*that)); |
| 415 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 416 | #ifndef V8_USE_UNSAFE_HANDLES |
| 417 | template <class S> V8_INLINE(Local(Handle<S> that)) |
| 418 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 419 | TYPE_CHECK(T, S); |
| 420 | } |
| 421 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 422 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 423 | template <class S> V8_INLINE(Local<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 424 | return Local<S>::Cast(*this); |
| 425 | } |
| 426 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 427 | /** |
| 428 | * Create a local handle for the content of another handle. |
| 429 | * The referee is kept alive by the local handle even when |
| 430 | * the original handle is destroyed/disposed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 432 | V8_INLINE(static Local<T> New(Handle<T> that)); |
| 433 | V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 434 | #ifndef V8_USE_UNSAFE_HANDLES |
| 435 | // TODO(dcarney): remove before cutover |
| 436 | V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 438 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 439 | |
| 440 | private: |
| 441 | #endif |
| 442 | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| 443 | #endif |
| 444 | |
| 445 | private: |
| 446 | template<class F> |
| 447 | friend class Persistent; |
| 448 | template<class F> |
| 449 | friend class Handle; |
| 450 | friend class Arguments; |
| 451 | friend class String; |
| 452 | friend class Object; |
| 453 | friend class AccessorInfo; |
| 454 | friend class Context; |
| 455 | friend class InternalHandleHelper; |
| 456 | friend class LocalContext; |
| 457 | |
| 458 | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| 459 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * An object reference that is independent of any handle scope. Where |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 463 | * a Local handle only lives as long as the HandleScope in which it was |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | * allocated, a Persistent handle remains valid until it is explicitly |
| 465 | * disposed. |
| 466 | * |
| 467 | * A persistent handle contains a reference to a storage cell within |
| 468 | * the v8 engine which holds an object value and which is updated by |
| 469 | * the garbage collector whenever the object is moved. A new storage |
| 470 | * cell can be created using Persistent::New and existing handles can |
| 471 | * be disposed using Persistent::Dispose. Since persistent handles |
| 472 | * are passed by value you may have many persistent handle objects |
| 473 | * that point to the same storage cell. For instance, if you pass a |
| 474 | * persistent handle as an argument to a function you will not get two |
| 475 | * different storage cells but rather two references to the same |
| 476 | * storage cell. |
| 477 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 478 | template <class T> class Persistent // NOLINT |
| 479 | #ifdef V8_USE_UNSAFE_HANDLES |
| 480 | : public Handle<T> { |
| 481 | #else |
| 482 | { // NOLINT |
| 483 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 485 | #ifndef V8_USE_UNSAFE_HANDLES |
| 486 | V8_INLINE(Persistent()) : val_(0) { } |
| 487 | V8_INLINE(~Persistent()) { |
| 488 | // TODO(dcarney): add this back before cutover. |
| 489 | // Dispose(); |
| 490 | } |
| 491 | V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| 492 | // TODO(dcarney): remove somehow before cutover |
| 493 | // The handle should either be 0, or a pointer to a live cell. |
| 494 | V8_INLINE(void Clear()) { val_ = 0; } |
| 495 | |
| 496 | /** |
| 497 | * A constructor that creates a new global cell pointing to that. In contrast |
| 498 | * to the copy constructor, this creates a new persistent handle which needs |
| 499 | * to be separately disposed. |
| 500 | */ |
| 501 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 502 | : val_(*New(isolate, that)) { } |
| 503 | |
| 504 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 505 | /** |
| 506 | * Creates an empty persistent handle that doesn't point to any |
| 507 | * storage cell. |
| 508 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 509 | V8_INLINE(Persistent()) : Handle<T>() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | |
| 511 | /** |
| 512 | * Creates a persistent handle for the same storage cell as the |
| 513 | * specified handle. This constructor allows you to pass persistent |
| 514 | * handles as arguments by value and to assign between persistent |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 515 | * handles. However, attempting to assign between incompatible |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 516 | * persistent handles, for instance from a Persistent<String> to a |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 517 | * Persistent<Number> will cause a compile-time error. Assigning |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | * between compatible persistent handles, for instance assigning a |
| 519 | * Persistent<String> to a variable declared as Persistent<Value>, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 520 | * is allowed as String is a subclass of Value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 522 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 524 | /** |
| 525 | * This check fails when trying to convert between incompatible |
| 526 | * handles. For example, converting from a Handle<String> to a |
| 527 | * Handle<Number>. |
| 528 | */ |
| 529 | TYPE_CHECK(T, S); |
| 530 | } |
| 531 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 532 | template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 534 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 535 | * A constructor that creates a new global cell pointing to that. In contrast |
| 536 | * to the copy constructor, this creates a new persistent handle which needs |
| 537 | * to be separately disposed. |
| 538 | */ |
| 539 | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| 540 | : Handle<T>(New(isolate, that)) { } |
| 541 | |
| 542 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 543 | * "Casts" a plain handle which is known to be a persistent handle |
| 544 | * to a persistent handle. |
| 545 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 546 | template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | : Handle<T>(*that) { } |
| 548 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 549 | #endif |
| 550 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 551 | template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 552 | #ifdef V8_ENABLE_CHECKS |
| 553 | // If we're going to perform the type check then we have to check |
| 554 | // that the handle isn't empty before doing the checked cast. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | if (that.IsEmpty()) return Persistent<T>(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 556 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | return Persistent<T>(T::Cast(*that)); |
| 558 | } |
| 559 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 560 | template <class S> V8_INLINE(Persistent<S> As()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 561 | return Persistent<S>::Cast(*this); |
| 562 | } |
| 563 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 564 | V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| 565 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 567 | * Creates a new persistent handle for an existing local or persistent handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 569 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 570 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 571 | #ifndef V8_USE_UNSAFE_HANDLES |
| 572 | // TODO(dcarney): remove before cutover |
| 573 | V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| 574 | #endif |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 575 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 576 | #ifndef V8_USE_UNSAFE_HANDLES |
| 577 | template <class S> V8_INLINE( |
| 578 | bool operator==(const Persistent<S>& that) const) { |
| 579 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 580 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 581 | if (a == 0) return b == 0; |
| 582 | if (b == 0) return false; |
| 583 | return *a == *b; |
| 584 | } |
| 585 | |
| 586 | template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { |
| 587 | internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 588 | internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 589 | if (a == 0) return b == 0; |
| 590 | if (b == 0) return false; |
| 591 | return *a == *b; |
| 592 | } |
| 593 | #endif |
| 594 | |
| 595 | V8_INLINE(void Dispose()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * Releases the storage cell referenced by this persistent handle. |
| 599 | * Does not remove the reference to the cell from any handles. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 600 | * This handle's reference, and any other references to the storage |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | * cell remain and IsEmpty will still return false. |
| 602 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 603 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 604 | V8_INLINE(void Dispose(Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 606 | template<typename S, typename P> |
| 607 | V8_INLINE(void MakeWeak( |
| 608 | Isolate* isolate, |
| 609 | P* parameters, |
| 610 | typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| 611 | |
| 612 | template<typename P> |
| 613 | V8_INLINE(void MakeWeak( |
| 614 | Isolate* isolate, |
| 615 | P* parameters, |
| 616 | typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 617 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | /** |
| 619 | * Make the reference to this object weak. When only weak handles |
| 620 | * refer to the object, the garbage collector will perform a |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 621 | * callback to the given V8::NearDeathCallback function, passing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | * it the object reference and the given parameters. |
| 623 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 624 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 625 | V8_INLINE(void MakeWeak(Isolate* isolate, |
| 626 | void* parameters, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 627 | NearDeathCallback callback)); |
| 628 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 629 | V8_INLINE(void ClearWeak()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 631 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 632 | V8_INLINE(void ClearWeak(Isolate* isolate)); |
| 633 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 634 | V8_INLINE(void MarkIndependent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | |
| 636 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 637 | * Marks the reference to this object independent. Garbage collector is free |
| 638 | * to ignore any object groups containing this object. Weak callback for an |
| 639 | * independent handle should not assume that it will be preceded by a global |
| 640 | * GC prologue callback or followed by a global GC epilogue callback. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 641 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 642 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 643 | V8_INLINE(void MarkIndependent(Isolate* isolate)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 644 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 645 | V8_INLINE(void MarkPartiallyDependent()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 646 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 647 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 648 | * Marks the reference to this object partially dependent. Partially dependent |
| 649 | * handles only depend on other partially dependent handles and these |
| 650 | * dependencies are provided through object groups. It provides a way to build |
| 651 | * smaller object groups for young objects that represent only a subset of all |
| 652 | * external dependencies. This mark is automatically cleared after each |
| 653 | * garbage collection. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 654 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 655 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 656 | V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 657 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 658 | V8_INLINE(bool IsIndependent() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 659 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 660 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 661 | V8_INLINE(bool IsIndependent(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 662 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 663 | V8_INLINE(bool IsNearDeath() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 664 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 665 | /** Checks if the handle holds the only reference to an object. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 666 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 667 | V8_INLINE(bool IsNearDeath(Isolate* isolate) const); |
| 668 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 669 | V8_INLINE(bool IsWeak() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 671 | /** Returns true if the handle's reference is weak. */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 672 | // TODO(dcarney): remove before cutover |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 673 | V8_INLINE(bool IsWeak(Isolate* isolate) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 675 | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 676 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 677 | /** |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 678 | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface |
| 679 | * description in v8-profiler.h for details. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 680 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 681 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 682 | V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); |
| 683 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 684 | V8_INLINE(uint16_t WrapperClassId() const); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 685 | |
| 686 | /** |
| 687 | * Returns the class ID previously assigned to this handle or 0 if no class ID |
| 688 | * was previously assigned. |
| 689 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 690 | // TODO(dcarney): remove before cutover |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 691 | V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 692 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 693 | /** |
| 694 | * Disposes the current contents of the handle and replaces it. |
| 695 | */ |
| 696 | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| 697 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 698 | /** |
| 699 | * Returns the underlying raw pointer and clears the handle. The caller is |
| 700 | * responsible of eventually destroying the underlying object (by creating a |
| 701 | * Persistent handle which points to it and Disposing it). In the future, |
| 702 | * destructing a Persistent will also Dispose it. With this function, the |
| 703 | * embedder can let the Persistent go out of scope without it getting |
| 704 | * disposed. |
| 705 | */ |
| 706 | V8_INLINE(T* ClearAndLeak()); |
| 707 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 708 | #ifndef V8_USE_UNSAFE_HANDLES |
| 709 | |
| 710 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 711 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 712 | private: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 713 | #endif |
| 714 | // TODO(dcarney): make unlinkable before cutover |
| 715 | V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| 716 | // TODO(dcarney): make unlinkable before cutover |
| 717 | V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| 718 | this->val_ = that.val_; |
| 719 | return *this; |
| 720 | } |
| 721 | |
| 722 | public: |
| 723 | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 724 | |
| 725 | private: |
| 726 | #endif |
| 727 | // TODO(dcarney): remove before cutover |
| 728 | template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| 729 | // TODO(dcarney): remove before cutover |
| 730 | template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| 731 | : val_(*that) { |
| 732 | TYPE_CHECK(T, S); |
| 733 | } |
| 734 | // TODO(dcarney): remove before cutover |
| 735 | V8_INLINE(T* operator*() const) { return val_; } |
| 736 | public: |
| 737 | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 738 | |
| 739 | private: |
| 740 | #endif |
| 741 | // TODO(dcarney): remove before cutover |
| 742 | V8_INLINE(T* operator->() const) { return val_; } |
| 743 | public: |
| 744 | #endif |
| 745 | |
| 746 | private: |
| 747 | template<class F> |
| 748 | friend class Handle; |
| 749 | template<class F> |
| 750 | friend class Local; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 751 | friend class ImplementationUtilities; |
| 752 | friend class ObjectTemplate; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 753 | friend class Context; |
| 754 | friend class InternalHandleHelper; |
| 755 | friend class LocalContext; |
| 756 | |
| 757 | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); |
| 758 | |
| 759 | #ifndef V8_USE_UNSAFE_HANDLES |
| 760 | T* val_; |
| 761 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 762 | }; |
| 763 | |
| 764 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 765 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | * A stack-allocated class that governs a number of local handles. |
| 767 | * After a handle scope has been created, all local handles will be |
| 768 | * allocated within that handle scope until either the handle scope is |
| 769 | * deleted or another handle scope is created. If there is already a |
| 770 | * 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] | 771 | * 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] | 772 | * new handles will again be allocated in the original handle scope. |
| 773 | * |
| 774 | * After the handle scope of a local handle has been deleted the |
| 775 | * garbage collector will no longer track the object stored in the |
| 776 | * handle and may deallocate it. The behavior of accessing a handle |
| 777 | * for which the handle scope has been deleted is undefined. |
| 778 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 779 | class V8EXPORT HandleScope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 781 | // TODO(svenpanne) Deprecate me when Chrome is fixed! |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 782 | HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 784 | HandleScope(Isolate* isolate); |
| 785 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 786 | ~HandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | |
| 788 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 789 | * Closes the handle scope and returns the value as a handle in the |
| 790 | * previous scope, which is the new current scope after the call. |
| 791 | */ |
| 792 | template <class T> Local<T> Close(Handle<T> value); |
| 793 | |
| 794 | /** |
| 795 | * Counts the number of allocated handles. |
| 796 | */ |
| 797 | static int NumberOfHandles(); |
| 798 | |
| 799 | /** |
| 800 | * Creates a new handle with the given value. |
| 801 | */ |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 802 | static internal::Object** CreateHandle(internal::Object* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 803 | static internal::Object** CreateHandle(internal::Isolate* isolate, |
| 804 | internal::Object* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 805 | // Faster version, uses HeapObject to obtain the current Isolate. |
| 806 | static internal::Object** CreateHandle(internal::HeapObject* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | |
| 808 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 809 | // Make it hard to create heap-allocated or illegal handle scopes by |
| 810 | // disallowing certain operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 811 | HandleScope(const HandleScope&); |
| 812 | void operator=(const HandleScope&); |
| 813 | void* operator new(size_t size); |
| 814 | void operator delete(void*, size_t); |
| 815 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 816 | // This Data class is accessible internally as HandleScopeData through a |
| 817 | // typedef in the ImplementationUtilities class. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 818 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 819 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 820 | internal::Object** next; |
| 821 | internal::Object** limit; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 822 | int level; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 823 | V8_INLINE(void Initialize()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 824 | next = limit = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 825 | level = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | } |
| 827 | }; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 828 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 829 | void Initialize(Isolate* isolate); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 830 | void Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 832 | internal::Isolate* isolate_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 833 | internal::Object** prev_next_; |
| 834 | internal::Object** prev_limit_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 836 | // Allow for the active closing of HandleScopes which allows to pass a handle |
| 837 | // from the HandleScope being closed to the next top most HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 838 | bool is_closed_; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 839 | internal::Object** RawClose(internal::Object** value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 840 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 841 | friend class ImplementationUtilities; |
| 842 | }; |
| 843 | |
| 844 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 845 | // --- Special objects --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | |
| 847 | |
| 848 | /** |
| 849 | * The superclass of values and API object templates. |
| 850 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 851 | class V8EXPORT Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | private: |
| 853 | Data(); |
| 854 | }; |
| 855 | |
| 856 | |
| 857 | /** |
| 858 | * Pre-compilation data that can be associated with a script. This |
| 859 | * data can be calculated for a script in advance of actually |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 860 | * compiling it, and can be stored between compilations. When script |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 861 | * data is given to the compile method compilation will be faster. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 862 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 863 | class V8EXPORT ScriptData { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | public: |
| 865 | virtual ~ScriptData() { } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 866 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 867 | /** |
| 868 | * Pre-compiles the specified script (context-independent). |
| 869 | * |
| 870 | * \param input Pointer to UTF-8 script source code. |
| 871 | * \param length Length of UTF-8 script source code. |
| 872 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | static ScriptData* PreCompile(const char* input, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 875 | /** |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 876 | * Pre-compiles the specified script (context-independent). |
| 877 | * |
| 878 | * NOTE: Pre-compilation using this method cannot happen on another thread |
| 879 | * without using Lockers. |
| 880 | * |
| 881 | * \param source Script source code. |
| 882 | */ |
| 883 | static ScriptData* PreCompile(Handle<String> source); |
| 884 | |
| 885 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 886 | * Load previous pre-compilation data. |
| 887 | * |
| 888 | * \param data Pointer to data returned by a call to Data() of a previous |
| 889 | * ScriptData. Ownership is not transferred. |
| 890 | * \param length Length of data. |
| 891 | */ |
| 892 | static ScriptData* New(const char* data, int length); |
| 893 | |
| 894 | /** |
| 895 | * Returns the length of Data(). |
| 896 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 897 | virtual int Length() = 0; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 898 | |
| 899 | /** |
| 900 | * Returns a serialized representation of this ScriptData that can later be |
| 901 | * passed to New(). NOTE: Serialized data is platform-dependent. |
| 902 | */ |
| 903 | virtual const char* Data() = 0; |
| 904 | |
| 905 | /** |
| 906 | * Returns true if the source code could not be parsed. |
| 907 | */ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 908 | virtual bool HasError() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 909 | }; |
| 910 | |
| 911 | |
| 912 | /** |
| 913 | * The origin, within a file, of a script. |
| 914 | */ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 915 | class ScriptOrigin { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 917 | V8_INLINE(ScriptOrigin( |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 918 | Handle<Value> resource_name, |
| 919 | Handle<Integer> resource_line_offset = Handle<Integer>(), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 920 | Handle<Integer> resource_column_offset = Handle<Integer>())) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | : resource_name_(resource_name), |
| 922 | resource_line_offset_(resource_line_offset), |
| 923 | resource_column_offset_(resource_column_offset) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 924 | V8_INLINE(Handle<Value> ResourceName() const); |
| 925 | V8_INLINE(Handle<Integer> ResourceLineOffset() const); |
| 926 | V8_INLINE(Handle<Integer> ResourceColumnOffset() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | private: |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 928 | Handle<Value> resource_name_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 929 | Handle<Integer> resource_line_offset_; |
| 930 | Handle<Integer> resource_column_offset_; |
| 931 | }; |
| 932 | |
| 933 | |
| 934 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 935 | * A compiled JavaScript script. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 937 | class V8EXPORT Script { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 938 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 939 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 940 | * Compiles the specified script (context-independent). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 941 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 942 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 943 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 944 | * when New() returns |
| 945 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 946 | * using pre_data speeds compilation if it's done multiple times. |
| 947 | * Owned by caller, no references are kept when New() returns. |
| 948 | * \param script_data Arbitrary data associated with script. Using |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 949 | * 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] | 950 | * available to compile event handlers. |
| 951 | * \return Compiled script object (context independent; when run it |
| 952 | * will use the currently entered context). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 953 | */ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 954 | static Local<Script> New(Handle<String> source, |
| 955 | ScriptOrigin* origin = NULL, |
| 956 | ScriptData* pre_data = NULL, |
| 957 | Handle<String> script_data = Handle<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 958 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 959 | /** |
| 960 | * Compiles the specified script using the specified file name |
| 961 | * object (typically a string) as the script's origin. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 962 | * |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 963 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 964 | * \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] | 965 | * as the script's origin. |
| 966 | * \return Compiled script object (context independent; when run it |
| 967 | * will use the currently entered context). |
| 968 | */ |
| 969 | static Local<Script> New(Handle<String> source, |
| 970 | Handle<Value> file_name); |
| 971 | |
| 972 | /** |
| 973 | * Compiles the specified script (bound to current context). |
| 974 | * |
| 975 | * \param source Script source code. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 976 | * \param origin Script origin, owned by caller, no references are kept |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 977 | * when Compile() returns |
| 978 | * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() |
| 979 | * using pre_data speeds compilation if it's done multiple times. |
| 980 | * Owned by caller, no references are kept when Compile() returns. |
| 981 | * \param script_data Arbitrary data associated with script. Using |
| 982 | * this has same effect as calling SetData(), but makes data available |
| 983 | * earlier (i.e. to compile event handlers). |
| 984 | * \return Compiled script object, bound to the context that was active |
| 985 | * when this function was called. When run it will always use this |
| 986 | * context. |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 987 | */ |
| 988 | static Local<Script> Compile(Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 989 | ScriptOrigin* origin = NULL, |
| 990 | ScriptData* pre_data = NULL, |
| 991 | Handle<String> script_data = Handle<String>()); |
| 992 | |
| 993 | /** |
| 994 | * Compiles the specified script using the specified file name |
| 995 | * object (typically a string) as the script's origin. |
| 996 | * |
| 997 | * \param source Script source code. |
| 998 | * \param file_name File name to use as script's origin |
| 999 | * \param script_data Arbitrary data associated with script. Using |
| 1000 | * this has same effect as calling SetData(), but makes data available |
| 1001 | * earlier (i.e. to compile event handlers). |
| 1002 | * \return Compiled script object, bound to the context that was active |
| 1003 | * when this function was called. When run it will always use this |
| 1004 | * context. |
| 1005 | */ |
| 1006 | static Local<Script> Compile(Handle<String> source, |
| 1007 | Handle<Value> file_name, |
| 1008 | Handle<String> script_data = Handle<String>()); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1009 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1010 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1011 | * Runs the script returning the resulting value. If the script is |
| 1012 | * context independent (created using ::New) it will be run in the |
| 1013 | * currently entered context. If it is context specific (created |
| 1014 | * using ::Compile) it will be run in the context in which it was |
| 1015 | * compiled. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1016 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1017 | Local<Value> Run(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1018 | |
| 1019 | /** |
| 1020 | * Returns the script id value. |
| 1021 | */ |
| 1022 | Local<Value> Id(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1023 | |
| 1024 | /** |
| 1025 | * Associate an additional data object with the script. This is mainly used |
| 1026 | * with the debugger as this data object is only available through the |
| 1027 | * debugger API. |
| 1028 | */ |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1029 | void SetData(Handle<String> data); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1030 | |
| 1031 | /** |
| 1032 | * Returns the name value of one Script. |
| 1033 | */ |
| 1034 | Handle<Value> GetScriptName(); |
| 1035 | |
| 1036 | /** |
| 1037 | * Returns zero based line number of the code_pos location in the script. |
| 1038 | * -1 will be returned if no information available. |
| 1039 | */ |
| 1040 | int GetLineNumber(int code_pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1041 | }; |
| 1042 | |
| 1043 | |
| 1044 | /** |
| 1045 | * An error message. |
| 1046 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1047 | class V8EXPORT Message { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1048 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1049 | Local<String> Get() const; |
| 1050 | Local<String> GetSourceLine() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1051 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1052 | /** |
| 1053 | * Returns the resource name for the script from where the function causing |
| 1054 | * the error originates. |
| 1055 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1056 | Handle<Value> GetScriptResourceName() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1058 | /** |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1059 | * Returns the resource data for the script from where the function causing |
| 1060 | * the error originates. |
| 1061 | */ |
| 1062 | Handle<Value> GetScriptData() const; |
| 1063 | |
| 1064 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1065 | * Exception stack trace. By default stack traces are not captured for |
| 1066 | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
| 1067 | * to change this option. |
| 1068 | */ |
| 1069 | Handle<StackTrace> GetStackTrace() const; |
| 1070 | |
| 1071 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1072 | * Returns the number, 1-based, of the line where the error occurred. |
| 1073 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1074 | int GetLineNumber() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1076 | /** |
| 1077 | * Returns the index within the script of the first character where |
| 1078 | * the error occurred. |
| 1079 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1080 | int GetStartPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1081 | |
| 1082 | /** |
| 1083 | * Returns the index within the script of the last character where |
| 1084 | * the error occurred. |
| 1085 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1086 | int GetEndPosition() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1087 | |
| 1088 | /** |
| 1089 | * Returns the index within the line of the first character where |
| 1090 | * the error occurred. |
| 1091 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1092 | int GetStartColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1093 | |
| 1094 | /** |
| 1095 | * Returns the index within the line of the last character where |
| 1096 | * the error occurred. |
| 1097 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1098 | int GetEndColumn() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1099 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1100 | // TODO(1245381): Print to a string instead of on a FILE. |
| 1101 | static void PrintCurrentStackTrace(FILE* out); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1102 | |
| 1103 | static const int kNoLineNumberInfo = 0; |
| 1104 | static const int kNoColumnInfo = 0; |
| 1105 | }; |
| 1106 | |
| 1107 | |
| 1108 | /** |
| 1109 | * Representation of a JavaScript stack trace. The information collected is a |
| 1110 | * snapshot of the execution stack and the information remains valid after |
| 1111 | * execution continues. |
| 1112 | */ |
| 1113 | class V8EXPORT StackTrace { |
| 1114 | public: |
| 1115 | /** |
| 1116 | * Flags that determine what information is placed captured for each |
| 1117 | * StackFrame when grabbing the current stack trace. |
| 1118 | */ |
| 1119 | enum StackTraceOptions { |
| 1120 | kLineNumber = 1, |
| 1121 | kColumnOffset = 1 << 1 | kLineNumber, |
| 1122 | kScriptName = 1 << 2, |
| 1123 | kFunctionName = 1 << 3, |
| 1124 | kIsEval = 1 << 4, |
| 1125 | kIsConstructor = 1 << 5, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1126 | kScriptNameOrSourceURL = 1 << 6, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1127 | kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1128 | kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1129 | }; |
| 1130 | |
| 1131 | /** |
| 1132 | * Returns a StackFrame at a particular index. |
| 1133 | */ |
| 1134 | Local<StackFrame> GetFrame(uint32_t index) const; |
| 1135 | |
| 1136 | /** |
| 1137 | * Returns the number of StackFrames. |
| 1138 | */ |
| 1139 | int GetFrameCount() const; |
| 1140 | |
| 1141 | /** |
| 1142 | * Returns StackTrace as a v8::Array that contains StackFrame objects. |
| 1143 | */ |
| 1144 | Local<Array> AsArray(); |
| 1145 | |
| 1146 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1147 | * Grab a snapshot of the current JavaScript execution stack. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1148 | * |
| 1149 | * \param frame_limit The maximum number of stack frames we want to capture. |
| 1150 | * \param options Enumerates the set of things we will capture for each |
| 1151 | * StackFrame. |
| 1152 | */ |
| 1153 | static Local<StackTrace> CurrentStackTrace( |
| 1154 | int frame_limit, |
| 1155 | StackTraceOptions options = kOverview); |
| 1156 | }; |
| 1157 | |
| 1158 | |
| 1159 | /** |
| 1160 | * A single JavaScript stack frame. |
| 1161 | */ |
| 1162 | class V8EXPORT StackFrame { |
| 1163 | public: |
| 1164 | /** |
| 1165 | * Returns the number, 1-based, of the line for the associate function call. |
| 1166 | * This method will return Message::kNoLineNumberInfo if it is unable to |
| 1167 | * retrieve the line number, or if kLineNumber was not passed as an option |
| 1168 | * when capturing the StackTrace. |
| 1169 | */ |
| 1170 | int GetLineNumber() const; |
| 1171 | |
| 1172 | /** |
| 1173 | * Returns the 1-based column offset on the line for the associated function |
| 1174 | * call. |
| 1175 | * This method will return Message::kNoColumnInfo if it is unable to retrieve |
| 1176 | * the column number, or if kColumnOffset was not passed as an option when |
| 1177 | * capturing the StackTrace. |
| 1178 | */ |
| 1179 | int GetColumn() const; |
| 1180 | |
| 1181 | /** |
| 1182 | * Returns the name of the resource that contains the script for the |
| 1183 | * function for this StackFrame. |
| 1184 | */ |
| 1185 | Local<String> GetScriptName() const; |
| 1186 | |
| 1187 | /** |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1188 | * Returns the name of the resource that contains the script for the |
| 1189 | * function for this StackFrame or sourceURL value if the script name |
| 1190 | * is undefined and its source ends with //@ sourceURL=... string. |
| 1191 | */ |
| 1192 | Local<String> GetScriptNameOrSourceURL() const; |
| 1193 | |
| 1194 | /** |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1195 | * Returns the name of the function associated with this stack frame. |
| 1196 | */ |
| 1197 | Local<String> GetFunctionName() const; |
| 1198 | |
| 1199 | /** |
| 1200 | * Returns whether or not the associated function is compiled via a call to |
| 1201 | * eval(). |
| 1202 | */ |
| 1203 | bool IsEval() const; |
| 1204 | |
| 1205 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1206 | * Returns whether or not the associated function is called as a |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1207 | * constructor via "new". |
| 1208 | */ |
| 1209 | bool IsConstructor() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1210 | }; |
| 1211 | |
| 1212 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1213 | // --- Value --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1214 | |
| 1215 | |
| 1216 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1217 | * The superclass of all JavaScript values and objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1218 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1219 | class V8EXPORT Value : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1220 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1221 | /** |
| 1222 | * Returns true if this value is the undefined value. See ECMA-262 |
| 1223 | * 4.3.10. |
| 1224 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1225 | V8_INLINE(bool IsUndefined() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1226 | |
| 1227 | /** |
| 1228 | * Returns true if this value is the null value. See ECMA-262 |
| 1229 | * 4.3.11. |
| 1230 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1231 | V8_INLINE(bool IsNull() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1232 | |
| 1233 | /** |
| 1234 | * Returns true if this value is true. |
| 1235 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1236 | bool IsTrue() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1237 | |
| 1238 | /** |
| 1239 | * Returns true if this value is false. |
| 1240 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1241 | bool IsFalse() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | |
| 1243 | /** |
| 1244 | * Returns true if this value is an instance of the String type. |
| 1245 | * See ECMA-262 8.4. |
| 1246 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1247 | V8_INLINE(bool IsString() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1248 | |
| 1249 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1250 | * Returns true if this value is a symbol. |
| 1251 | * This is an experimental feature. |
| 1252 | */ |
| 1253 | bool IsSymbol() const; |
| 1254 | |
| 1255 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1256 | * Returns true if this value is a function. |
| 1257 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1258 | bool IsFunction() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1259 | |
| 1260 | /** |
| 1261 | * Returns true if this value is an array. |
| 1262 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1263 | bool IsArray() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1265 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | * Returns true if this value is an object. |
| 1267 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1268 | bool IsObject() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1270 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | * Returns true if this value is boolean. |
| 1272 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1273 | bool IsBoolean() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1274 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1275 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | * Returns true if this value is a number. |
| 1277 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1278 | bool IsNumber() 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 external. |
| 1282 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1283 | bool IsExternal() 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 a 32-bit signed integer. |
| 1287 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1288 | bool IsInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1290 | /** |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1291 | * Returns true if this value is a 32-bit unsigned integer. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1292 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1293 | bool IsUint32() const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1294 | |
| 1295 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1296 | * Returns true if this value is a Date. |
| 1297 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1298 | bool IsDate() const; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1299 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1300 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1301 | * Returns true if this value is a Boolean object. |
| 1302 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1303 | bool IsBooleanObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1304 | |
| 1305 | /** |
| 1306 | * Returns true if this value is a Number object. |
| 1307 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1308 | bool IsNumberObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * Returns true if this value is a String object. |
| 1312 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1313 | bool IsStringObject() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1314 | |
| 1315 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1316 | * Returns true if this value is a Symbol object. |
| 1317 | * This is an experimental feature. |
| 1318 | */ |
| 1319 | bool IsSymbolObject() const; |
| 1320 | |
| 1321 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1322 | * Returns true if this value is a NativeError. |
| 1323 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1324 | bool IsNativeError() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1325 | |
| 1326 | /** |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1327 | * Returns true if this value is a RegExp. |
| 1328 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1329 | bool IsRegExp() const; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 1330 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1331 | |
| 1332 | /** |
| 1333 | * Returns true if this value is an ArrayBuffer. |
| 1334 | * This is an experimental feature. |
| 1335 | */ |
| 1336 | bool IsArrayBuffer() const; |
| 1337 | |
| 1338 | /** |
| 1339 | * Returns true if this value is one of TypedArrays. |
| 1340 | * This is an experimental feature. |
| 1341 | */ |
| 1342 | bool IsTypedArray() const; |
| 1343 | |
| 1344 | /** |
| 1345 | * Returns true if this value is an Uint8Array. |
| 1346 | * This is an experimental feature. |
| 1347 | */ |
| 1348 | bool IsUint8Array() const; |
| 1349 | |
| 1350 | /** |
| 1351 | * Returns true if this value is an Uint8ClampedArray. |
| 1352 | * This is an experimental feature. |
| 1353 | */ |
| 1354 | bool IsUint8ClampedArray() const; |
| 1355 | |
| 1356 | /** |
| 1357 | * Returns true if this value is an Int8Array. |
| 1358 | * This is an experimental feature. |
| 1359 | */ |
| 1360 | bool IsInt8Array() const; |
| 1361 | |
| 1362 | /** |
| 1363 | * Returns true if this value is an Uint16Array. |
| 1364 | * This is an experimental feature. |
| 1365 | */ |
| 1366 | bool IsUint16Array() const; |
| 1367 | |
| 1368 | /** |
| 1369 | * Returns true if this value is an Int16Array. |
| 1370 | * This is an experimental feature. |
| 1371 | */ |
| 1372 | bool IsInt16Array() const; |
| 1373 | |
| 1374 | /** |
| 1375 | * Returns true if this value is an Uint32Array. |
| 1376 | * This is an experimental feature. |
| 1377 | */ |
| 1378 | bool IsUint32Array() const; |
| 1379 | |
| 1380 | /** |
| 1381 | * Returns true if this value is an Int32Array. |
| 1382 | * This is an experimental feature. |
| 1383 | */ |
| 1384 | bool IsInt32Array() const; |
| 1385 | |
| 1386 | /** |
| 1387 | * Returns true if this value is a Float32Array. |
| 1388 | * This is an experimental feature. |
| 1389 | */ |
| 1390 | bool IsFloat32Array() const; |
| 1391 | |
| 1392 | /** |
| 1393 | * Returns true if this value is a Float64Array. |
| 1394 | * This is an experimental feature. |
| 1395 | */ |
| 1396 | bool IsFloat64Array() const; |
| 1397 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1398 | Local<Boolean> ToBoolean() const; |
| 1399 | Local<Number> ToNumber() const; |
| 1400 | Local<String> ToString() const; |
| 1401 | Local<String> ToDetailString() const; |
| 1402 | Local<Object> ToObject() const; |
| 1403 | Local<Integer> ToInteger() const; |
| 1404 | Local<Uint32> ToUint32() const; |
| 1405 | Local<Int32> ToInt32() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1406 | |
| 1407 | /** |
| 1408 | * Attempts to convert a string to an array index. |
| 1409 | * Returns an empty handle if the conversion fails. |
| 1410 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1411 | Local<Uint32> ToArrayIndex() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1412 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1413 | bool BooleanValue() const; |
| 1414 | double NumberValue() const; |
| 1415 | int64_t IntegerValue() const; |
| 1416 | uint32_t Uint32Value() const; |
| 1417 | int32_t Int32Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1418 | |
| 1419 | /** JS == */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1420 | bool Equals(Handle<Value> that) const; |
| 1421 | bool StrictEquals(Handle<Value> that) const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1422 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1423 | private: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1424 | V8_INLINE(bool QuickIsUndefined() const); |
| 1425 | V8_INLINE(bool QuickIsNull() const); |
| 1426 | V8_INLINE(bool QuickIsString() const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1427 | bool FullIsUndefined() const; |
| 1428 | bool FullIsNull() const; |
| 1429 | bool FullIsString() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1430 | }; |
| 1431 | |
| 1432 | |
| 1433 | /** |
| 1434 | * The superclass of primitive values. See ECMA-262 4.3.2. |
| 1435 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1436 | class V8EXPORT Primitive : public Value { }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | |
| 1438 | |
| 1439 | /** |
| 1440 | * A primitive boolean value (ECMA-262, 4.3.14). Either the true |
| 1441 | * or false value. |
| 1442 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1443 | class V8EXPORT Boolean : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1445 | bool Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1446 | V8_INLINE(static Handle<Boolean> New(bool value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1447 | }; |
| 1448 | |
| 1449 | |
| 1450 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1451 | * A JavaScript string value (ECMA-262, 4.3.17). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1453 | class V8EXPORT String : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1454 | public: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1455 | enum Encoding { |
| 1456 | UNKNOWN_ENCODING = 0x1, |
| 1457 | TWO_BYTE_ENCODING = 0x0, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1458 | ASCII_ENCODING = 0x4, |
| 1459 | ONE_BYTE_ENCODING = 0x4 |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1460 | }; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1461 | /** |
| 1462 | * Returns the number of characters in this string. |
| 1463 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1464 | int Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1465 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1466 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1467 | * Returns the number of bytes in the UTF-8 encoded |
| 1468 | * representation of this string. |
| 1469 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1470 | int Utf8Length() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1471 | |
| 1472 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1473 | * This function is no longer useful. |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1474 | */ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1475 | V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1476 | |
| 1477 | /** |
| 1478 | * Returns whether this string contains only one byte data. |
| 1479 | */ |
| 1480 | bool IsOneByte() const; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1481 | |
| 1482 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1483 | * Write the contents of the string to an external buffer. |
| 1484 | * If no arguments are given, expects the buffer to be large |
| 1485 | * enough to hold the entire string and NULL terminator. Copies |
| 1486 | * the contents of the string and the NULL terminator into the |
| 1487 | * buffer. |
| 1488 | * |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1489 | * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop |
| 1490 | * before the end of the buffer. |
| 1491 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1492 | * Copies up to length characters into the output buffer. |
| 1493 | * Only null-terminates if there is enough space in the buffer. |
| 1494 | * |
| 1495 | * \param buffer The buffer into which the string will be copied. |
| 1496 | * \param start The starting position within the string at which |
| 1497 | * copying begins. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1498 | * \param length The number of characters to copy from the string. For |
| 1499 | * WriteUtf8 the number of bytes in the buffer. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1500 | * \param nchars_ref The number of characters written, can be NULL. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1501 | * \param options Various options that might affect performance of this or |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1502 | * subsequent operations. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1503 | * \return The number of characters copied to the buffer excluding the null |
| 1504 | * terminator. For WriteUtf8: The number of bytes copied to the buffer |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1505 | * including the null terminator (if written). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1506 | */ |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1507 | enum WriteOptions { |
| 1508 | NO_OPTIONS = 0, |
| 1509 | HINT_MANY_WRITES_EXPECTED = 1, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1510 | NO_NULL_TERMINATION = 2, |
| 1511 | PRESERVE_ASCII_NULL = 4 |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1512 | }; |
| 1513 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1514 | // 16-bit character codes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1515 | int Write(uint16_t* buffer, |
| 1516 | int start = 0, |
| 1517 | int length = -1, |
| 1518 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1519 | // ASCII characters. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1520 | V8_DEPRECATED(int WriteAscii(char* buffer, |
| 1521 | int start = 0, |
| 1522 | int length = -1, |
| 1523 | int options = NO_OPTIONS) const); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1524 | // One byte characters. |
| 1525 | int WriteOneByte(uint8_t* buffer, |
| 1526 | int start = 0, |
| 1527 | int length = -1, |
| 1528 | int options = NO_OPTIONS) const; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1529 | // UTF-8 encoded characters. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1530 | int WriteUtf8(char* buffer, |
| 1531 | int length = -1, |
| 1532 | int* nchars_ref = NULL, |
| 1533 | int options = NO_OPTIONS) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1534 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1535 | /** |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1536 | * A zero length string. |
| 1537 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1538 | static v8::Local<v8::String> Empty(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1539 | V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate)); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 1540 | |
| 1541 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1542 | * Returns true if the string is external |
| 1543 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1544 | bool IsExternal() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1545 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1546 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1547 | * Returns true if the string is both external and ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1548 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1549 | bool IsExternalAscii() const; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1550 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1551 | class V8EXPORT ExternalStringResourceBase { // NOLINT |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1552 | public: |
| 1553 | virtual ~ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1554 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1555 | protected: |
| 1556 | ExternalStringResourceBase() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1557 | |
| 1558 | /** |
| 1559 | * Internally V8 will call this Dispose method when the external string |
| 1560 | * resource is no longer needed. The default implementation will use the |
| 1561 | * delete operator. This method can be overridden in subclasses to |
| 1562 | * control how allocated external string resources are disposed. |
| 1563 | */ |
| 1564 | virtual void Dispose() { delete this; } |
| 1565 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1566 | private: |
| 1567 | // Disallow copying and assigning. |
| 1568 | ExternalStringResourceBase(const ExternalStringResourceBase&); |
| 1569 | void operator=(const ExternalStringResourceBase&); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1570 | |
| 1571 | friend class v8::internal::Heap; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1572 | }; |
| 1573 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1574 | /** |
| 1575 | * An ExternalStringResource is a wrapper around a two-byte string |
| 1576 | * buffer that resides outside V8's heap. Implement an |
| 1577 | * ExternalStringResource to manage the life cycle of the underlying |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1578 | * buffer. Note that the string data must be immutable. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1579 | */ |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1580 | class V8EXPORT ExternalStringResource |
| 1581 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1582 | public: |
| 1583 | /** |
| 1584 | * Override the destructor to manage the life cycle of the underlying |
| 1585 | * buffer. |
| 1586 | */ |
| 1587 | virtual ~ExternalStringResource() {} |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1588 | |
| 1589 | /** |
| 1590 | * The string data from the underlying buffer. |
| 1591 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1592 | virtual const uint16_t* data() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1593 | |
| 1594 | /** |
| 1595 | * The length of the string. That is, the number of two-byte characters. |
| 1596 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1597 | virtual size_t length() const = 0; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1598 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1599 | protected: |
| 1600 | ExternalStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1601 | }; |
| 1602 | |
| 1603 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1604 | * An ExternalAsciiStringResource is a wrapper around an ASCII |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1605 | * string buffer that resides outside V8's heap. Implement an |
| 1606 | * ExternalAsciiStringResource to manage the life cycle of the |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1607 | * underlying buffer. Note that the string data must be immutable |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1608 | * 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] | 1609 | * UTF-8, which would require special treatment internally in the |
| 1610 | * engine and, in the case of UTF-8, do not allow efficient indexing. |
| 1611 | * 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] | 1612 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1613 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1614 | class V8EXPORT ExternalAsciiStringResource |
| 1615 | : public ExternalStringResourceBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1616 | public: |
| 1617 | /** |
| 1618 | * Override the destructor to manage the life cycle of the underlying |
| 1619 | * buffer. |
| 1620 | */ |
| 1621 | virtual ~ExternalAsciiStringResource() {} |
| 1622 | /** The string data from the underlying buffer.*/ |
| 1623 | virtual const char* data() const = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1624 | /** The number of ASCII characters in the string.*/ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1625 | virtual size_t length() const = 0; |
| 1626 | protected: |
| 1627 | ExternalAsciiStringResource() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1628 | }; |
| 1629 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1630 | typedef ExternalAsciiStringResource ExternalOneByteStringResource; |
| 1631 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1632 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1633 | * If the string is an external string, return the ExternalStringResourceBase |
| 1634 | * regardless of the encoding, otherwise return NULL. The encoding of the |
| 1635 | * string is returned in encoding_out. |
| 1636 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1637 | V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase( |
| 1638 | Encoding* encoding_out) const); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1639 | |
| 1640 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1641 | * Get the ExternalStringResource for an external string. Returns |
| 1642 | * NULL if IsExternal() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1643 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1644 | V8_INLINE(ExternalStringResource* GetExternalStringResource() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | |
| 1646 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1647 | * Get the ExternalAsciiStringResource for an external ASCII string. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1648 | * Returns NULL if IsExternalAscii() doesn't return true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1649 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1650 | const ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1651 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1652 | V8_INLINE(static String* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1653 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1654 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1655 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1656 | * 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] | 1657 | * The second parameter 'length' gives the buffer length. If omitted, |
| 1658 | * the function calls 'strlen' to determine the buffer length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1659 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1660 | 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] | 1661 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1662 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1663 | /** Allocates a new string from 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1664 | 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] | 1665 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1666 | // TODO(dcarney): deprecate |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1667 | /** |
| 1668 | * Creates an internalized string (historically called a "symbol", |
| 1669 | * 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] | 1670 | */ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1671 | V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1)); |
| 1672 | |
| 1673 | enum NewStringType { |
| 1674 | kNormalString, kInternalizedString, kUndetectableString |
| 1675 | }; |
| 1676 | |
| 1677 | /** Allocates a new string from UTF-8 data.*/ |
| 1678 | static Local<String> NewFromUtf8(Isolate* isolate, |
| 1679 | const char* data, |
| 1680 | NewStringType type = kNormalString, |
| 1681 | int length = -1); |
| 1682 | |
| 1683 | /** Allocates a new string from Latin-1 data.*/ |
| 1684 | static Local<String> NewFromOneByte( |
| 1685 | Isolate* isolate, |
| 1686 | const uint8_t* data, |
| 1687 | NewStringType type = kNormalString, |
| 1688 | int length = -1); |
| 1689 | |
| 1690 | /** Allocates a new string from UTF-16 data.*/ |
| 1691 | static Local<String> NewFromTwoByte( |
| 1692 | Isolate* isolate, |
| 1693 | const uint16_t* data, |
| 1694 | NewStringType type = kNormalString, |
| 1695 | int length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1696 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1697 | /** |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1698 | * Creates a new string by concatenating the left and the right strings |
| 1699 | * passed in as parameters. |
| 1700 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1701 | 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] | 1702 | |
| 1703 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1704 | * 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] | 1705 | * 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] | 1706 | * resource will be disposed by calling its Dispose method. The caller of |
| 1707 | * this function should not otherwise delete or modify the resource. Neither |
| 1708 | * should the underlying buffer be deallocated or modified except through the |
| 1709 | * destructor of the external string resource. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1710 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1711 | static Local<String> NewExternal(ExternalStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1712 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1713 | /** |
| 1714 | * Associate an external string resource with this string by transforming it |
| 1715 | * in place so that existing references to this string in the JavaScript heap |
| 1716 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1717 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1718 | * 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] | 1719 | * The string is not modified if the operation fails. See NewExternal for |
| 1720 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1721 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1722 | bool MakeExternal(ExternalStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1724 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1725 | * 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] | 1726 | * 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] | 1727 | * resource will be disposed by calling its Dispose method. The caller of |
| 1728 | * this function should not otherwise delete or modify the resource. Neither |
| 1729 | * should the underlying buffer be deallocated or modified except through the |
| 1730 | * destructor of the external string resource. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1731 | */ |
| 1732 | static Local<String> NewExternal(ExternalAsciiStringResource* resource); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1733 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1734 | /** |
| 1735 | * Associate an external string resource with this string by transforming it |
| 1736 | * in place so that existing references to this string in the JavaScript heap |
| 1737 | * will use the external string resource. The external string resource's |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1738 | * character contents need to be equivalent to this string. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1739 | * 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] | 1740 | * The string is not modified if the operation fails. See NewExternal for |
| 1741 | * information on the lifetime of the resource. |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1742 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1743 | bool MakeExternal(ExternalAsciiStringResource* resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1744 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1745 | /** |
| 1746 | * Returns true if this string can be made external. |
| 1747 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1748 | bool CanMakeExternal(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 1749 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1750 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1751 | /** 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] | 1752 | V8_INLINE( |
| 1753 | static Local<String> NewUndetectable(const char* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1754 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1755 | // TODO(dcarney): deprecate |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1756 | /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1757 | V8_INLINE(static Local<String> NewUndetectable( |
| 1758 | const uint16_t* data, int length = -1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1759 | |
| 1760 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1761 | * 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] | 1762 | * 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] | 1763 | * (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] | 1764 | * then the length() method returns 0 and the * operator returns |
| 1765 | * NULL. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1766 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1767 | class V8EXPORT Utf8Value { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1768 | public: |
| 1769 | explicit Utf8Value(Handle<v8::Value> obj); |
| 1770 | ~Utf8Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1771 | char* operator*() { return str_; } |
| 1772 | const char* operator*() const { return str_; } |
| 1773 | int length() const { return length_; } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1774 | private: |
| 1775 | char* str_; |
| 1776 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1777 | |
| 1778 | // Disallow copying and assigning. |
| 1779 | Utf8Value(const Utf8Value&); |
| 1780 | void operator=(const Utf8Value&); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1781 | }; |
| 1782 | |
| 1783 | /** |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1784 | * Converts an object to an ASCII string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1785 | * Useful if you want to print the object. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1786 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1787 | * method of the object) then the length() method returns 0 and the * operator |
| 1788 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1789 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1790 | class V8EXPORT AsciiValue { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1791 | public: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 1792 | // TODO(dcarney): deprecate |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1793 | explicit AsciiValue(Handle<v8::Value> obj); |
| 1794 | ~AsciiValue(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1795 | char* operator*() { return str_; } |
| 1796 | const char* operator*() const { return str_; } |
| 1797 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | private: |
| 1799 | char* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1800 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1801 | |
| 1802 | // Disallow copying and assigning. |
| 1803 | AsciiValue(const AsciiValue&); |
| 1804 | void operator=(const AsciiValue&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1805 | }; |
| 1806 | |
| 1807 | /** |
| 1808 | * Converts an object to a two-byte string. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 1809 | * If conversion to a string fails (eg. due to an exception in the toString() |
| 1810 | * method of the object) then the length() method returns 0 and the * operator |
| 1811 | * returns NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1812 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1813 | class V8EXPORT Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1814 | public: |
| 1815 | explicit Value(Handle<v8::Value> obj); |
| 1816 | ~Value(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1817 | uint16_t* operator*() { return str_; } |
| 1818 | const uint16_t* operator*() const { return str_; } |
| 1819 | int length() const { return length_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | private: |
| 1821 | uint16_t* str_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1822 | int length_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1823 | |
| 1824 | // Disallow copying and assigning. |
| 1825 | Value(const Value&); |
| 1826 | void operator=(const Value&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1828 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1829 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1830 | void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1831 | Encoding encoding) const; |
| 1832 | void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 1833 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1834 | }; |
| 1835 | |
| 1836 | |
| 1837 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1838 | * A JavaScript symbol (ECMA-262 edition 6) |
| 1839 | * |
| 1840 | * This is an experimental feature. Use at your own risk. |
| 1841 | */ |
| 1842 | class V8EXPORT Symbol : public Primitive { |
| 1843 | public: |
| 1844 | // Returns the print name string of the symbol, or undefined if none. |
| 1845 | Local<Value> Name() const; |
| 1846 | |
| 1847 | // Create a symbol without a print name. |
| 1848 | static Local<Symbol> New(Isolate* isolate); |
| 1849 | |
| 1850 | // Create a symbol with a print name. |
| 1851 | static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); |
| 1852 | |
| 1853 | V8_INLINE(static Symbol* Cast(v8::Value* obj)); |
| 1854 | private: |
| 1855 | Symbol(); |
| 1856 | static void CheckCast(v8::Value* obj); |
| 1857 | }; |
| 1858 | |
| 1859 | |
| 1860 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1861 | * A JavaScript number value (ECMA-262, 4.3.20) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1863 | class V8EXPORT Number : public Primitive { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1864 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1865 | double Value() const; |
| 1866 | static Local<Number> New(double value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1867 | V8_INLINE(static Number* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1868 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1869 | Number(); |
| 1870 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1871 | }; |
| 1872 | |
| 1873 | |
| 1874 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1875 | * A JavaScript value representing a signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1876 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1877 | class V8EXPORT Integer : public Number { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1878 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1879 | static Local<Integer> New(int32_t value); |
| 1880 | static Local<Integer> NewFromUnsigned(uint32_t value); |
| 1881 | static Local<Integer> New(int32_t value, Isolate*); |
| 1882 | static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); |
| 1883 | int64_t Value() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1884 | V8_INLINE(static Integer* Cast(v8::Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1885 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1886 | Integer(); |
| 1887 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | }; |
| 1889 | |
| 1890 | |
| 1891 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1892 | * A JavaScript value representing a 32-bit signed integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1893 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1894 | class V8EXPORT Int32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1895 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1896 | int32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1898 | Int32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | }; |
| 1900 | |
| 1901 | |
| 1902 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1903 | * A JavaScript value representing a 32-bit unsigned integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1905 | class V8EXPORT Uint32 : public Integer { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1906 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1907 | uint32_t Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1908 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1909 | Uint32(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1910 | }; |
| 1911 | |
| 1912 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1913 | enum PropertyAttribute { |
| 1914 | None = 0, |
| 1915 | ReadOnly = 1 << 0, |
| 1916 | DontEnum = 1 << 1, |
| 1917 | DontDelete = 1 << 2 |
| 1918 | }; |
| 1919 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1920 | enum ExternalArrayType { |
| 1921 | kExternalByteArray = 1, |
| 1922 | kExternalUnsignedByteArray, |
| 1923 | kExternalShortArray, |
| 1924 | kExternalUnsignedShortArray, |
| 1925 | kExternalIntArray, |
| 1926 | kExternalUnsignedIntArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1927 | kExternalFloatArray, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1928 | kExternalDoubleArray, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1929 | kExternalPixelArray |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1930 | }; |
| 1931 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1932 | /** |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1933 | * Accessor[Getter|Setter] are used as callback functions when |
| 1934 | * setting|getting a particular property. See Object and ObjectTemplate's |
| 1935 | * method SetAccessor. |
| 1936 | */ |
| 1937 | typedef Handle<Value> (*AccessorGetter)(Local<String> property, |
| 1938 | const AccessorInfo& info); |
| 1939 | |
| 1940 | |
| 1941 | typedef void (*AccessorSetter)(Local<String> property, |
| 1942 | Local<Value> value, |
| 1943 | const AccessorInfo& info); |
| 1944 | |
| 1945 | |
| 1946 | /** |
| 1947 | * Access control specifications. |
| 1948 | * |
| 1949 | * Some accessors should be accessible across contexts. These |
| 1950 | * accessors have an explicit access control parameter which specifies |
| 1951 | * the kind of cross-context access that should be allowed. |
| 1952 | * |
| 1953 | * Additionally, for security, accessors can prohibit overwriting by |
| 1954 | * accessors defined in JavaScript. For objects that have such |
| 1955 | * accessors either locally or in their prototype chain it is not |
| 1956 | * possible to overwrite the accessor by using __defineGetter__ or |
| 1957 | * __defineSetter__ from JavaScript code. |
| 1958 | */ |
| 1959 | enum AccessControl { |
| 1960 | DEFAULT = 0, |
| 1961 | ALL_CAN_READ = 1, |
| 1962 | ALL_CAN_WRITE = 1 << 1, |
| 1963 | PROHIBITS_OVERWRITING = 1 << 2 |
| 1964 | }; |
| 1965 | |
| 1966 | |
| 1967 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1968 | * A JavaScript object (ECMA-262, 4.3.3) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1970 | class V8EXPORT Object : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1971 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1972 | bool Set(Handle<Value> key, |
| 1973 | Handle<Value> value, |
| 1974 | PropertyAttribute attribs = None); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1975 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1976 | bool Set(uint32_t index, Handle<Value> value); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1977 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1978 | // Sets a local property on this object bypassing interceptors and |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1979 | // overriding accessors or read-only properties. |
| 1980 | // |
| 1981 | // Note that if the object has an interceptor the property will be set |
| 1982 | // locally, but since the interceptor takes precedence the local property |
| 1983 | // will only be returned if the interceptor doesn't return a value. |
| 1984 | // |
| 1985 | // Note also that this only works for named properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1986 | bool ForceSet(Handle<Value> key, |
| 1987 | Handle<Value> value, |
| 1988 | PropertyAttribute attribs = None); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1989 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1990 | Local<Value> Get(Handle<Value> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1991 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1992 | Local<Value> Get(uint32_t index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1993 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1994 | /** |
| 1995 | * Gets the property attributes of a property which can be None or |
| 1996 | * any combination of ReadOnly, DontEnum and DontDelete. Returns |
| 1997 | * None when the property doesn't exist. |
| 1998 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1999 | PropertyAttribute GetPropertyAttributes(Handle<Value> key); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2000 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2001 | bool Has(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2002 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2003 | bool Delete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2004 | |
| 2005 | // Delete a property on this object bypassing interceptors and |
| 2006 | // ignoring dont-delete attributes. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2007 | bool ForceDelete(Handle<Value> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2008 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2009 | bool Has(uint32_t index); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2010 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2011 | bool Delete(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2012 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2013 | bool SetAccessor(Handle<String> name, |
| 2014 | AccessorGetter getter, |
| 2015 | AccessorSetter setter = 0, |
| 2016 | Handle<Value> data = Handle<Value>(), |
| 2017 | AccessControl settings = DEFAULT, |
| 2018 | PropertyAttribute attribute = None); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2019 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2020 | // This function is not yet stable and should not be used at this time. |
| 2021 | bool SetAccessor(Handle<String> name, |
| 2022 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 2023 | AccessControl settings = DEFAULT, |
| 2024 | PropertyAttribute attribute = None); |
| 2025 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2026 | /** |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2027 | * Returns an array containing the names of the enumerable properties |
| 2028 | * of this object, including properties from prototype objects. The |
| 2029 | * array returned by this method contains the same values as would |
| 2030 | * be enumerated by a for-in statement over this object. |
| 2031 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2032 | Local<Array> GetPropertyNames(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2033 | |
| 2034 | /** |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2035 | * This function has the same functionality as GetPropertyNames but |
| 2036 | * the returned array doesn't contain the names of properties from |
| 2037 | * prototype objects. |
| 2038 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2039 | Local<Array> GetOwnPropertyNames(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2040 | |
| 2041 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2042 | * Get the prototype object. This does not skip objects marked to |
| 2043 | * be skipped by __proto__ and it does not consult the security |
| 2044 | * handler. |
| 2045 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2046 | Local<Value> GetPrototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2047 | |
| 2048 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2049 | * Set the prototype object. This does not skip objects marked to |
| 2050 | * be skipped by __proto__ and it does not consult the security |
| 2051 | * handler. |
| 2052 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2053 | bool SetPrototype(Handle<Value> prototype); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2054 | |
| 2055 | /** |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2056 | * Finds an instance of the given function template in the prototype |
| 2057 | * chain. |
| 2058 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2059 | Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2060 | |
| 2061 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2062 | * Call builtin Object.prototype.toString on this object. |
| 2063 | * This is different from Value::ToString() that may call |
| 2064 | * user-defined toString function. This one does not. |
| 2065 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2066 | Local<String> ObjectProtoToString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2067 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2068 | /** |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2069 | * Returns the function invoked as a constructor for this object. |
| 2070 | * May be the null value. |
| 2071 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2072 | Local<Value> GetConstructor(); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 2073 | |
| 2074 | /** |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2075 | * Returns the name of the function invoked as a constructor for this object. |
| 2076 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2077 | Local<String> GetConstructorName(); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2078 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2079 | /** Gets the number of internal fields for this Object. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2080 | int InternalFieldCount(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2081 | |
| 2082 | /** Gets the value from an internal field. */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2083 | V8_INLINE(Local<Value> GetInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2084 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2085 | /** Sets the value in an internal field. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2086 | void SetInternalField(int index, Handle<Value> value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2087 | |
| 2088 | /** |
| 2089 | * Gets a 2-byte-aligned native pointer from an internal field. This field |
| 2090 | * must have been set by SetAlignedPointerInInternalField, everything else |
| 2091 | * leads to undefined behavior. |
| 2092 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2093 | V8_INLINE(void* GetAlignedPointerFromInternalField(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2094 | |
| 2095 | /** |
| 2096 | * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such |
| 2097 | * a field, GetAlignedPointerFromInternalField must be used, everything else |
| 2098 | * leads to undefined behavior. |
| 2099 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2100 | void SetAlignedPointerInInternalField(int index, void* value); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2101 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2102 | // Testers for local properties. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2103 | bool HasOwnProperty(Handle<String> key); |
| 2104 | bool HasRealNamedProperty(Handle<String> key); |
| 2105 | bool HasRealIndexedProperty(uint32_t index); |
| 2106 | bool HasRealNamedCallbackProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2107 | |
| 2108 | /** |
| 2109 | * If result.IsEmpty() no real property was located in the prototype chain. |
| 2110 | * This means interceptors in the prototype chain are not called. |
| 2111 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2112 | Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 2113 | |
| 2114 | /** |
| 2115 | * If result.IsEmpty() no real property was located on the object or |
| 2116 | * in the prototype chain. |
| 2117 | * This means interceptors in the prototype chain are not called. |
| 2118 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2119 | Local<Value> GetRealNamedProperty(Handle<String> key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2120 | |
| 2121 | /** Tests for a named lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2122 | bool HasNamedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2123 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2124 | /** Tests for an index lookup interceptor.*/ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2125 | bool HasIndexedLookupInterceptor(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2126 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2127 | /** |
| 2128 | * Turns on access check on the object if the object is an instance of |
| 2129 | * a template that has access check callbacks. If an object has no |
| 2130 | * access check info, the object cannot be accessed by anyone. |
| 2131 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2132 | void TurnOnAccessCheck(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2133 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2134 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2135 | * Returns the identity hash for this object. The current implementation |
| 2136 | * 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] | 2137 | * |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2138 | * 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] | 2139 | * unique. |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2140 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2141 | int GetIdentityHash(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 2142 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2143 | /** |
| 2144 | * Access hidden properties on JavaScript objects. These properties are |
| 2145 | * hidden from the executing JavaScript and only accessible through the V8 |
| 2146 | * C++ API. Hidden properties introduced by V8 internally (for example the |
| 2147 | * identity hash) are prefixed with "v8::". |
| 2148 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2149 | bool SetHiddenValue(Handle<String> key, Handle<Value> value); |
| 2150 | Local<Value> GetHiddenValue(Handle<String> key); |
| 2151 | bool DeleteHiddenValue(Handle<String> key); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2152 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2153 | /** |
| 2154 | * Returns true if this is an instance of an api function (one |
| 2155 | * created from a function created from a function template) and has |
| 2156 | * been modified since it was created. Note that this method is |
| 2157 | * conservative and may return true for objects that haven't actually |
| 2158 | * been modified. |
| 2159 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2160 | bool IsDirty(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 2161 | |
| 2162 | /** |
| 2163 | * Clone this object with a fast but shallow copy. Values will point |
| 2164 | * to the same values as the original object. |
| 2165 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2166 | Local<Object> Clone(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2167 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2168 | /** |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2169 | * Returns the context in which the object was created. |
| 2170 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2171 | Local<Context> CreationContext(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2172 | |
| 2173 | /** |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2174 | * Set the backing store of the indexed properties to be managed by the |
| 2175 | * embedding layer. Access to the indexed properties will follow the rules |
| 2176 | * spelled out in CanvasPixelArray. |
| 2177 | * Note: The embedding program still owns the data and needs to ensure that |
| 2178 | * the backing store is preserved while V8 has a reference. |
| 2179 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2180 | void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 2181 | bool HasIndexedPropertiesInPixelData(); |
| 2182 | uint8_t* GetIndexedPropertiesPixelData(); |
| 2183 | int GetIndexedPropertiesPixelDataLength(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2184 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2185 | /** |
| 2186 | * Set the backing store of the indexed properties to be managed by the |
| 2187 | * embedding layer. Access to the indexed properties will follow the rules |
| 2188 | * spelled out for the CanvasArray subtypes in the WebGL specification. |
| 2189 | * Note: The embedding program still owns the data and needs to ensure that |
| 2190 | * the backing store is preserved while V8 has a reference. |
| 2191 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2192 | void SetIndexedPropertiesToExternalArrayData(void* data, |
| 2193 | ExternalArrayType array_type, |
| 2194 | int number_of_elements); |
| 2195 | bool HasIndexedPropertiesInExternalArrayData(); |
| 2196 | void* GetIndexedPropertiesExternalArrayData(); |
| 2197 | ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 2198 | int GetIndexedPropertiesExternalArrayDataLength(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2199 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2200 | /** |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2201 | * Checks whether a callback is set by the |
| 2202 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2203 | * When an Object is callable this method returns true. |
| 2204 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2205 | bool IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2206 | |
| 2207 | /** |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 2208 | * 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] | 2209 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2210 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2211 | Local<Value> CallAsFunction(Handle<Object> recv, |
| 2212 | int argc, |
| 2213 | Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2214 | |
| 2215 | /** |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2216 | * 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] | 2217 | * ObjectTemplate::SetCallAsFunctionHandler method. |
| 2218 | * Note: This method behaves like the Function::NewInstance method. |
| 2219 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2220 | Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2221 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2222 | static Local<Object> New(); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2223 | V8_INLINE(static Object* Cast(Value* obj)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2225 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2226 | Object(); |
| 2227 | static void CheckCast(Value* obj); |
| 2228 | Local<Value> SlowGetInternalField(int index); |
| 2229 | void* SlowGetAlignedPointerFromInternalField(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2230 | }; |
| 2231 | |
| 2232 | |
| 2233 | /** |
| 2234 | * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 2235 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2236 | class V8EXPORT Array : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2237 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2238 | uint32_t Length() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2239 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2240 | /** |
| 2241 | * Clones an element at index |index|. Returns an empty |
| 2242 | * handle if cloning fails (for any reason). |
| 2243 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2244 | Local<Object> CloneElementAt(uint32_t index); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2245 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2246 | /** |
| 2247 | * Creates a JavaScript array with the given length. If the length |
| 2248 | * is negative the returned array will have length 0. |
| 2249 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2250 | static Local<Array> New(int length = 0); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2251 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2252 | V8_INLINE(static Array* Cast(Value* obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2253 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2254 | Array(); |
| 2255 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2256 | }; |
| 2257 | |
| 2258 | |
| 2259 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2260 | * A JavaScript function object (ECMA-262, 15.3). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2261 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2262 | class V8EXPORT Function : public Object { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2263 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2264 | Local<Object> NewInstance() const; |
| 2265 | Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 2266 | Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 2267 | void SetName(Handle<String> name); |
| 2268 | Handle<Value> GetName() const; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2269 | |
| 2270 | /** |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2271 | * Name inferred from variable or property assignment of this function. |
| 2272 | * Used to facilitate debugging and profiling of JavaScript code written |
| 2273 | * in an OO style, where many functions are anonymous but are assigned |
| 2274 | * to object properties. |
| 2275 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2276 | Handle<Value> GetInferredName() const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2277 | |
| 2278 | /** |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2279 | * Returns zero based line number of function body and |
| 2280 | * kLineOffsetNotFound if no information available. |
| 2281 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2282 | int GetScriptLineNumber() const; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2283 | /** |
| 2284 | * Returns zero based column number of function body and |
| 2285 | * kLineOffsetNotFound if no information available. |
| 2286 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2287 | int GetScriptColumnNumber() const; |
| 2288 | Handle<Value> GetScriptId() const; |
| 2289 | ScriptOrigin GetScriptOrigin() const; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2290 | V8_INLINE(static Function* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2291 | static const int kLineOffsetNotFound; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2292 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2293 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2294 | Function(); |
| 2295 | static void CheckCast(Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2296 | }; |
| 2297 | |
| 2298 | |
| 2299 | /** |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2300 | * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
| 2301 | * This API is experimental and may change significantly. |
| 2302 | */ |
| 2303 | class V8EXPORT ArrayBuffer : public Object { |
| 2304 | public: |
| 2305 | /** |
| 2306 | * Data length in bytes. |
| 2307 | */ |
| 2308 | size_t ByteLength() const; |
| 2309 | /** |
| 2310 | * Raw pointer to the array buffer data |
| 2311 | */ |
| 2312 | void* Data() const; |
| 2313 | |
| 2314 | /** |
| 2315 | * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 2316 | * Allocated memory will be owned by a created ArrayBuffer and |
| 2317 | * will be deallocated when it is garbage-collected. |
| 2318 | */ |
| 2319 | static Local<ArrayBuffer> New(size_t byte_length); |
| 2320 | |
| 2321 | /** |
| 2322 | * Create a new ArrayBuffer over an existing memory block. |
| 2323 | * The memory block will not be reclaimed when a created ArrayBuffer |
| 2324 | * is garbage-collected. |
| 2325 | */ |
| 2326 | static Local<ArrayBuffer> New(void* data, size_t byte_length); |
| 2327 | |
| 2328 | V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
| 2329 | |
| 2330 | private: |
| 2331 | ArrayBuffer(); |
| 2332 | static void CheckCast(Value* obj); |
| 2333 | }; |
| 2334 | |
| 2335 | |
| 2336 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2337 | * A base class for an instance of TypedArray series of constructors |
| 2338 | * (ES6 draft 15.13.6). |
| 2339 | * This API is experimental and may change significantly. |
| 2340 | */ |
| 2341 | class V8EXPORT TypedArray : public Object { |
| 2342 | public: |
| 2343 | /** |
| 2344 | * Returns underlying ArrayBuffer. |
| 2345 | */ |
| 2346 | Local<ArrayBuffer> Buffer(); |
| 2347 | /** |
| 2348 | * Byte offset in |Buffer| |
| 2349 | */ |
| 2350 | size_t ByteOffset(); |
| 2351 | /** |
| 2352 | * Numbe of elements in this typed array. |
| 2353 | */ |
| 2354 | size_t Length(); |
| 2355 | /** |
| 2356 | * Size of typed array in bytes (e.g. for Int16Array, 2*|Length|). |
| 2357 | */ |
| 2358 | size_t ByteLength(); |
| 2359 | /** |
| 2360 | * Base address of typed array. |
| 2361 | */ |
| 2362 | void* BaseAddress(); |
| 2363 | |
| 2364 | V8_INLINE(static TypedArray* Cast(Value* obj)); |
| 2365 | |
| 2366 | private: |
| 2367 | TypedArray(); |
| 2368 | static void CheckCast(Value* obj); |
| 2369 | }; |
| 2370 | |
| 2371 | |
| 2372 | /** |
| 2373 | * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
| 2374 | * This API is experimental and may change significantly. |
| 2375 | */ |
| 2376 | class V8EXPORT Uint8Array : public TypedArray { |
| 2377 | public: |
| 2378 | static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2379 | size_t byte_offset, size_t length); |
| 2380 | V8_INLINE(static Uint8Array* Cast(Value* obj)); |
| 2381 | |
| 2382 | private: |
| 2383 | Uint8Array(); |
| 2384 | static void CheckCast(Value* obj); |
| 2385 | }; |
| 2386 | |
| 2387 | |
| 2388 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2389 | * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
| 2390 | * This API is experimental and may change significantly. |
| 2391 | */ |
| 2392 | class V8EXPORT Uint8ClampedArray : public TypedArray { |
| 2393 | public: |
| 2394 | static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, |
| 2395 | size_t byte_offset, size_t length); |
| 2396 | V8_INLINE(static Uint8ClampedArray* Cast(Value* obj)); |
| 2397 | |
| 2398 | private: |
| 2399 | Uint8ClampedArray(); |
| 2400 | static void CheckCast(Value* obj); |
| 2401 | }; |
| 2402 | |
| 2403 | /** |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2404 | * An instance of Int8Array constructor (ES6 draft 15.13.6). |
| 2405 | * This API is experimental and may change significantly. |
| 2406 | */ |
| 2407 | class V8EXPORT Int8Array : public TypedArray { |
| 2408 | public: |
| 2409 | static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, |
| 2410 | size_t byte_offset, size_t length); |
| 2411 | V8_INLINE(static Int8Array* Cast(Value* obj)); |
| 2412 | |
| 2413 | private: |
| 2414 | Int8Array(); |
| 2415 | static void CheckCast(Value* obj); |
| 2416 | }; |
| 2417 | |
| 2418 | |
| 2419 | /** |
| 2420 | * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
| 2421 | * This API is experimental and may change significantly. |
| 2422 | */ |
| 2423 | class V8EXPORT Uint16Array : public TypedArray { |
| 2424 | public: |
| 2425 | static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2426 | size_t byte_offset, size_t length); |
| 2427 | V8_INLINE(static Uint16Array* Cast(Value* obj)); |
| 2428 | |
| 2429 | private: |
| 2430 | Uint16Array(); |
| 2431 | static void CheckCast(Value* obj); |
| 2432 | }; |
| 2433 | |
| 2434 | |
| 2435 | /** |
| 2436 | * An instance of Int16Array constructor (ES6 draft 15.13.6). |
| 2437 | * This API is experimental and may change significantly. |
| 2438 | */ |
| 2439 | class V8EXPORT Int16Array : public TypedArray { |
| 2440 | public: |
| 2441 | static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, |
| 2442 | size_t byte_offset, size_t length); |
| 2443 | V8_INLINE(static Int16Array* Cast(Value* obj)); |
| 2444 | |
| 2445 | private: |
| 2446 | Int16Array(); |
| 2447 | static void CheckCast(Value* obj); |
| 2448 | }; |
| 2449 | |
| 2450 | |
| 2451 | /** |
| 2452 | * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
| 2453 | * This API is experimental and may change significantly. |
| 2454 | */ |
| 2455 | class V8EXPORT Uint32Array : public TypedArray { |
| 2456 | public: |
| 2457 | static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2458 | size_t byte_offset, size_t length); |
| 2459 | V8_INLINE(static Uint32Array* Cast(Value* obj)); |
| 2460 | |
| 2461 | private: |
| 2462 | Uint32Array(); |
| 2463 | static void CheckCast(Value* obj); |
| 2464 | }; |
| 2465 | |
| 2466 | |
| 2467 | /** |
| 2468 | * An instance of Int32Array constructor (ES6 draft 15.13.6). |
| 2469 | * This API is experimental and may change significantly. |
| 2470 | */ |
| 2471 | class V8EXPORT Int32Array : public TypedArray { |
| 2472 | public: |
| 2473 | static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2474 | size_t byte_offset, size_t length); |
| 2475 | V8_INLINE(static Int32Array* Cast(Value* obj)); |
| 2476 | |
| 2477 | private: |
| 2478 | Int32Array(); |
| 2479 | static void CheckCast(Value* obj); |
| 2480 | }; |
| 2481 | |
| 2482 | |
| 2483 | /** |
| 2484 | * An instance of Float32Array constructor (ES6 draft 15.13.6). |
| 2485 | * This API is experimental and may change significantly. |
| 2486 | */ |
| 2487 | class V8EXPORT Float32Array : public TypedArray { |
| 2488 | public: |
| 2489 | static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, |
| 2490 | size_t byte_offset, size_t length); |
| 2491 | V8_INLINE(static Float32Array* Cast(Value* obj)); |
| 2492 | |
| 2493 | private: |
| 2494 | Float32Array(); |
| 2495 | static void CheckCast(Value* obj); |
| 2496 | }; |
| 2497 | |
| 2498 | |
| 2499 | /** |
| 2500 | * An instance of Float64Array constructor (ES6 draft 15.13.6). |
| 2501 | * This API is experimental and may change significantly. |
| 2502 | */ |
| 2503 | class V8EXPORT Float64Array : public TypedArray { |
| 2504 | public: |
| 2505 | static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, |
| 2506 | size_t byte_offset, size_t length); |
| 2507 | V8_INLINE(static Float64Array* Cast(Value* obj)); |
| 2508 | |
| 2509 | private: |
| 2510 | Float64Array(); |
| 2511 | static void CheckCast(Value* obj); |
| 2512 | }; |
| 2513 | |
| 2514 | |
| 2515 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2516 | * An instance of the built-in Date constructor (ECMA-262, 15.9). |
| 2517 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2518 | class V8EXPORT Date : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2519 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2520 | static Local<Value> New(double time); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2521 | |
| 2522 | /** |
| 2523 | * A specialization of Value::NumberValue that is more efficient |
| 2524 | * because we know the structure of this object. |
| 2525 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2526 | double NumberValue() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2527 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2528 | V8_INLINE(static Date* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2529 | |
| 2530 | /** |
| 2531 | * Notification that the embedder has changed the time zone, |
| 2532 | * daylight savings time, or other date / time configuration |
| 2533 | * parameters. V8 keeps a cache of various values used for |
| 2534 | * date / time computation. This notification will reset |
| 2535 | * those cached values for the current context so that date / |
| 2536 | * time configuration changes would be reflected in the Date |
| 2537 | * object. |
| 2538 | * |
| 2539 | * This API should not be called more than needed as it will |
| 2540 | * negatively impact the performance of date operations. |
| 2541 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2542 | static void DateTimeConfigurationChangeNotification(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2543 | |
| 2544 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2545 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2546 | }; |
| 2547 | |
| 2548 | |
| 2549 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2550 | * A Number object (ECMA-262, 4.3.21). |
| 2551 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2552 | class V8EXPORT NumberObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2553 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2554 | static Local<Value> New(double value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2555 | |
| 2556 | /** |
| 2557 | * Returns the Number held by the object. |
| 2558 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2559 | double NumberValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2560 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2561 | V8_INLINE(static NumberObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2562 | |
| 2563 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2564 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2565 | }; |
| 2566 | |
| 2567 | |
| 2568 | /** |
| 2569 | * A Boolean object (ECMA-262, 4.3.15). |
| 2570 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2571 | class V8EXPORT BooleanObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2572 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2573 | static Local<Value> New(bool value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2574 | |
| 2575 | /** |
| 2576 | * Returns the Boolean held by the object. |
| 2577 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2578 | bool BooleanValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2579 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2580 | V8_INLINE(static BooleanObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2581 | |
| 2582 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2583 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2584 | }; |
| 2585 | |
| 2586 | |
| 2587 | /** |
| 2588 | * A String object (ECMA-262, 4.3.18). |
| 2589 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2590 | class V8EXPORT StringObject : public Object { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2591 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2592 | static Local<Value> New(Handle<String> value); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2593 | |
| 2594 | /** |
| 2595 | * Returns the String held by the object. |
| 2596 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2597 | Local<String> StringValue() const; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2598 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2599 | V8_INLINE(static StringObject* Cast(v8::Value* obj)); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2600 | |
| 2601 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2602 | static void CheckCast(v8::Value* obj); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2603 | }; |
| 2604 | |
| 2605 | |
| 2606 | /** |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2607 | * A Symbol object (ECMA-262 edition 6). |
| 2608 | * |
| 2609 | * This is an experimental feature. Use at your own risk. |
| 2610 | */ |
| 2611 | class V8EXPORT SymbolObject : public Object { |
| 2612 | public: |
| 2613 | static Local<Value> New(Isolate* isolate, Handle<Symbol> value); |
| 2614 | |
| 2615 | /** |
| 2616 | * Returns the Symbol held by the object. |
| 2617 | */ |
| 2618 | Local<Symbol> SymbolValue() const; |
| 2619 | |
| 2620 | V8_INLINE(static SymbolObject* Cast(v8::Value* obj)); |
| 2621 | |
| 2622 | private: |
| 2623 | static void CheckCast(v8::Value* obj); |
| 2624 | }; |
| 2625 | |
| 2626 | |
| 2627 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2628 | * An instance of the built-in RegExp constructor (ECMA-262, 15.10). |
| 2629 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2630 | class V8EXPORT RegExp : public Object { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2631 | public: |
| 2632 | /** |
| 2633 | * Regular expression flag bits. They can be or'ed to enable a set |
| 2634 | * of flags. |
| 2635 | */ |
| 2636 | enum Flags { |
| 2637 | kNone = 0, |
| 2638 | kGlobal = 1, |
| 2639 | kIgnoreCase = 2, |
| 2640 | kMultiline = 4 |
| 2641 | }; |
| 2642 | |
| 2643 | /** |
| 2644 | * Creates a regular expression from the given pattern string and |
| 2645 | * the flags bit field. May throw a JavaScript exception as |
| 2646 | * described in ECMA-262, 15.10.4.1. |
| 2647 | * |
| 2648 | * For example, |
| 2649 | * RegExp::New(v8::String::New("foo"), |
| 2650 | * static_cast<RegExp::Flags>(kGlobal | kMultiline)) |
| 2651 | * is equivalent to evaluating "/foo/gm". |
| 2652 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2653 | static Local<RegExp> New(Handle<String> pattern, Flags flags); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2654 | |
| 2655 | /** |
| 2656 | * Returns the value of the source property: a string representing |
| 2657 | * the regular expression. |
| 2658 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2659 | Local<String> GetSource() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2660 | |
| 2661 | /** |
| 2662 | * Returns the flags bit field. |
| 2663 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2664 | Flags GetFlags() const; |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2665 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2666 | V8_INLINE(static RegExp* Cast(v8::Value* obj)); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2667 | |
| 2668 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2669 | static void CheckCast(v8::Value* obj); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2670 | }; |
| 2671 | |
| 2672 | |
| 2673 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2674 | * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
| 2675 | * to associate C++ data structures with JavaScript objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2676 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2677 | class V8EXPORT External : public Value { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2678 | public: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2679 | static Local<External> New(void* value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2680 | V8_INLINE(static External* Cast(Value* obj)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2681 | void* Value() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2683 | static void CheckCast(v8::Value* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2684 | }; |
| 2685 | |
| 2686 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2687 | // --- Templates --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2688 | |
| 2689 | |
| 2690 | /** |
| 2691 | * The superclass of object and function templates. |
| 2692 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2693 | class V8EXPORT Template : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2694 | public: |
| 2695 | /** Adds a property to each instance created by this template.*/ |
| 2696 | void Set(Handle<String> name, Handle<Data> value, |
| 2697 | PropertyAttribute attributes = None); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2698 | V8_INLINE(void Set(const char* name, Handle<Data> value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2699 | private: |
| 2700 | Template(); |
| 2701 | |
| 2702 | friend class ObjectTemplate; |
| 2703 | friend class FunctionTemplate; |
| 2704 | }; |
| 2705 | |
| 2706 | |
| 2707 | /** |
| 2708 | * The argument information given to function call callbacks. This |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2709 | * class provides access to information about the context of the call, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2710 | * including the receiver, the number and values of arguments, and |
| 2711 | * the holder of the function. |
| 2712 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2713 | class V8EXPORT Arguments { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2714 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2715 | V8_INLINE(int Length() const); |
| 2716 | V8_INLINE(Local<Value> operator[](int i) const); |
| 2717 | V8_INLINE(Local<Function> Callee() const); |
| 2718 | V8_INLINE(Local<Object> This() const); |
| 2719 | V8_INLINE(Local<Object> Holder() const); |
| 2720 | V8_INLINE(bool IsConstructCall() const); |
| 2721 | V8_INLINE(Local<Value> Data() const); |
| 2722 | V8_INLINE(Isolate* GetIsolate() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2723 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | private: |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2725 | static const int kIsolateIndex = 0; |
| 2726 | static const int kDataIndex = -1; |
| 2727 | static const int kCalleeIndex = -2; |
| 2728 | static const int kHolderIndex = -3; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2729 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2730 | friend class ImplementationUtilities; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2731 | V8_INLINE(Arguments(internal::Object** implicit_args, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2732 | internal::Object** values, |
| 2733 | int length, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2734 | bool is_construct_call)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2735 | internal::Object** implicit_args_; |
| 2736 | internal::Object** values_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2737 | int length_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2738 | bool is_construct_call_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2739 | }; |
| 2740 | |
| 2741 | |
| 2742 | /** |
| 2743 | * The information passed to an accessor callback about the context |
| 2744 | * of the property access. |
| 2745 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2746 | class V8EXPORT AccessorInfo { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2747 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2748 | V8_INLINE(AccessorInfo(internal::Object** args)) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2749 | : args_(args) { } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2750 | V8_INLINE(Isolate* GetIsolate() const); |
| 2751 | V8_INLINE(Local<Value> Data() const); |
| 2752 | V8_INLINE(Local<Object> This() const); |
| 2753 | V8_INLINE(Local<Object> Holder() const); |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 2754 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2755 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2756 | internal::Object** args_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2757 | }; |
| 2758 | |
| 2759 | |
| 2760 | typedef Handle<Value> (*InvocationCallback)(const Arguments& args); |
| 2761 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2762 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2763 | * NamedProperty[Getter|Setter] are used as interceptors on object. |
| 2764 | * See ObjectTemplate::SetNamedPropertyHandler. |
| 2765 | */ |
| 2766 | typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 2767 | const AccessorInfo& info); |
| 2768 | |
| 2769 | |
| 2770 | /** |
| 2771 | * Returns the value if the setter intercepts the request. |
| 2772 | * Otherwise, returns an empty handle. |
| 2773 | */ |
| 2774 | typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, |
| 2775 | Local<Value> value, |
| 2776 | const AccessorInfo& info); |
| 2777 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2778 | /** |
| 2779 | * Returns a non-empty handle if the interceptor intercepts the request. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2780 | * The result is an integer encoding property attributes (like v8::None, |
| 2781 | * v8::DontEnum, etc.) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2782 | */ |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2783 | typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, |
| 2784 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2785 | |
| 2786 | |
| 2787 | /** |
| 2788 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2789 | * The return value is true if the property could be deleted and false |
| 2790 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2791 | */ |
| 2792 | typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, |
| 2793 | const AccessorInfo& info); |
| 2794 | |
| 2795 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2796 | * Returns an array containing the names of the properties the named |
| 2797 | * property getter intercepts. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2798 | */ |
| 2799 | typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); |
| 2800 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2801 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2803 | * Returns the value of the property if the getter intercepts the |
| 2804 | * request. Otherwise, returns an empty handle. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2805 | */ |
| 2806 | typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, |
| 2807 | const AccessorInfo& info); |
| 2808 | |
| 2809 | |
| 2810 | /** |
| 2811 | * Returns the value if the setter intercepts the request. |
| 2812 | * Otherwise, returns an empty handle. |
| 2813 | */ |
| 2814 | typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, |
| 2815 | Local<Value> value, |
| 2816 | const AccessorInfo& info); |
| 2817 | |
| 2818 | |
| 2819 | /** |
| 2820 | * Returns a non-empty handle if the interceptor intercepts the request. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2821 | * The result is an integer encoding property attributes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2822 | */ |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2823 | typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, |
| 2824 | const AccessorInfo& info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2825 | |
| 2826 | /** |
| 2827 | * Returns a non-empty handle if the deleter intercepts the request. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2828 | * The return value is true if the property could be deleted and false |
| 2829 | * otherwise. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2830 | */ |
| 2831 | typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, |
| 2832 | const AccessorInfo& info); |
| 2833 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2834 | /** |
| 2835 | * Returns an array containing the indices of the properties the |
| 2836 | * indexed property getter intercepts. |
| 2837 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); |
| 2839 | |
| 2840 | |
| 2841 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2842 | * Access type specification. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2843 | */ |
| 2844 | enum AccessType { |
| 2845 | ACCESS_GET, |
| 2846 | ACCESS_SET, |
| 2847 | ACCESS_HAS, |
| 2848 | ACCESS_DELETE, |
| 2849 | ACCESS_KEYS |
| 2850 | }; |
| 2851 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2852 | |
| 2853 | /** |
| 2854 | * 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] | 2855 | * property with the given key on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2856 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2857 | typedef bool (*NamedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2858 | Local<Value> key, |
| 2859 | AccessType type, |
| 2860 | Local<Value> data); |
| 2861 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2862 | |
| 2863 | /** |
| 2864 | * 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] | 2865 | * property with the given index on the host object. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2866 | */ |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2867 | typedef bool (*IndexedSecurityCallback)(Local<Object> host, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2868 | uint32_t index, |
| 2869 | AccessType type, |
| 2870 | Local<Value> data); |
| 2871 | |
| 2872 | |
| 2873 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2874 | * A FunctionTemplate is used to create functions at runtime. There |
| 2875 | * can only be one function created from a FunctionTemplate in a |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2876 | * context. The lifetime of the created function is equal to the |
| 2877 | * lifetime of the context. So in case the embedder needs to create |
| 2878 | * temporary functions that can be collected using Scripts is |
| 2879 | * preferred. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2880 | * |
| 2881 | * A FunctionTemplate can have properties, these properties are added to the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2882 | * function object when it is created. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2883 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2884 | * A FunctionTemplate has a corresponding instance template which is |
| 2885 | * used to create object instances when the function is used as a |
| 2886 | * constructor. Properties added to the instance template are added to |
| 2887 | * each object instance. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | * |
| 2889 | * A FunctionTemplate can have a prototype template. The prototype template |
| 2890 | * is used to create the prototype object of the function. |
| 2891 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2892 | * The following example shows how to use a FunctionTemplate: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2893 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2894 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2895 | * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
| 2896 | * t->Set("func_property", v8::Number::New(1)); |
| 2897 | * |
| 2898 | * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); |
| 2899 | * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); |
| 2900 | * proto_t->Set("proto_const", v8::Number::New(2)); |
| 2901 | * |
| 2902 | * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); |
| 2903 | * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); |
| 2904 | * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); |
| 2905 | * instance_t->Set("instance_property", Number::New(3)); |
| 2906 | * |
| 2907 | * v8::Local<v8::Function> function = t->GetFunction(); |
| 2908 | * v8::Local<v8::Object> instance = function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2909 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | * |
| 2911 | * 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] | 2912 | * and "instance" for the instance object created above. The function |
| 2913 | * and the instance will have the following properties: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2914 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2915 | * \code |
| 2916 | * func_property in function == true; |
| 2917 | * function.func_property == 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2918 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2919 | * function.prototype.proto_method() invokes 'InvokeCallback' |
| 2920 | * function.prototype.proto_const == 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2921 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2922 | * instance instanceof function == true; |
| 2923 | * instance.instance_accessor calls 'InstanceAccessorCallback' |
| 2924 | * instance.instance_property == 3; |
| 2925 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2926 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2927 | * A FunctionTemplate can inherit from another one by calling the |
| 2928 | * FunctionTemplate::Inherit method. The following graph illustrates |
| 2929 | * the semantics of inheritance: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2930 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2931 | * \code |
| 2932 | * FunctionTemplate Parent -> Parent() . prototype -> { } |
| 2933 | * ^ ^ |
| 2934 | * | Inherit(Parent) | .__proto__ |
| 2935 | * | | |
| 2936 | * FunctionTemplate Child -> Child() . prototype -> { } |
| 2937 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2938 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2939 | * A FunctionTemplate 'Child' inherits from 'Parent', the prototype |
| 2940 | * object of the Child() function has __proto__ pointing to the |
| 2941 | * Parent() function's prototype object. An instance of the Child |
| 2942 | * function has all properties on Parent's instance templates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2944 | * Let Parent be the FunctionTemplate initialized in the previous |
| 2945 | * section and create a Child FunctionTemplate by: |
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 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | * Local<FunctionTemplate> parent = t; |
| 2949 | * Local<FunctionTemplate> child = FunctionTemplate::New(); |
| 2950 | * child->Inherit(parent); |
| 2951 | * |
| 2952 | * Local<Function> child_function = child->GetFunction(); |
| 2953 | * Local<Object> child_instance = child_function->NewInstance(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2954 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2956 | * The Child function and Child instance will have the following |
| 2957 | * properties: |
| 2958 | * |
| 2959 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2960 | * child_func.prototype.__proto__ == function.prototype; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2961 | * child_instance.instance_accessor calls 'InstanceAccessorCallback' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | * child_instance.instance_property == 3; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2963 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2965 | class V8EXPORT FunctionTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2966 | public: |
| 2967 | /** Creates a function template.*/ |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2968 | static Local<FunctionTemplate> New( |
| 2969 | InvocationCallback callback = 0, |
| 2970 | Handle<Value> data = Handle<Value>(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2971 | Handle<Signature> signature = Handle<Signature>(), |
| 2972 | int length = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2973 | /** Returns the unique function instance in the current execution context.*/ |
| 2974 | Local<Function> GetFunction(); |
| 2975 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2976 | /** |
| 2977 | * Set the call-handler callback for a FunctionTemplate. This |
| 2978 | * callback is called whenever the function created from this |
| 2979 | * FunctionTemplate is called. |
| 2980 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2981 | void SetCallHandler(InvocationCallback callback, |
| 2982 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2983 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2984 | /** Set the predefined length property for the FunctionTemplate. */ |
| 2985 | void SetLength(int length); |
| 2986 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2987 | /** Get the InstanceTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2988 | Local<ObjectTemplate> InstanceTemplate(); |
| 2989 | |
| 2990 | /** Causes the function template to inherit from a parent function template.*/ |
| 2991 | void Inherit(Handle<FunctionTemplate> parent); |
| 2992 | |
| 2993 | /** |
| 2994 | * A PrototypeTemplate is the template used to create the prototype object |
| 2995 | * of the function created by this template. |
| 2996 | */ |
| 2997 | Local<ObjectTemplate> PrototypeTemplate(); |
| 2998 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 2999 | /** |
| 3000 | * Set the class name of the FunctionTemplate. This is used for |
| 3001 | * printing objects created with the function created from the |
| 3002 | * FunctionTemplate as its constructor. |
| 3003 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3004 | void SetClassName(Handle<String> name); |
| 3005 | |
| 3006 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3007 | * Determines whether the __proto__ accessor ignores instances of |
| 3008 | * the function template. If instances of the function template are |
| 3009 | * ignored, __proto__ skips all instances and instead returns the |
| 3010 | * next object in the prototype chain. |
| 3011 | * |
| 3012 | * Call with a value of true to make the __proto__ accessor ignore |
| 3013 | * instances of the function template. Call with a value of false |
| 3014 | * to make the __proto__ accessor not ignore instances of the |
| 3015 | * function template. By default, instances of a function template |
| 3016 | * are not ignored. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3017 | */ |
| 3018 | void SetHiddenPrototype(bool value); |
| 3019 | |
| 3020 | /** |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3021 | * Sets the ReadOnly flag in the attributes of the 'prototype' property |
| 3022 | * of functions created from this FunctionTemplate to true. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3023 | */ |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3024 | void ReadOnlyPrototype(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3025 | |
| 3026 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3027 | * Returns true if the given object is an instance of this function |
| 3028 | * template. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3029 | */ |
| 3030 | bool HasInstance(Handle<Value> object); |
| 3031 | |
| 3032 | private: |
| 3033 | FunctionTemplate(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3034 | void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, |
| 3035 | NamedPropertySetter setter, |
| 3036 | NamedPropertyQuery query, |
| 3037 | NamedPropertyDeleter remover, |
| 3038 | NamedPropertyEnumerator enumerator, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3039 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3040 | void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, |
| 3041 | IndexedPropertySetter setter, |
| 3042 | IndexedPropertyQuery query, |
| 3043 | IndexedPropertyDeleter remover, |
| 3044 | IndexedPropertyEnumerator enumerator, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3045 | Handle<Value> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3046 | void SetInstanceCallAsFunctionHandler(InvocationCallback callback, |
| 3047 | Handle<Value> data); |
| 3048 | |
| 3049 | friend class Context; |
| 3050 | friend class ObjectTemplate; |
| 3051 | }; |
| 3052 | |
| 3053 | |
| 3054 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3055 | * An ObjectTemplate is used to create objects at runtime. |
| 3056 | * |
| 3057 | * Properties added to an ObjectTemplate are added to each object |
| 3058 | * created from the ObjectTemplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3059 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3060 | class V8EXPORT ObjectTemplate : public Template { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3062 | /** Creates an ObjectTemplate. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3063 | static Local<ObjectTemplate> New(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3064 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3065 | /** Creates a new instance of this template.*/ |
| 3066 | Local<Object> NewInstance(); |
| 3067 | |
| 3068 | /** |
| 3069 | * Sets an accessor on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3070 | * |
| 3071 | * Whenever the property with the given name is accessed on objects |
| 3072 | * created from this ObjectTemplate the getter and setter callbacks |
| 3073 | * are called instead of getting and setting the property directly |
| 3074 | * on the JavaScript object. |
| 3075 | * |
| 3076 | * \param name The name of the property for which an accessor is added. |
| 3077 | * \param getter The callback to invoke when getting the property. |
| 3078 | * \param setter The callback to invoke when setting the property. |
| 3079 | * \param data A piece of data that will be passed to the getter and setter |
| 3080 | * callbacks whenever they are invoked. |
| 3081 | * \param settings Access control settings for the accessor. This is a bit |
| 3082 | * field consisting of one of more of |
| 3083 | * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. |
| 3084 | * The default is to not allow cross-context access. |
| 3085 | * ALL_CAN_READ means that all cross-context reads are allowed. |
| 3086 | * ALL_CAN_WRITE means that all cross-context writes are allowed. |
| 3087 | * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all |
| 3088 | * cross-context access. |
| 3089 | * \param attribute The attributes of the property for which an accessor |
| 3090 | * is added. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3091 | * \param signature The signature describes valid receivers for the accessor |
| 3092 | * and is used to perform implicit instance checks against them. If the |
| 3093 | * receiver is incompatible (i.e. is not an instance of the constructor as |
| 3094 | * defined by FunctionTemplate::HasInstance()), an implicit TypeError is |
| 3095 | * thrown and no callback is invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | */ |
| 3097 | void SetAccessor(Handle<String> name, |
| 3098 | AccessorGetter getter, |
| 3099 | AccessorSetter setter = 0, |
| 3100 | Handle<Value> data = Handle<Value>(), |
| 3101 | AccessControl settings = DEFAULT, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3102 | PropertyAttribute attribute = None, |
| 3103 | Handle<AccessorSignature> signature = |
| 3104 | Handle<AccessorSignature>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3105 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3106 | // This function is not yet stable and should not be used at this time. |
| 3107 | bool SetAccessor(Handle<String> name, |
| 3108 | Handle<DeclaredAccessorDescriptor> descriptor, |
| 3109 | AccessControl settings = DEFAULT, |
| 3110 | PropertyAttribute attribute = None, |
| 3111 | Handle<AccessorSignature> signature = |
| 3112 | Handle<AccessorSignature>()); |
| 3113 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3114 | /** |
| 3115 | * Sets a named property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3116 | * |
| 3117 | * Whenever a named property is accessed on objects created from |
| 3118 | * this object template, the provided callback is invoked instead of |
| 3119 | * accessing the property directly on the JavaScript object. |
| 3120 | * |
| 3121 | * \param getter The callback to invoke when getting a property. |
| 3122 | * \param setter The callback to invoke when setting a property. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3123 | * \param query The callback to invoke to check if a property is present, |
| 3124 | * and if present, get its attributes. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3125 | * \param deleter The callback to invoke when deleting a property. |
| 3126 | * \param enumerator The callback to invoke to enumerate all the named |
| 3127 | * properties of an object. |
| 3128 | * \param data A piece of data that will be passed to the callbacks |
| 3129 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3130 | */ |
| 3131 | void SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 3132 | NamedPropertySetter setter = 0, |
| 3133 | NamedPropertyQuery query = 0, |
| 3134 | NamedPropertyDeleter deleter = 0, |
| 3135 | NamedPropertyEnumerator enumerator = 0, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3136 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3137 | |
| 3138 | /** |
| 3139 | * Sets an indexed property handler on the object template. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3140 | * |
| 3141 | * Whenever an indexed property is accessed on objects created from |
| 3142 | * this object template, the provided callback is invoked instead of |
| 3143 | * accessing the property directly on the JavaScript object. |
| 3144 | * |
| 3145 | * \param getter The callback to invoke when getting a property. |
| 3146 | * \param setter The callback to invoke when setting a property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3147 | * \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] | 3148 | * \param deleter The callback to invoke when deleting a property. |
| 3149 | * \param enumerator The callback to invoke to enumerate all the indexed |
| 3150 | * properties of an object. |
| 3151 | * \param data A piece of data that will be passed to the callbacks |
| 3152 | * whenever they are invoked. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3153 | */ |
| 3154 | void SetIndexedPropertyHandler(IndexedPropertyGetter getter, |
| 3155 | IndexedPropertySetter setter = 0, |
| 3156 | IndexedPropertyQuery query = 0, |
| 3157 | IndexedPropertyDeleter deleter = 0, |
| 3158 | IndexedPropertyEnumerator enumerator = 0, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3159 | Handle<Value> data = Handle<Value>()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3160 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3161 | /** |
| 3162 | * Sets the callback to be used when calling instances created from |
| 3163 | * this template as a function. If no callback is set, instances |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3164 | * behave like normal JavaScript objects that cannot be called as a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3165 | * function. |
| 3166 | */ |
| 3167 | void SetCallAsFunctionHandler(InvocationCallback callback, |
| 3168 | Handle<Value> data = Handle<Value>()); |
| 3169 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3170 | /** |
| 3171 | * Mark object instances of the template as undetectable. |
| 3172 | * |
| 3173 | * In many ways, undetectable objects behave as though they are not |
| 3174 | * there. They behave like 'undefined' in conditionals and when |
| 3175 | * printed. However, properties can be accessed and called as on |
| 3176 | * normal objects. |
| 3177 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3178 | void MarkAsUndetectable(); |
| 3179 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3180 | /** |
| 3181 | * Sets access check callbacks on the object template. |
| 3182 | * |
| 3183 | * When accessing properties on instances of this object template, |
| 3184 | * the access check callback will be called to determine whether or |
| 3185 | * not to allow cross-context access to the properties. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3186 | * The last parameter specifies whether access checks are turned |
| 3187 | * on by default on instances. If access checks are off by default, |
| 3188 | * they can be turned on on individual instances by calling |
| 3189 | * Object::TurnOnAccessCheck(). |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3190 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3191 | void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, |
| 3192 | IndexedSecurityCallback indexed_handler, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3193 | Handle<Value> data = Handle<Value>(), |
| 3194 | bool turned_on_by_default = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3195 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3196 | /** |
| 3197 | * Gets the number of internal fields for objects generated from |
| 3198 | * this template. |
| 3199 | */ |
| 3200 | int InternalFieldCount(); |
| 3201 | |
| 3202 | /** |
| 3203 | * Sets the number of internal fields for objects generated from |
| 3204 | * this template. |
| 3205 | */ |
| 3206 | void SetInternalFieldCount(int value); |
| 3207 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3208 | private: |
| 3209 | ObjectTemplate(); |
| 3210 | static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); |
| 3211 | friend class FunctionTemplate; |
| 3212 | }; |
| 3213 | |
| 3214 | |
| 3215 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3216 | * A Signature specifies which receivers and arguments are valid |
| 3217 | * parameters to a function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3218 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3219 | class V8EXPORT Signature : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3220 | public: |
| 3221 | static Local<Signature> New(Handle<FunctionTemplate> receiver = |
| 3222 | Handle<FunctionTemplate>(), |
| 3223 | int argc = 0, |
| 3224 | Handle<FunctionTemplate> argv[] = 0); |
| 3225 | private: |
| 3226 | Signature(); |
| 3227 | }; |
| 3228 | |
| 3229 | |
| 3230 | /** |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3231 | * An AccessorSignature specifies which receivers are valid parameters |
| 3232 | * to an accessor callback. |
| 3233 | */ |
| 3234 | class V8EXPORT AccessorSignature : public Data { |
| 3235 | public: |
| 3236 | static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = |
| 3237 | Handle<FunctionTemplate>()); |
| 3238 | private: |
| 3239 | AccessorSignature(); |
| 3240 | }; |
| 3241 | |
| 3242 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3243 | class V8EXPORT DeclaredAccessorDescriptor : public Data { |
| 3244 | private: |
| 3245 | DeclaredAccessorDescriptor(); |
| 3246 | }; |
| 3247 | |
| 3248 | |
| 3249 | class V8EXPORT ObjectOperationDescriptor : public Data { |
| 3250 | public: |
| 3251 | // This function is not yet stable and should not be used at this time. |
| 3252 | static Local<RawOperationDescriptor> NewInternalFieldDereference( |
| 3253 | Isolate* isolate, |
| 3254 | int internal_field); |
| 3255 | private: |
| 3256 | ObjectOperationDescriptor(); |
| 3257 | }; |
| 3258 | |
| 3259 | |
| 3260 | enum DeclaredAccessorDescriptorDataType { |
| 3261 | kDescriptorBoolType, |
| 3262 | kDescriptorInt8Type, kDescriptorUint8Type, |
| 3263 | kDescriptorInt16Type, kDescriptorUint16Type, |
| 3264 | kDescriptorInt32Type, kDescriptorUint32Type, |
| 3265 | kDescriptorFloatType, kDescriptorDoubleType |
| 3266 | }; |
| 3267 | |
| 3268 | |
| 3269 | class V8EXPORT RawOperationDescriptor : public Data { |
| 3270 | public: |
| 3271 | Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate); |
| 3272 | Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate); |
| 3273 | Local<RawOperationDescriptor> NewRawShift(Isolate* isolate, |
| 3274 | int16_t byte_offset); |
| 3275 | Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate, |
| 3276 | void* compare_value); |
| 3277 | Local<DeclaredAccessorDescriptor> NewPrimitiveValue( |
| 3278 | Isolate* isolate, |
| 3279 | DeclaredAccessorDescriptorDataType data_type, |
| 3280 | uint8_t bool_offset = 0); |
| 3281 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate, |
| 3282 | uint8_t bitmask, |
| 3283 | uint8_t compare_value); |
| 3284 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare16( |
| 3285 | Isolate* isolate, |
| 3286 | uint16_t bitmask, |
| 3287 | uint16_t compare_value); |
| 3288 | Local<DeclaredAccessorDescriptor> NewBitmaskCompare32( |
| 3289 | Isolate* isolate, |
| 3290 | uint32_t bitmask, |
| 3291 | uint32_t compare_value); |
| 3292 | |
| 3293 | private: |
| 3294 | RawOperationDescriptor(); |
| 3295 | }; |
| 3296 | |
| 3297 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3298 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3299 | * A utility for determining the type of objects based on the template |
| 3300 | * they were constructed from. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3301 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3302 | class V8EXPORT TypeSwitch : public Data { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3303 | public: |
| 3304 | static Local<TypeSwitch> New(Handle<FunctionTemplate> type); |
| 3305 | static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); |
| 3306 | int match(Handle<Value> value); |
| 3307 | private: |
| 3308 | TypeSwitch(); |
| 3309 | }; |
| 3310 | |
| 3311 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3312 | // --- Extensions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3313 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3314 | class V8EXPORT ExternalAsciiStringResourceImpl |
| 3315 | : public String::ExternalAsciiStringResource { |
| 3316 | public: |
| 3317 | ExternalAsciiStringResourceImpl() : data_(0), length_(0) {} |
| 3318 | ExternalAsciiStringResourceImpl(const char* data, size_t length) |
| 3319 | : data_(data), length_(length) {} |
| 3320 | const char* data() const { return data_; } |
| 3321 | size_t length() const { return length_; } |
| 3322 | |
| 3323 | private: |
| 3324 | const char* data_; |
| 3325 | size_t length_; |
| 3326 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3327 | |
| 3328 | /** |
| 3329 | * Ignore |
| 3330 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3331 | class V8EXPORT Extension { // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3332 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3333 | // Note that the strings passed into this constructor must live as long |
| 3334 | // as the Extension itself. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3335 | Extension(const char* name, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3336 | const char* source = 0, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3337 | int dep_count = 0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3338 | const char** deps = 0, |
| 3339 | int source_length = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3340 | virtual ~Extension() { } |
| 3341 | virtual v8::Handle<v8::FunctionTemplate> |
| 3342 | GetNativeFunction(v8::Handle<v8::String> name) { |
| 3343 | return v8::Handle<v8::FunctionTemplate>(); |
| 3344 | } |
| 3345 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3346 | const char* name() const { return name_; } |
| 3347 | size_t source_length() const { return source_length_; } |
| 3348 | const String::ExternalAsciiStringResource* source() const { |
| 3349 | return &source_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3350 | int dependency_count() { return dep_count_; } |
| 3351 | const char** dependencies() { return deps_; } |
| 3352 | void set_auto_enable(bool value) { auto_enable_ = value; } |
| 3353 | bool auto_enable() { return auto_enable_; } |
| 3354 | |
| 3355 | private: |
| 3356 | const char* name_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3357 | size_t source_length_; // expected to initialize before source_ |
| 3358 | ExternalAsciiStringResourceImpl source_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3359 | int dep_count_; |
| 3360 | const char** deps_; |
| 3361 | bool auto_enable_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3362 | |
| 3363 | // Disallow copying and assigning. |
| 3364 | Extension(const Extension&); |
| 3365 | void operator=(const Extension&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3366 | }; |
| 3367 | |
| 3368 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3369 | void V8EXPORT RegisterExtension(Extension* extension); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3370 | |
| 3371 | |
| 3372 | /** |
| 3373 | * Ignore |
| 3374 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3375 | class V8EXPORT DeclareExtension { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3376 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3377 | V8_INLINE(DeclareExtension(Extension* extension)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3378 | RegisterExtension(extension); |
| 3379 | } |
| 3380 | }; |
| 3381 | |
| 3382 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3383 | // --- Statics --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3384 | |
| 3385 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3386 | Handle<Primitive> V8EXPORT Undefined(); |
| 3387 | Handle<Primitive> V8EXPORT Null(); |
| 3388 | Handle<Boolean> V8EXPORT True(); |
| 3389 | Handle<Boolean> V8EXPORT False(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3390 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3391 | V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate)); |
| 3392 | V8_INLINE(Handle<Primitive> Null(Isolate* isolate)); |
| 3393 | V8_INLINE(Handle<Boolean> True(Isolate* isolate)); |
| 3394 | V8_INLINE(Handle<Boolean> False(Isolate* isolate)); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3395 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3396 | |
| 3397 | /** |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3398 | * A set of constraints that specifies the limits of the runtime's memory use. |
| 3399 | * You must set the heap size before initializing the VM - the size cannot be |
| 3400 | * adjusted after the VM is initialized. |
| 3401 | * |
| 3402 | * If you are using threads then you should hold the V8::Locker lock while |
| 3403 | * setting the stack limit and you must set a non-default stack limit separately |
| 3404 | * for each thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3405 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3406 | class V8EXPORT ResourceConstraints { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3407 | public: |
| 3408 | ResourceConstraints(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3409 | int max_young_space_size() const { return max_young_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3410 | 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] | 3411 | int max_old_space_size() const { return max_old_space_size_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3412 | 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] | 3413 | int max_executable_size() { return max_executable_size_; } |
| 3414 | void set_max_executable_size(int value) { max_executable_size_ = value; } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3415 | uint32_t* stack_limit() const { return stack_limit_; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3416 | // 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] | 3417 | void set_stack_limit(uint32_t* value) { stack_limit_ = value; } |
| 3418 | private: |
| 3419 | int max_young_space_size_; |
| 3420 | int max_old_space_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3421 | int max_executable_size_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3422 | uint32_t* stack_limit_; |
| 3423 | }; |
| 3424 | |
| 3425 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3426 | bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3427 | |
| 3428 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3429 | // --- Exceptions --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3430 | |
| 3431 | |
| 3432 | typedef void (*FatalErrorCallback)(const char* location, const char* message); |
| 3433 | |
| 3434 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3435 | typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3436 | |
| 3437 | |
| 3438 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3439 | * Schedules an exception to be thrown when returning to JavaScript. When an |
| 3440 | * exception has been scheduled it is illegal to invoke any JavaScript |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3441 | * operation; the caller must return immediately and only after the exception |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3442 | * has been handled does it become legal to invoke JavaScript operations. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3443 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3444 | Handle<Value> V8EXPORT ThrowException(Handle<Value> exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3445 | |
| 3446 | /** |
| 3447 | * Create new error objects by calling the corresponding error object |
| 3448 | * constructor with the message. |
| 3449 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3450 | class V8EXPORT Exception { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3451 | public: |
| 3452 | static Local<Value> RangeError(Handle<String> message); |
| 3453 | static Local<Value> ReferenceError(Handle<String> message); |
| 3454 | static Local<Value> SyntaxError(Handle<String> message); |
| 3455 | static Local<Value> TypeError(Handle<String> message); |
| 3456 | static Local<Value> Error(Handle<String> message); |
| 3457 | }; |
| 3458 | |
| 3459 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3460 | // --- Counters Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3461 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3462 | typedef int* (*CounterLookupCallback)(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3463 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3464 | typedef void* (*CreateHistogramCallback)(const char* name, |
| 3465 | int min, |
| 3466 | int max, |
| 3467 | size_t buckets); |
| 3468 | |
| 3469 | typedef void (*AddHistogramSampleCallback)(void* histogram, int sample); |
| 3470 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3471 | // --- Memory Allocation Callback --- |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3472 | enum ObjectSpace { |
| 3473 | kObjectSpaceNewSpace = 1 << 0, |
| 3474 | kObjectSpaceOldPointerSpace = 1 << 1, |
| 3475 | kObjectSpaceOldDataSpace = 1 << 2, |
| 3476 | kObjectSpaceCodeSpace = 1 << 3, |
| 3477 | kObjectSpaceMapSpace = 1 << 4, |
| 3478 | kObjectSpaceLoSpace = 1 << 5, |
| 3479 | |
| 3480 | kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace | |
| 3481 | kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace | |
| 3482 | kObjectSpaceLoSpace |
| 3483 | }; |
| 3484 | |
| 3485 | enum AllocationAction { |
| 3486 | kAllocationActionAllocate = 1 << 0, |
| 3487 | kAllocationActionFree = 1 << 1, |
| 3488 | kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree |
| 3489 | }; |
| 3490 | |
| 3491 | typedef void (*MemoryAllocationCallback)(ObjectSpace space, |
| 3492 | AllocationAction action, |
| 3493 | int size); |
| 3494 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3495 | // --- Leave Script Callback --- |
| 3496 | typedef void (*CallCompletedCallback)(); |
| 3497 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3498 | // --- Failed Access Check Callback --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3499 | typedef void (*FailedAccessCheckCallback)(Local<Object> target, |
| 3500 | AccessType type, |
| 3501 | Local<Value> data); |
| 3502 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3503 | // --- AllowCodeGenerationFromStrings callbacks --- |
| 3504 | |
| 3505 | /** |
| 3506 | * Callback to check if code generation from strings is allowed. See |
| 3507 | * Context::AllowCodeGenerationFromStrings. |
| 3508 | */ |
| 3509 | typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context); |
| 3510 | |
| 3511 | // --- Garbage Collection Callbacks --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3512 | |
| 3513 | /** |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3514 | * Applications can register callback functions which will be called |
| 3515 | * before and after a garbage collection. Allocations are not |
| 3516 | * allowed in the callback functions, you therefore cannot manipulate |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3517 | * objects (set or delete properties for example) since it is possible |
| 3518 | * such operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3519 | */ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3520 | enum GCType { |
| 3521 | kGCTypeScavenge = 1 << 0, |
| 3522 | kGCTypeMarkSweepCompact = 1 << 1, |
| 3523 | kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
| 3524 | }; |
| 3525 | |
| 3526 | enum GCCallbackFlags { |
| 3527 | kNoGCCallbackFlags = 0, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3528 | kGCCallbackFlagCompacted = 1 << 0, |
| 3529 | kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3530 | }; |
| 3531 | |
| 3532 | typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); |
| 3533 | typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); |
| 3534 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3535 | typedef void (*GCCallback)(); |
| 3536 | |
| 3537 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3538 | /** |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3539 | * Collection of V8 heap information. |
| 3540 | * |
| 3541 | * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 3542 | * get heap statistics from V8. |
| 3543 | */ |
| 3544 | class V8EXPORT HeapStatistics { |
| 3545 | public: |
| 3546 | HeapStatistics(); |
| 3547 | size_t total_heap_size() { return total_heap_size_; } |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3548 | size_t total_heap_size_executable() { return total_heap_size_executable_; } |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3549 | size_t total_physical_size() { return total_physical_size_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3550 | size_t used_heap_size() { return used_heap_size_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3551 | size_t heap_size_limit() { return heap_size_limit_; } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3552 | |
| 3553 | private: |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3554 | size_t total_heap_size_; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3555 | size_t total_heap_size_executable_; |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3556 | size_t total_physical_size_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3557 | size_t used_heap_size_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3558 | size_t heap_size_limit_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3559 | |
| 3560 | friend class V8; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3561 | friend class Isolate; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3562 | }; |
| 3563 | |
| 3564 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3565 | class RetainedObjectInfo; |
| 3566 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3567 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3568 | * Isolate represents an isolated instance of the V8 engine. V8 |
| 3569 | * isolates have completely separate states. Objects from one isolate |
| 3570 | * must not be used in other isolates. When V8 is initialized a |
| 3571 | * default isolate is implicitly created and entered. The embedder |
| 3572 | * can create additional isolates and use them in parallel in multiple |
| 3573 | * 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] | 3574 | * given time. The Locker/Unlocker API must be used to synchronize. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3575 | */ |
| 3576 | class V8EXPORT Isolate { |
| 3577 | public: |
| 3578 | /** |
| 3579 | * Stack-allocated class which sets the isolate for all operations |
| 3580 | * executed within a local scope. |
| 3581 | */ |
| 3582 | class V8EXPORT Scope { |
| 3583 | public: |
| 3584 | explicit Scope(Isolate* isolate) : isolate_(isolate) { |
| 3585 | isolate->Enter(); |
| 3586 | } |
| 3587 | |
| 3588 | ~Scope() { isolate_->Exit(); } |
| 3589 | |
| 3590 | private: |
| 3591 | Isolate* const isolate_; |
| 3592 | |
| 3593 | // Prevent copying of Scope objects. |
| 3594 | Scope(const Scope&); |
| 3595 | Scope& operator=(const Scope&); |
| 3596 | }; |
| 3597 | |
| 3598 | /** |
| 3599 | * Creates a new isolate. Does not change the currently entered |
| 3600 | * isolate. |
| 3601 | * |
| 3602 | * When an isolate is no longer used its resources should be freed |
| 3603 | * by calling Dispose(). Using the delete operator is not allowed. |
| 3604 | */ |
| 3605 | static Isolate* New(); |
| 3606 | |
| 3607 | /** |
| 3608 | * Returns the entered isolate for the current thread or NULL in |
| 3609 | * case there is no current isolate. |
| 3610 | */ |
| 3611 | static Isolate* GetCurrent(); |
| 3612 | |
| 3613 | /** |
| 3614 | * Methods below this point require holding a lock (using Locker) in |
| 3615 | * a multi-threaded environment. |
| 3616 | */ |
| 3617 | |
| 3618 | /** |
| 3619 | * Sets this isolate as the entered one for the current thread. |
| 3620 | * Saves the previously entered one (if any), so that it can be |
| 3621 | * restored when exiting. Re-entering an isolate is allowed. |
| 3622 | */ |
| 3623 | void Enter(); |
| 3624 | |
| 3625 | /** |
| 3626 | * Exits this isolate by restoring the previously entered one in the |
| 3627 | * current thread. The isolate may still stay the same, if it was |
| 3628 | * entered more than once. |
| 3629 | * |
| 3630 | * Requires: this == Isolate::GetCurrent(). |
| 3631 | */ |
| 3632 | void Exit(); |
| 3633 | |
| 3634 | /** |
| 3635 | * Disposes the isolate. The isolate must not be entered by any |
| 3636 | * thread to be disposable. |
| 3637 | */ |
| 3638 | void Dispose(); |
| 3639 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3640 | /** |
| 3641 | * Associate embedder-specific data with the isolate |
| 3642 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3643 | V8_INLINE(void SetData(void* data)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3644 | |
| 3645 | /** |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3646 | * Retrieve embedder-specific data from the isolate. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3647 | * Returns NULL if SetData has never been called. |
| 3648 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3649 | V8_INLINE(void* GetData()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3650 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3651 | /** |
| 3652 | * Get statistics about the heap memory usage. |
| 3653 | */ |
| 3654 | void GetHeapStatistics(HeapStatistics* heap_statistics); |
| 3655 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3656 | /** |
| 3657 | * Adjusts the amount of registered external memory. Used to give V8 an |
| 3658 | * indication of the amount of externally allocated memory that is kept alive |
| 3659 | * by JavaScript objects. V8 uses this to decide when to perform global |
| 3660 | * garbage collections. Registering externally allocated memory will trigger |
| 3661 | * global garbage collections more often than it would otherwise in an attempt |
| 3662 | * to garbage collect the JavaScript objects that keep the externally |
| 3663 | * allocated memory alive. |
| 3664 | * |
| 3665 | * \param change_in_bytes the change in externally allocated memory that is |
| 3666 | * kept alive by JavaScript objects. |
| 3667 | * \returns the adjusted value. |
| 3668 | */ |
| 3669 | intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); |
| 3670 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3671 | /** |
| 3672 | * Returns heap profiler for this isolate. Will return NULL until the isolate |
| 3673 | * is initialized. |
| 3674 | */ |
| 3675 | HeapProfiler* GetHeapProfiler(); |
| 3676 | |
| 3677 | /** |
| 3678 | * Returns CPU profiler for this isolate. Will return NULL until the isolate |
| 3679 | * is initialized. |
| 3680 | */ |
| 3681 | CpuProfiler* GetCpuProfiler(); |
| 3682 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 3683 | /** Returns the context that is on the top of the stack. */ |
| 3684 | Local<Context> GetCurrentContext(); |
| 3685 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3686 | /** |
| 3687 | * Allows the host application to group objects together. If one |
| 3688 | * object in the group is alive, all objects in the group are alive. |
| 3689 | * After each garbage collection, object groups are removed. It is |
| 3690 | * intended to be used in the before-garbage-collection callback |
| 3691 | * function, for instance to simulate DOM tree connections among JS |
| 3692 | * wrapper objects. Object groups for all dependent handles need to |
| 3693 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 3694 | * garbage collection types it is sufficient to provide object groups |
| 3695 | * for partially dependent handles only. |
| 3696 | */ |
| 3697 | void SetObjectGroupId(const Persistent<Value>& object, |
| 3698 | UniqueId id); |
| 3699 | |
| 3700 | /** |
| 3701 | * Allows the host application to declare implicit references from an object |
| 3702 | * group to an object. If the objects of the object group are alive, the child |
| 3703 | * object is alive too. After each garbage collection, all implicit references |
| 3704 | * are removed. It is intended to be used in the before-garbage-collection |
| 3705 | * callback function. |
| 3706 | */ |
| 3707 | void SetReferenceFromGroup(UniqueId id, |
| 3708 | const Persistent<Value>& child); |
| 3709 | |
| 3710 | /** |
| 3711 | * Allows the host application to declare implicit references from an object |
| 3712 | * to another object. If the parent object is alive, the child object is alive |
| 3713 | * too. After each garbage collection, all implicit references are removed. It |
| 3714 | * is intended to be used in the before-garbage-collection callback function. |
| 3715 | */ |
| 3716 | void SetReference(const Persistent<Object>& parent, |
| 3717 | const Persistent<Value>& child); |
| 3718 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3719 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3720 | Isolate(); |
| 3721 | Isolate(const Isolate&); |
| 3722 | ~Isolate(); |
| 3723 | Isolate& operator=(const Isolate&); |
| 3724 | void* operator new(size_t size); |
| 3725 | void operator delete(void*, size_t); |
| 3726 | }; |
| 3727 | |
| 3728 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3729 | class V8EXPORT StartupData { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3730 | public: |
| 3731 | enum CompressionAlgorithm { |
| 3732 | kUncompressed, |
| 3733 | kBZip2 |
| 3734 | }; |
| 3735 | |
| 3736 | const char* data; |
| 3737 | int compressed_size; |
| 3738 | int raw_size; |
| 3739 | }; |
| 3740 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3741 | |
| 3742 | /** |
| 3743 | * A helper class for driving V8 startup data decompression. It is based on |
| 3744 | * "CompressedStartupData" API functions from the V8 class. It isn't mandatory |
| 3745 | * for an embedder to use this class, instead, API functions can be used |
| 3746 | * directly. |
| 3747 | * |
| 3748 | * For an example of the class usage, see the "shell.cc" sample application. |
| 3749 | */ |
| 3750 | class V8EXPORT StartupDataDecompressor { // NOLINT |
| 3751 | public: |
| 3752 | StartupDataDecompressor(); |
| 3753 | virtual ~StartupDataDecompressor(); |
| 3754 | int Decompress(); |
| 3755 | |
| 3756 | protected: |
| 3757 | virtual int DecompressData(char* raw_data, |
| 3758 | int* raw_data_size, |
| 3759 | const char* compressed_data, |
| 3760 | int compressed_data_size) = 0; |
| 3761 | |
| 3762 | private: |
| 3763 | char** raw_data; |
| 3764 | }; |
| 3765 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3766 | |
| 3767 | /** |
| 3768 | * EntropySource is used as a callback function when v8 needs a source |
| 3769 | * of entropy. |
| 3770 | */ |
| 3771 | typedef bool (*EntropySource)(unsigned char* buffer, size_t length); |
| 3772 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3773 | |
| 3774 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3775 | * ReturnAddressLocationResolver is used as a callback function when v8 is |
| 3776 | * resolving the location of a return address on the stack. Profilers that |
| 3777 | * change the return address on the stack can use this to resolve the stack |
| 3778 | * location to whereever the profiler stashed the original return address. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3779 | * |
| 3780 | * \param return_addr_location points to a location on stack where a machine |
| 3781 | * return address resides. |
| 3782 | * \returns either return_addr_location, or else a pointer to the profiler's |
| 3783 | * copy of the original return address. |
| 3784 | * |
| 3785 | * \note the resolver function must not cause garbage collection. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3786 | */ |
| 3787 | typedef uintptr_t (*ReturnAddressLocationResolver)( |
| 3788 | uintptr_t return_addr_location); |
| 3789 | |
| 3790 | |
| 3791 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3792 | * FunctionEntryHook is the type of the profile entry hook called at entry to |
| 3793 | * any generated function when function-level profiling is enabled. |
| 3794 | * |
| 3795 | * \param function the address of the function that's being entered. |
| 3796 | * \param return_addr_location points to a location on stack where the machine |
| 3797 | * return address resides. This can be used to identify the caller of |
| 3798 | * \p function, and/or modified to divert execution when \p function exits. |
| 3799 | * |
| 3800 | * \note the entry hook must not cause garbage collection. |
| 3801 | */ |
| 3802 | typedef void (*FunctionEntryHook)(uintptr_t function, |
| 3803 | uintptr_t return_addr_location); |
| 3804 | |
| 3805 | |
| 3806 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3807 | * A JIT code event is issued each time code is added, moved or removed. |
| 3808 | * |
| 3809 | * \note removal events are not currently issued. |
| 3810 | */ |
| 3811 | struct JitCodeEvent { |
| 3812 | enum EventType { |
| 3813 | CODE_ADDED, |
| 3814 | CODE_MOVED, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3815 | CODE_REMOVED, |
| 3816 | CODE_ADD_LINE_POS_INFO, |
| 3817 | CODE_START_LINE_INFO_RECORDING, |
| 3818 | CODE_END_LINE_INFO_RECORDING |
| 3819 | }; |
| 3820 | // Definition of the code position type. The "POSITION" type means the place |
| 3821 | // in the source code which are of interest when making stack traces to |
| 3822 | // pin-point the source location of a stack frame as close as possible. |
| 3823 | // The "STATEMENT_POSITION" means the place at the beginning of each |
| 3824 | // statement, and is used to indicate possible break locations. |
| 3825 | enum PositionType { |
| 3826 | POSITION, |
| 3827 | STATEMENT_POSITION |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3828 | }; |
| 3829 | |
| 3830 | // Type of event. |
| 3831 | EventType type; |
| 3832 | // Start of the instructions. |
| 3833 | void* code_start; |
| 3834 | // Size of the instructions. |
| 3835 | size_t code_len; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3836 | // Script info for CODE_ADDED event. |
| 3837 | Handle<Script> script; |
| 3838 | // User-defined data for *_LINE_INFO_* event. It's used to hold the source |
| 3839 | // code line information which is returned from the |
| 3840 | // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent |
| 3841 | // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events. |
| 3842 | void* user_data; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3843 | |
| 3844 | union { |
| 3845 | // Only valid for CODE_ADDED. |
| 3846 | struct { |
| 3847 | // Name of the object associated with the code, note that the string is |
| 3848 | // not zero-terminated. |
| 3849 | const char* str; |
| 3850 | // Number of chars in str. |
| 3851 | size_t len; |
| 3852 | } name; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3853 | |
| 3854 | // Only valid for CODE_ADD_LINE_POS_INFO |
| 3855 | struct { |
| 3856 | // PC offset |
| 3857 | size_t offset; |
| 3858 | // Code postion |
| 3859 | size_t pos; |
| 3860 | // The position type. |
| 3861 | PositionType position_type; |
| 3862 | } line_info; |
| 3863 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3864 | // New location of instructions. Only valid for CODE_MOVED. |
| 3865 | void* new_code_start; |
| 3866 | }; |
| 3867 | }; |
| 3868 | |
| 3869 | /** |
| 3870 | * Option flags passed to the SetJitCodeEventHandler function. |
| 3871 | */ |
| 3872 | enum JitCodeEventOptions { |
| 3873 | kJitCodeEventDefault = 0, |
| 3874 | // Generate callbacks for already existent code. |
| 3875 | kJitCodeEventEnumExisting = 1 |
| 3876 | }; |
| 3877 | |
| 3878 | |
| 3879 | /** |
| 3880 | * Callback function passed to SetJitCodeEventHandler. |
| 3881 | * |
| 3882 | * \param event code add, move or removal event. |
| 3883 | */ |
| 3884 | typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); |
| 3885 | |
| 3886 | |
| 3887 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3888 | * Interface for iterating through all external resources in the heap. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3889 | */ |
| 3890 | class V8EXPORT ExternalResourceVisitor { // NOLINT |
| 3891 | public: |
| 3892 | virtual ~ExternalResourceVisitor() {} |
| 3893 | virtual void VisitExternalString(Handle<String> string) {} |
| 3894 | }; |
| 3895 | |
| 3896 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3897 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3898 | * Interface for iterating through all the persistent handles in the heap. |
| 3899 | */ |
| 3900 | class V8EXPORT PersistentHandleVisitor { // NOLINT |
| 3901 | public: |
| 3902 | virtual ~PersistentHandleVisitor() {} |
| 3903 | virtual void VisitPersistentHandle(Persistent<Value> value, |
| 3904 | uint16_t class_id) {} |
| 3905 | }; |
| 3906 | |
| 3907 | |
| 3908 | /** |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3909 | * Asserts that no action is performed that could cause a handle's value |
| 3910 | * to be modified. Useful when otherwise unsafe handle operations need to |
| 3911 | * be performed. |
| 3912 | */ |
| 3913 | class V8EXPORT AssertNoGCScope { |
| 3914 | #ifndef DEBUG |
| 3915 | V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} |
| 3916 | #else |
| 3917 | AssertNoGCScope(Isolate* isolate); |
| 3918 | ~AssertNoGCScope(); |
| 3919 | private: |
| 3920 | Isolate* isolate_; |
| 3921 | bool last_state_; |
| 3922 | #endif |
| 3923 | }; |
| 3924 | |
| 3925 | |
| 3926 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3927 | * Container class for static utility functions. |
| 3928 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3929 | class V8EXPORT V8 { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3930 | public: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3931 | /** Set the callback to invoke in case of fatal errors. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3932 | static void SetFatalErrorHandler(FatalErrorCallback that); |
| 3933 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3934 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3935 | * Set the callback to invoke to check if code generation from |
| 3936 | * strings should be allowed. |
| 3937 | */ |
| 3938 | static void SetAllowCodeGenerationFromStringsCallback( |
| 3939 | AllowCodeGenerationFromStringsCallback that); |
| 3940 | |
| 3941 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3942 | * Ignore out-of-memory exceptions. |
| 3943 | * |
| 3944 | * V8 running out of memory is treated as a fatal error by default. |
| 3945 | * This means that the fatal error handler is called and that V8 is |
| 3946 | * terminated. |
| 3947 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3948 | * IgnoreOutOfMemoryException can be used to not treat an |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3949 | * out-of-memory situation as a fatal error. This way, the contexts |
| 3950 | * that did not cause the out of memory problem might be able to |
| 3951 | * continue execution. |
| 3952 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3953 | static void IgnoreOutOfMemoryException(); |
| 3954 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3955 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3956 | * 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] | 3957 | * fatal errors such as out-of-memory situations. |
| 3958 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3959 | static bool IsDead(); |
| 3960 | |
| 3961 | /** |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3962 | * The following 4 functions are to be used when V8 is built with |
| 3963 | * the 'compress_startup_data' flag enabled. In this case, the |
| 3964 | * embedder must decompress startup data prior to initializing V8. |
| 3965 | * |
| 3966 | * This is how interaction with V8 should look like: |
| 3967 | * int compressed_data_count = v8::V8::GetCompressedStartupDataCount(); |
| 3968 | * v8::StartupData* compressed_data = |
| 3969 | * new v8::StartupData[compressed_data_count]; |
| 3970 | * v8::V8::GetCompressedStartupData(compressed_data); |
| 3971 | * ... decompress data (compressed_data can be updated in-place) ... |
| 3972 | * v8::V8::SetDecompressedStartupData(compressed_data); |
| 3973 | * ... now V8 can be initialized |
| 3974 | * ... make sure the decompressed data stays valid until V8 shutdown |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3975 | * |
| 3976 | * A helper class StartupDataDecompressor is provided. It implements |
| 3977 | * the protocol of the interaction described above, and can be used in |
| 3978 | * most cases instead of calling these API functions directly. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3979 | */ |
| 3980 | static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm(); |
| 3981 | static int GetCompressedStartupDataCount(); |
| 3982 | static void GetCompressedStartupData(StartupData* compressed_data); |
| 3983 | static void SetDecompressedStartupData(StartupData* decompressed_data); |
| 3984 | |
| 3985 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3986 | * Adds a message listener. |
| 3987 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3988 | * 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] | 3989 | * case it will be called more than once for each message. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3990 | * |
| 3991 | * If data is specified, it will be passed to the callback when it is called. |
| 3992 | * Otherwise, the exception object will be passed to the callback instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3993 | */ |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3994 | static bool AddMessageListener(MessageCallback that, |
| 3995 | Handle<Value> data = Handle<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3996 | |
| 3997 | /** |
| 3998 | * Remove all message listeners from the specified callback function. |
| 3999 | */ |
| 4000 | static void RemoveMessageListeners(MessageCallback that); |
| 4001 | |
| 4002 | /** |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4003 | * Tells V8 to capture current stack trace when uncaught exception occurs |
| 4004 | * and report it to the message listeners. The option is off by default. |
| 4005 | */ |
| 4006 | static void SetCaptureStackTraceForUncaughtExceptions( |
| 4007 | bool capture, |
| 4008 | int frame_limit = 10, |
| 4009 | StackTrace::StackTraceOptions options = StackTrace::kOverview); |
| 4010 | |
| 4011 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4012 | * Sets V8 flags from a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4013 | */ |
| 4014 | static void SetFlagsFromString(const char* str, int length); |
| 4015 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4016 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4017 | * Sets V8 flags from the command line. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4018 | */ |
| 4019 | static void SetFlagsFromCommandLine(int* argc, |
| 4020 | char** argv, |
| 4021 | bool remove_flags); |
| 4022 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4023 | /** Get the version string. */ |
| 4024 | static const char* GetVersion(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4025 | |
| 4026 | /** |
| 4027 | * Enables the host application to provide a mechanism for recording |
| 4028 | * statistics counters. |
| 4029 | */ |
| 4030 | static void SetCounterFunction(CounterLookupCallback); |
| 4031 | |
| 4032 | /** |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4033 | * Enables the host application to provide a mechanism for recording |
| 4034 | * histograms. The CreateHistogram function returns a |
| 4035 | * histogram which will later be passed to the AddHistogramSample |
| 4036 | * function. |
| 4037 | */ |
| 4038 | static void SetCreateHistogramFunction(CreateHistogramCallback); |
| 4039 | static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); |
| 4040 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4041 | /** Callback function for reporting failed access checks.*/ |
| 4042 | static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); |
| 4043 | |
| 4044 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4045 | * Enables the host application to receive a notification before a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4046 | * garbage collection. Allocations are not allowed in the |
| 4047 | * callback function, you therefore cannot manipulate objects (set |
| 4048 | * or delete properties for example) since it is possible such |
| 4049 | * operations will result in the allocation of objects. It is possible |
| 4050 | * to specify the GCType filter for your callback. But it is not possible to |
| 4051 | * register the same callback function two times with different |
| 4052 | * GCType filters. |
| 4053 | */ |
| 4054 | static void AddGCPrologueCallback( |
| 4055 | GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4056 | |
| 4057 | /** |
| 4058 | * This function removes callback which was installed by |
| 4059 | * AddGCPrologueCallback function. |
| 4060 | */ |
| 4061 | static void RemoveGCPrologueCallback(GCPrologueCallback callback); |
| 4062 | |
| 4063 | /** |
| 4064 | * The function is deprecated. Please use AddGCPrologueCallback instead. |
| 4065 | * Enables the host application to receive a notification before a |
| 4066 | * garbage collection. Allocations are not allowed in the |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4067 | * callback function, you therefore cannot manipulate objects (set |
| 4068 | * or delete properties for example) since it is possible such |
| 4069 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4070 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4071 | V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4072 | |
| 4073 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4074 | * Enables the host application to receive a notification after a |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4075 | * garbage collection. Allocations are not allowed in the |
| 4076 | * callback function, you therefore cannot manipulate objects (set |
| 4077 | * or delete properties for example) since it is possible such |
| 4078 | * operations will result in the allocation of objects. It is possible |
| 4079 | * to specify the GCType filter for your callback. But it is not possible to |
| 4080 | * register the same callback function two times with different |
| 4081 | * GCType filters. |
| 4082 | */ |
| 4083 | static void AddGCEpilogueCallback( |
| 4084 | GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); |
| 4085 | |
| 4086 | /** |
| 4087 | * This function removes callback which was installed by |
| 4088 | * AddGCEpilogueCallback function. |
| 4089 | */ |
| 4090 | static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); |
| 4091 | |
| 4092 | /** |
| 4093 | * The function is deprecated. Please use AddGCEpilogueCallback instead. |
| 4094 | * Enables the host application to receive a notification after a |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4095 | * major garbage collection. Allocations are not allowed in the |
| 4096 | * callback function, you therefore cannot manipulate objects (set |
| 4097 | * or delete properties for example) since it is possible such |
| 4098 | * operations will result in the allocation of objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4099 | */ |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4100 | V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4101 | |
| 4102 | /** |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4103 | * Enables the host application to provide a mechanism to be notified |
| 4104 | * and perform custom logging when V8 Allocates Executable Memory. |
| 4105 | */ |
| 4106 | static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4107 | ObjectSpace space, |
| 4108 | AllocationAction action); |
| 4109 | |
| 4110 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4111 | * Removes callback that was installed by AddMemoryAllocationCallback. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4112 | */ |
| 4113 | static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
| 4114 | |
| 4115 | /** |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4116 | * Adds a callback to notify the host application when a script finished |
| 4117 | * running. If a script re-enters the runtime during executing, the |
| 4118 | * CallCompletedCallback is only invoked when the outer-most script |
| 4119 | * execution ends. Executing scripts inside the callback do not trigger |
| 4120 | * further callbacks. |
| 4121 | */ |
| 4122 | static void AddCallCompletedCallback(CallCompletedCallback callback); |
| 4123 | |
| 4124 | /** |
| 4125 | * Removes callback that was installed by AddCallCompletedCallback. |
| 4126 | */ |
| 4127 | static void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 4128 | |
| 4129 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4130 | * Allows the host application to group objects together. If one |
| 4131 | * object in the group is alive, all objects in the group are alive. |
| 4132 | * After each garbage collection, object groups are removed. It is |
| 4133 | * intended to be used in the before-garbage-collection callback |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4134 | * function, for instance to simulate DOM tree connections among JS |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4135 | * wrapper objects. Object groups for all dependent handles need to |
| 4136 | * be provided for kGCTypeMarkSweepCompact collections, for all other |
| 4137 | * garbage collection types it is sufficient to provide object groups |
| 4138 | * for partially dependent handles only. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4139 | * See v8-profiler.h for RetainedObjectInfo interface description. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4140 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4141 | // TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId and |
| 4142 | // HeapProfiler::SetRetainedObjectInfo instead. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4143 | static void AddObjectGroup(Persistent<Value>* objects, |
| 4144 | size_t length, |
| 4145 | RetainedObjectInfo* info = NULL); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4146 | static void AddObjectGroup(Isolate* isolate, |
| 4147 | Persistent<Value>* objects, |
| 4148 | size_t length, |
| 4149 | RetainedObjectInfo* info = NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4150 | |
| 4151 | /** |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4152 | * Allows the host application to declare implicit references between |
| 4153 | * the objects: if |parent| is alive, all |children| are alive too. |
| 4154 | * After each garbage collection, all implicit references |
| 4155 | * are removed. It is intended to be used in the before-garbage-collection |
| 4156 | * callback function. |
| 4157 | */ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4158 | // TODO(marja): Deprecate AddImplicitReferences. Use |
| 4159 | // Isolate::SetReferenceFromGroup instead. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4160 | static void AddImplicitReferences(Persistent<Object> parent, |
| 4161 | Persistent<Value>* children, |
| 4162 | size_t length); |
| 4163 | |
| 4164 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4165 | * Initializes from snapshot if possible. Otherwise, attempts to |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4166 | * initialize from scratch. This function is called implicitly if |
| 4167 | * you use the API without calling it first. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4168 | */ |
| 4169 | static bool Initialize(); |
| 4170 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4171 | /** |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4172 | * Allows the host application to provide a callback which can be used |
| 4173 | * as a source of entropy for random number generators. |
| 4174 | */ |
| 4175 | static void SetEntropySource(EntropySource source); |
| 4176 | |
| 4177 | /** |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4178 | * Allows the host application to provide a callback that allows v8 to |
| 4179 | * cooperate with a profiler that rewrites return addresses on stack. |
| 4180 | */ |
| 4181 | static void SetReturnAddressLocationResolver( |
| 4182 | ReturnAddressLocationResolver return_address_resolver); |
| 4183 | |
| 4184 | /** |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4185 | * Allows the host application to provide the address of a function that's |
| 4186 | * invoked on entry to every V8-generated function. |
| 4187 | * Note that \p entry_hook is invoked at the very start of each |
| 4188 | * generated function. |
| 4189 | * |
| 4190 | * \param entry_hook a function that will be invoked on entry to every |
| 4191 | * V8-generated function. |
| 4192 | * \returns true on success on supported platforms, false on failure. |
| 4193 | * \note Setting a new entry hook function when one is already active will |
| 4194 | * fail. |
| 4195 | */ |
| 4196 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 4197 | |
| 4198 | /** |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4199 | * Allows the host application to provide the address of a function that is |
| 4200 | * notified each time code is added, moved or removed. |
| 4201 | * |
| 4202 | * \param options options for the JIT code event handler. |
| 4203 | * \param event_handler the JIT code event handler, which will be invoked |
| 4204 | * each time code is added, moved or removed. |
| 4205 | * \note \p event_handler won't get notified of existent code. |
| 4206 | * \note since code removal notifications are not currently issued, the |
| 4207 | * \p event_handler may get notifications of code that overlaps earlier |
| 4208 | * code notifications. This happens when code areas are reused, and the |
| 4209 | * earlier overlapping code areas should therefore be discarded. |
| 4210 | * \note the events passed to \p event_handler and the strings they point to |
| 4211 | * are not guaranteed to live past each call. The \p event_handler must |
| 4212 | * copy strings and other parameters it needs to keep around. |
| 4213 | * \note the set of events declared in JitCodeEvent::EventType is expected to |
| 4214 | * grow over time, and the JitCodeEvent structure is expected to accrue |
| 4215 | * new members. The \p event_handler function must ignore event codes |
| 4216 | * it does not recognize to maintain future compatibility. |
| 4217 | */ |
| 4218 | static void SetJitCodeEventHandler(JitCodeEventOptions options, |
| 4219 | JitCodeEventHandler event_handler); |
| 4220 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4221 | // TODO(svenpanne) Really deprecate me when Chrome is fixed. |
| 4222 | /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4223 | static intptr_t AdjustAmountOfExternalAllocatedMemory( |
| 4224 | intptr_t change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4225 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4226 | /** |
| 4227 | * Suspends recording of tick samples in the profiler. |
| 4228 | * When the V8 profiling mode is enabled (usually via command line |
| 4229 | * switches) this function suspends recording of tick samples. |
| 4230 | * Profiling ticks are discarded until ResumeProfiler() is called. |
| 4231 | * |
| 4232 | * See also the --prof and --prof_auto command line switches to |
| 4233 | * enable V8 profiling. |
| 4234 | */ |
| 4235 | static void PauseProfiler(); |
| 4236 | |
| 4237 | /** |
| 4238 | * Resumes recording of tick samples in the profiler. |
| 4239 | * See also PauseProfiler(). |
| 4240 | */ |
| 4241 | static void ResumeProfiler(); |
| 4242 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4243 | /** |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4244 | * Return whether profiler is currently paused. |
| 4245 | */ |
| 4246 | static bool IsProfilerPaused(); |
| 4247 | |
| 4248 | /** |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4249 | * Retrieve the V8 thread id of the calling thread. |
| 4250 | * |
| 4251 | * The thread id for a thread should only be retrieved after the V8 |
| 4252 | * lock has been acquired with a Locker object with that thread. |
| 4253 | */ |
| 4254 | static int GetCurrentThreadId(); |
| 4255 | |
| 4256 | /** |
| 4257 | * Forcefully terminate execution of a JavaScript thread. This can |
| 4258 | * be used to terminate long-running scripts. |
| 4259 | * |
| 4260 | * TerminateExecution should only be called when then V8 lock has |
| 4261 | * been acquired with a Locker object. Therefore, in order to be |
| 4262 | * able to terminate long-running threads, preemption must be |
| 4263 | * enabled to allow the user of TerminateExecution to acquire the |
| 4264 | * lock. |
| 4265 | * |
| 4266 | * The termination is achieved by throwing an exception that is |
| 4267 | * uncatchable by JavaScript exception handlers. Termination |
| 4268 | * 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] | 4269 | * handler. If forceful termination is used, any C++ TryCatch |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4270 | * exception handler that catches an exception should check if that |
| 4271 | * exception is a termination exception and immediately return if |
| 4272 | * that is the case. Returning immediately in that case will |
| 4273 | * continue the propagation of the termination exception if needed. |
| 4274 | * |
| 4275 | * The thread id passed to TerminateExecution must have been |
| 4276 | * obtained by calling GetCurrentThreadId on the thread in question. |
| 4277 | * |
| 4278 | * \param thread_id The thread id of the thread to terminate. |
| 4279 | */ |
| 4280 | static void TerminateExecution(int thread_id); |
| 4281 | |
| 4282 | /** |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4283 | * Forcefully terminate the current thread of JavaScript execution |
| 4284 | * in the given isolate. If no isolate is provided, the default |
| 4285 | * isolate is used. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4286 | * |
| 4287 | * This method can be used by any thread even if that thread has not |
| 4288 | * acquired the V8 lock with a Locker object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4289 | * |
| 4290 | * \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] | 4291 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4292 | static void TerminateExecution(Isolate* isolate = NULL); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4293 | |
| 4294 | /** |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4295 | * Is V8 terminating JavaScript execution. |
| 4296 | * |
| 4297 | * Returns true if JavaScript execution is currently terminating |
| 4298 | * because of a call to TerminateExecution. In that case there are |
| 4299 | * still JavaScript frames on the stack and the termination |
| 4300 | * exception is still active. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4301 | * |
| 4302 | * \param isolate The isolate in which to check. |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4303 | */ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4304 | static bool IsExecutionTerminating(Isolate* isolate = NULL); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 4305 | |
| 4306 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4307 | * Resume execution capability in the given isolate, whose execution |
| 4308 | * was previously forcefully terminated using TerminateExecution(). |
| 4309 | * |
| 4310 | * When execution is forcefully terminated using TerminateExecution(), |
| 4311 | * the isolate can not resume execution until all JavaScript frames |
| 4312 | * have propagated the uncatchable exception which is generated. This |
| 4313 | * method allows the program embedding the engine to handle the |
| 4314 | * termination event and resume execution capability, even if |
| 4315 | * JavaScript frames remain on the stack. |
| 4316 | * |
| 4317 | * This method can be used by any thread even if that thread has not |
| 4318 | * acquired the V8 lock with a Locker object. |
| 4319 | * |
| 4320 | * \param isolate The isolate in which to resume execution capability. |
| 4321 | */ |
| 4322 | static void CancelTerminateExecution(Isolate* isolate); |
| 4323 | |
| 4324 | /** |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4325 | * Releases any resources used by v8 and stops any utility threads |
| 4326 | * that may be running. Note that disposing v8 is permanent, it |
| 4327 | * cannot be reinitialized. |
| 4328 | * |
| 4329 | * It should generally not be necessary to dispose v8 before exiting |
| 4330 | * a process, this should happen automatically. It is only necessary |
| 4331 | * to use if the process needs the resources taken up by v8. |
| 4332 | */ |
| 4333 | static bool Dispose(); |
| 4334 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4335 | /** Deprecated. Use Isolate::GetHeapStatistics instead. */ |
| 4336 | V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4337 | |
| 4338 | /** |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4339 | * Iterates through all external resources referenced from current isolate |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4340 | * heap. GC is not invoked prior to iterating, therefore there is no |
| 4341 | * guarantee that visited objects are still alive. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4342 | */ |
| 4343 | static void VisitExternalResources(ExternalResourceVisitor* visitor); |
| 4344 | |
| 4345 | /** |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4346 | * Iterates through all the persistent handles in the current isolate's heap |
| 4347 | * that have class_ids. |
| 4348 | */ |
| 4349 | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); |
| 4350 | |
| 4351 | /** |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4352 | * Iterates through all the persistent handles in the current isolate's heap |
| 4353 | * that have class_ids and are candidates to be marked as partially dependent |
| 4354 | * handles. This will visit handles to young objects created since the last |
| 4355 | * garbage collection but is free to visit an arbitrary superset of these |
| 4356 | * objects. |
| 4357 | */ |
| 4358 | static void VisitHandlesForPartialDependence( |
| 4359 | Isolate* isolate, PersistentHandleVisitor* visitor); |
| 4360 | |
| 4361 | /** |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4362 | * Optional notification that the embedder is idle. |
| 4363 | * V8 uses the notification to reduce memory footprint. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4364 | * This call can be used repeatedly if the embedder remains idle. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 4365 | * Returns true if the embedder should stop calling IdleNotification |
| 4366 | * until real work has been done. This indicates that V8 has done |
| 4367 | * as much cleanup as it will be able to do. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4368 | * |
| 4369 | * The hint argument specifies the amount of work to be done in the function |
| 4370 | * on scale from 1 to 1000. There is no guarantee that the actual work will |
| 4371 | * match the hint. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4372 | */ |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4373 | static bool IdleNotification(int hint = 1000); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4374 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4375 | /** |
| 4376 | * Optional notification that the system is running low on memory. |
| 4377 | * V8 uses these notifications to attempt to free memory. |
| 4378 | */ |
| 4379 | static void LowMemoryNotification(); |
| 4380 | |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4381 | /** |
| 4382 | * Optional notification that a context has been disposed. V8 uses |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4383 | * these notifications to guide the GC heuristic. Returns the number |
| 4384 | * of context disposals - including this one - since the last time |
| 4385 | * V8 had a chance to clean up. |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4386 | */ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4387 | static int ContextDisposedNotification(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4388 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4389 | private: |
| 4390 | V8(); |
| 4391 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4392 | static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| 4393 | internal::Object** handle); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4394 | static void DisposeGlobal(internal::Isolate* isolate, |
| 4395 | internal::Object** global_handle); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4396 | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4397 | static void MakeWeak(internal::Isolate* isolate, |
| 4398 | internal::Object** global_handle, |
| 4399 | void* data, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4400 | RevivableCallback weak_reference_callback, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4401 | NearDeathCallback near_death_callback); |
| 4402 | static void ClearWeak(internal::Isolate* isolate, |
| 4403 | internal::Object** global_handle); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4404 | |
| 4405 | template <class T> friend class Handle; |
| 4406 | template <class T> friend class Local; |
| 4407 | template <class T> friend class Persistent; |
| 4408 | friend class Context; |
| 4409 | }; |
| 4410 | |
| 4411 | |
| 4412 | /** |
| 4413 | * An external exception handler. |
| 4414 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4415 | class V8EXPORT TryCatch { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4416 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4417 | /** |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4418 | * Creates a new try/catch block and registers it with v8. Note that |
| 4419 | * all TryCatch blocks should be stack allocated because the memory |
| 4420 | * location itself is compared against JavaScript try/catch blocks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4421 | */ |
| 4422 | TryCatch(); |
| 4423 | |
| 4424 | /** |
| 4425 | * Unregisters and deletes this try/catch block. |
| 4426 | */ |
| 4427 | ~TryCatch(); |
| 4428 | |
| 4429 | /** |
| 4430 | * Returns true if an exception has been caught by this try/catch block. |
| 4431 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4432 | bool HasCaught() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4433 | |
| 4434 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4435 | * 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] | 4436 | * |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4437 | * If CanContinue returns false, the correct action is to perform any C++ |
| 4438 | * cleanup needed and then return. If CanContinue returns false and |
| 4439 | * HasTerminated returns true, it is possible to call |
| 4440 | * CancelTerminateExecution in order to continue calling into the engine. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4441 | */ |
| 4442 | bool CanContinue() const; |
| 4443 | |
| 4444 | /** |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4445 | * Returns true if an exception has been caught due to script execution |
| 4446 | * being terminated. |
| 4447 | * |
| 4448 | * There is no JavaScript representation of an execution termination |
| 4449 | * exception. Such exceptions are thrown when the TerminateExecution |
| 4450 | * methods are called to terminate a long-running script. |
| 4451 | * |
| 4452 | * If such an exception has been thrown, HasTerminated will return true, |
| 4453 | * indicating that it is possible to call CancelTerminateExecution in order |
| 4454 | * to continue calling into the engine. |
| 4455 | */ |
| 4456 | bool HasTerminated() const; |
| 4457 | |
| 4458 | /** |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4459 | * Throws the exception caught by this TryCatch in a way that avoids |
| 4460 | * it being caught again by this same TryCatch. As with ThrowException |
| 4461 | * it is illegal to execute any JavaScript operations after calling |
| 4462 | * ReThrow; the caller must return immediately to where the exception |
| 4463 | * is caught. |
| 4464 | */ |
| 4465 | Handle<Value> ReThrow(); |
| 4466 | |
| 4467 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4468 | * Returns the exception caught by this try/catch block. If no exception has |
| 4469 | * been caught an empty handle is returned. |
| 4470 | * |
| 4471 | * The returned handle is valid until this TryCatch block has been destroyed. |
| 4472 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4473 | Local<Value> Exception() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4474 | |
| 4475 | /** |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4476 | * Returns the .stack property of the thrown object. If no .stack |
| 4477 | * property is present an empty handle is returned. |
| 4478 | */ |
| 4479 | Local<Value> StackTrace() const; |
| 4480 | |
| 4481 | /** |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4482 | * Returns the message associated with this exception. If there is |
| 4483 | * no message associated an empty handle is returned. |
| 4484 | * |
| 4485 | * The returned handle is valid until this TryCatch block has been |
| 4486 | * destroyed. |
| 4487 | */ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4488 | Local<v8::Message> Message() const; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4489 | |
| 4490 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4491 | * Clears any exceptions that may have been caught by this try/catch block. |
| 4492 | * After this method has been called, HasCaught() will return false. |
| 4493 | * |
| 4494 | * It is not necessary to clear a try/catch block before using it again; if |
| 4495 | * another exception is thrown the previously caught exception will just be |
| 4496 | * overwritten. However, it is often a good idea since it makes it easier |
| 4497 | * to determine which operation threw a given exception. |
| 4498 | */ |
| 4499 | void Reset(); |
| 4500 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4501 | /** |
| 4502 | * Set verbosity of the external exception handler. |
| 4503 | * |
| 4504 | * By default, exceptions that are caught by an external exception |
| 4505 | * handler are not reported. Call SetVerbose with true on an |
| 4506 | * external exception handler to have exceptions caught by the |
| 4507 | * handler reported as if they were not caught. |
| 4508 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4509 | void SetVerbose(bool value); |
| 4510 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4511 | /** |
| 4512 | * Set whether or not this TryCatch should capture a Message object |
| 4513 | * which holds source information about where the exception |
| 4514 | * occurred. True by default. |
| 4515 | */ |
| 4516 | void SetCaptureMessage(bool value); |
| 4517 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4518 | private: |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 4519 | // Make it hard to create heap-allocated TryCatch blocks. |
| 4520 | TryCatch(const TryCatch&); |
| 4521 | void operator=(const TryCatch&); |
| 4522 | void* operator new(size_t size); |
| 4523 | void operator delete(void*, size_t); |
| 4524 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4525 | v8::internal::Isolate* isolate_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4526 | void* next_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4527 | void* exception_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4528 | void* message_; |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 4529 | bool is_verbose_ : 1; |
| 4530 | bool can_continue_ : 1; |
| 4531 | bool capture_message_ : 1; |
| 4532 | bool rethrow_ : 1; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4533 | bool has_terminated_ : 1; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4534 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4535 | friend class v8::internal::Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4536 | }; |
| 4537 | |
| 4538 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4539 | // --- Context --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4540 | |
| 4541 | |
| 4542 | /** |
| 4543 | * Ignore |
| 4544 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4545 | class V8EXPORT ExtensionConfiguration { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4546 | public: |
| 4547 | ExtensionConfiguration(int name_count, const char* names[]) |
| 4548 | : name_count_(name_count), names_(names) { } |
| 4549 | private: |
| 4550 | friend class ImplementationUtilities; |
| 4551 | int name_count_; |
| 4552 | const char** names_; |
| 4553 | }; |
| 4554 | |
| 4555 | |
| 4556 | /** |
| 4557 | * A sandboxed execution context with its own set of built-in objects |
| 4558 | * and functions. |
| 4559 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4560 | class V8EXPORT Context { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4561 | public: |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4562 | /** |
| 4563 | * Returns the global proxy object or global object itself for |
| 4564 | * detached contexts. |
| 4565 | * |
| 4566 | * Global proxy object is a thin wrapper whose prototype points to |
| 4567 | * actual context's global object with the properties like Object, etc. |
| 4568 | * This is done that way for security reasons (for more details see |
| 4569 | * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 4570 | * |
| 4571 | * Please note that changes to global proxy object prototype most probably |
| 4572 | * would break VM---v8 expects only global object as a prototype of |
| 4573 | * global proxy object. |
| 4574 | * |
| 4575 | * If DetachGlobal() has been invoked, Global() would return actual global |
| 4576 | * object until global is reattached with ReattachGlobal(). |
| 4577 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4578 | Local<Object> Global(); |
| 4579 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4580 | /** |
| 4581 | * Detaches the global object from its context before |
| 4582 | * the global object can be reused to create a new context. |
| 4583 | */ |
| 4584 | void DetachGlobal(); |
| 4585 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4586 | /** |
| 4587 | * Reattaches a global object to a context. This can be used to |
| 4588 | * restore the connection between a global object and a context |
| 4589 | * after DetachGlobal has been called. |
| 4590 | * |
| 4591 | * \param global_object The global object to reattach to the |
| 4592 | * context. For this to work, the global object must be the global |
| 4593 | * object that was associated with this context before a call to |
| 4594 | * DetachGlobal. |
| 4595 | */ |
| 4596 | void ReattachGlobal(Handle<Object> global_object); |
| 4597 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4598 | /** |
| 4599 | * Creates a new context and returns a handle to the newly allocated |
| 4600 | * context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4601 | * |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4602 | * \param isolate The isolate in which to create the context. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4603 | * |
| 4604 | * \param extensions An optional extension configuration containing |
| 4605 | * the extensions to be installed in the newly created context. |
| 4606 | * |
| 4607 | * \param global_template An optional object template from which the |
| 4608 | * global object for the newly created context will be created. |
| 4609 | * |
| 4610 | * \param global_object An optional global object to be reused for |
| 4611 | * the newly created context. This global object must have been |
| 4612 | * created by a previous call to Context::New with the same global |
| 4613 | * template. The state of the global object will be completely reset |
| 4614 | * and only object identify will remain. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4615 | */ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4616 | static Local<Context> New( |
| 4617 | Isolate* isolate, |
| 4618 | ExtensionConfiguration* extensions = NULL, |
| 4619 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
| 4620 | Handle<Value> global_object = Handle<Value>()); |
| 4621 | |
| 4622 | /** Deprecated. Use Isolate version instead. */ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 4623 | V8_DEPRECATED(static Persistent<Context> New( |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4624 | ExtensionConfiguration* extensions = NULL, |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4625 | Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 4626 | Handle<Value> global_object = Handle<Value>())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4627 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4628 | /** Returns the last entered context. */ |
| 4629 | static Local<Context> GetEntered(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4630 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4631 | // TODO(svenpanne) Actually deprecate this. |
| 4632 | /** Deprecated. Use Isolate::GetCurrentContext instead. */ |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4633 | static Local<Context> GetCurrent(); |
| 4634 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4635 | /** |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4636 | * Returns the context of the calling JavaScript code. That is the |
| 4637 | * context of the top-most JavaScript frame. If there are no |
| 4638 | * JavaScript frames an empty handle is returned. |
| 4639 | */ |
| 4640 | static Local<Context> GetCalling(); |
| 4641 | |
| 4642 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4643 | * Sets the security token for the context. To access an object in |
| 4644 | * another context, the security tokens must match. |
| 4645 | */ |
| 4646 | void SetSecurityToken(Handle<Value> token); |
| 4647 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4648 | /** Restores the security token to the default value. */ |
| 4649 | void UseDefaultSecurityToken(); |
| 4650 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4651 | /** Returns the security token of this context.*/ |
| 4652 | Handle<Value> GetSecurityToken(); |
| 4653 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4654 | /** |
| 4655 | * Enter this context. After entering a context, all code compiled |
| 4656 | * and run is compiled and run in this context. If another context |
| 4657 | * is already entered, this old context is saved so it can be |
| 4658 | * restored when the new context is exited. |
| 4659 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4660 | void Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4661 | |
| 4662 | /** |
| 4663 | * Exit this context. Exiting the current context restores the |
| 4664 | * context that was in place when entering the current context. |
| 4665 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4666 | void Exit(); |
| 4667 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4668 | /** 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] | 4669 | bool HasOutOfMemoryException(); |
| 4670 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4671 | /** Returns true if V8 has a current context. */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4672 | static bool InContext(); |
| 4673 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4674 | /** Returns an isolate associated with a current context. */ |
| 4675 | v8::Isolate* GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4676 | |
| 4677 | /** |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4678 | * Gets the embedder data with the given index, which must have been set by a |
| 4679 | * previous call to SetEmbedderData with the same index. Note that index 0 |
| 4680 | * currently has a special meaning for Chrome's debugger. |
| 4681 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4682 | V8_INLINE(Local<Value> GetEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4683 | |
| 4684 | /** |
| 4685 | * Sets the embedder data with the given index, growing the data as |
| 4686 | * needed. Note that index 0 currently has a special meaning for Chrome's |
| 4687 | * debugger. |
| 4688 | */ |
| 4689 | void SetEmbedderData(int index, Handle<Value> value); |
| 4690 | |
| 4691 | /** |
| 4692 | * Gets a 2-byte-aligned native pointer from the embedder data with the given |
| 4693 | * index, which must have bees set by a previous call to |
| 4694 | * SetAlignedPointerInEmbedderData with the same index. Note that index 0 |
| 4695 | * currently has a special meaning for Chrome's debugger. |
| 4696 | */ |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4697 | V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4698 | |
| 4699 | /** |
| 4700 | * Sets a 2-byte-aligned native pointer in the embedder data with the given |
| 4701 | * index, growing the data as needed. Note that index 0 currently has a |
| 4702 | * special meaning for Chrome's debugger. |
| 4703 | */ |
| 4704 | void SetAlignedPointerInEmbedderData(int index, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4705 | |
| 4706 | /** |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4707 | * Control whether code generation from strings is allowed. Calling |
| 4708 | * this method with false will disable 'eval' and the 'Function' |
| 4709 | * constructor for code running in this context. If 'eval' or the |
| 4710 | * 'Function' constructor are used an exception will be thrown. |
| 4711 | * |
| 4712 | * If code generation from strings is not allowed the |
| 4713 | * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 4714 | * set before blocking the call to 'eval' or the 'Function' |
| 4715 | * constructor. If that callback returns true, the call will be |
| 4716 | * allowed, otherwise an exception will be thrown. If no callback is |
| 4717 | * set an exception will be thrown. |
| 4718 | */ |
| 4719 | void AllowCodeGenerationFromStrings(bool allow); |
| 4720 | |
| 4721 | /** |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4722 | * Returns true if code generation from strings is allowed for the context. |
| 4723 | * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
| 4724 | */ |
| 4725 | bool IsCodeGenerationFromStringsAllowed(); |
| 4726 | |
| 4727 | /** |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4728 | * Sets the error description for the exception that is thrown when |
| 4729 | * code generation from strings is not allowed and 'eval' or the 'Function' |
| 4730 | * constructor are called. |
| 4731 | */ |
| 4732 | void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); |
| 4733 | |
| 4734 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4735 | * Stack-allocated class which sets the execution context for all |
| 4736 | * operations executed within a local scope. |
| 4737 | */ |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4738 | class Scope { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4739 | public: |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4740 | explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4741 | context_->Enter(); |
| 4742 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4743 | V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| 4744 | #ifndef V8_USE_UNSAFE_HANDLES |
| 4745 | : context_(Handle<Context>::New(isolate, context)) { |
| 4746 | #else |
| 4747 | : context_(Local<Context>::New(isolate, context)) { |
| 4748 | #endif |
| 4749 | context_->Enter(); |
| 4750 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4751 | V8_INLINE(~Scope()) { context_->Exit(); } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4752 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4753 | private: |
| 4754 | Handle<Context> context_; |
| 4755 | }; |
| 4756 | |
| 4757 | private: |
| 4758 | friend class Value; |
| 4759 | friend class Script; |
| 4760 | friend class Object; |
| 4761 | friend class Function; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4762 | |
| 4763 | Local<Value> SlowGetEmbedderData(int index); |
| 4764 | void* SlowGetAlignedPointerFromEmbedderData(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4765 | }; |
| 4766 | |
| 4767 | |
| 4768 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4769 | * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
| 4770 | * to use any given V8 isolate, see the comments in the Isolate class. The |
| 4771 | * definition of 'using a V8 isolate' includes accessing handles or holding onto |
| 4772 | * object pointers obtained from V8 handles while in the particular V8 isolate. |
| 4773 | * It is up to the user of V8 to ensure, perhaps with locking, that this |
| 4774 | * constraint is not violated. In addition to any other synchronization |
| 4775 | * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
| 4776 | * used to signal thead switches to V8. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4777 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4778 | * v8::Locker is a scoped lock object. While it's active, i.e. between its |
| 4779 | * construction and destruction, the current thread is allowed to use the locked |
| 4780 | * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
| 4781 | * 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] | 4782 | * |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4783 | * Sample usage: |
| 4784 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4785 | * ... |
| 4786 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4787 | * v8::Locker locker(isolate); |
| 4788 | * v8::Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4789 | * ... |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4790 | * // Code using V8 and isolate goes here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4791 | * ... |
| 4792 | * } // Destructor called here |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4793 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4794 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4795 | * If you wish to stop using V8 in a thread A you can do this either by |
| 4796 | * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
| 4797 | * object: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4798 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4799 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4800 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4801 | * isolate->Exit(); |
| 4802 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4803 | * ... |
| 4804 | * // Code not using V8 goes here while V8 can run in another thread. |
| 4805 | * ... |
| 4806 | * } // Destructor called here. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4807 | * isolate->Enter(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4808 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4809 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4810 | * The Unlocker object is intended for use in a long-running callback from V8, |
| 4811 | * 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] | 4812 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4813 | * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
| 4814 | * given thread. This can be useful if you have code that can be called either |
| 4815 | * from code that holds the lock or from code that does not. The Unlocker is |
| 4816 | * not recursive so you can not have several Unlockers on the stack at once, and |
| 4817 | * 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] | 4818 | * |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4819 | * An unlocker will unlock several lockers if it has to and reinstate the |
| 4820 | * correct depth of locking on its destruction, e.g.: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4821 | * |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4822 | * \code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4823 | * // V8 not locked. |
| 4824 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4825 | * v8::Locker locker(isolate); |
| 4826 | * Isolate::Scope isolate_scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4827 | * // V8 locked. |
| 4828 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4829 | * v8::Locker another_locker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4830 | * // V8 still locked (2 levels). |
| 4831 | * { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4832 | * isolate->Exit(); |
| 4833 | * v8::Unlocker unlocker(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4834 | * // V8 not locked. |
| 4835 | * } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4836 | * isolate->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4837 | * // V8 locked again (2 levels). |
| 4838 | * } |
| 4839 | * // V8 still locked (1 level). |
| 4840 | * } |
| 4841 | * // V8 Now no longer locked. |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4842 | * \endcode |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4843 | */ |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4844 | class V8EXPORT Unlocker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4845 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4846 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4847 | * Initialize Unlocker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4848 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4849 | V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 4850 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4851 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4852 | V8_DEPRECATED(Unlocker()); |
| 4853 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4854 | ~Unlocker(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4855 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4856 | void Initialize(Isolate* isolate); |
| 4857 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4858 | internal::Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4859 | }; |
| 4860 | |
| 4861 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4862 | class V8EXPORT Locker { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4863 | public: |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4864 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4865 | * Initialize Locker for a given Isolate. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4866 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4867 | V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 4868 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4869 | /** Deprecated. Use Isolate version instead. */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4870 | V8_DEPRECATED(Locker()); |
| 4871 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4872 | ~Locker(); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4873 | |
| 4874 | /** |
| 4875 | * Start preemption. |
| 4876 | * |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4877 | * When preemption is started, a timer is fired every n milliseconds |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 4878 | * that will switch between multiple threads that are in contention |
| 4879 | * for the V8 lock. |
| 4880 | */ |
| 4881 | static void StartPreemption(int every_n_ms); |
| 4882 | |
| 4883 | /** |
| 4884 | * Stop preemption. |
| 4885 | */ |
| 4886 | static void StopPreemption(); |
| 4887 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4888 | /** |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4889 | * Returns whether or not the locker for a given isolate, is locked by the |
| 4890 | * current thread. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4891 | */ |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4892 | static bool IsLocked(Isolate* isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4893 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4894 | /** |
| 4895 | * Returns whether v8::Locker is being used by this V8 instance. |
| 4896 | */ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4897 | static bool IsActive(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4898 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4899 | private: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4900 | void Initialize(Isolate* isolate); |
| 4901 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4902 | bool has_lock_; |
| 4903 | bool top_level_; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4904 | internal::Isolate* isolate_; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4905 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 4906 | static bool active_; |
| 4907 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4908 | // Disallow copying and assigning. |
| 4909 | Locker(const Locker&); |
| 4910 | void operator=(const Locker&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4911 | }; |
| 4912 | |
| 4913 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4914 | /** |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4915 | * A struct for exporting HeapStats data from V8, using "push" model. |
| 4916 | */ |
| 4917 | struct HeapStatsUpdate; |
| 4918 | |
| 4919 | |
| 4920 | /** |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4921 | * An interface for exporting data from V8, using "push" model. |
| 4922 | */ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 4923 | class V8EXPORT OutputStream { // NOLINT |
| 4924 | public: |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4925 | enum OutputEncoding { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4926 | kAscii = 0 // 7-bit ASCII. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4927 | }; |
| 4928 | enum WriteResult { |
| 4929 | kContinue = 0, |
| 4930 | kAbort = 1 |
| 4931 | }; |
| 4932 | virtual ~OutputStream() {} |
| 4933 | /** Notify about the end of stream. */ |
| 4934 | virtual void EndOfStream() = 0; |
| 4935 | /** Get preferred output chunk size. Called only once. */ |
| 4936 | virtual int GetChunkSize() { return 1024; } |
| 4937 | /** Get preferred output encoding. Called only once. */ |
| 4938 | virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 4939 | /** |
| 4940 | * Writes the next chunk of snapshot data into the stream. Writing |
| 4941 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4942 | * will not be called in case writing was aborted. |
| 4943 | */ |
| 4944 | virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 4945 | /** |
| 4946 | * Writes the next chunk of heap stats data into the stream. Writing |
| 4947 | * can be stopped by returning kAbort as function result. EndOfStream |
| 4948 | * will not be called in case writing was aborted. |
| 4949 | */ |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4950 | virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) { |
jkummerow@chromium.org | 3ee08a6 | 2012-04-13 13:01:33 +0000 | [diff] [blame] | 4951 | return kAbort; |
| 4952 | }; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4953 | }; |
| 4954 | |
| 4955 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4956 | /** |
| 4957 | * An interface for reporting progress and controlling long-running |
| 4958 | * activities. |
| 4959 | */ |
| 4960 | class V8EXPORT ActivityControl { // NOLINT |
| 4961 | public: |
| 4962 | enum ControlOption { |
| 4963 | kContinue = 0, |
| 4964 | kAbort = 1 |
| 4965 | }; |
| 4966 | virtual ~ActivityControl() {} |
| 4967 | /** |
| 4968 | * Notify about current progress. The activity can be stopped by |
| 4969 | * returning kAbort as the callback result. |
| 4970 | */ |
| 4971 | virtual ControlOption ReportProgressValue(int done, int total) = 0; |
| 4972 | }; |
| 4973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4974 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4975 | // --- Implementation --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4976 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4977 | |
| 4978 | namespace internal { |
| 4979 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4980 | const int kApiPointerSize = sizeof(void*); // NOLINT |
| 4981 | const int kApiIntSize = sizeof(int); // NOLINT |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4982 | |
| 4983 | // Tag information for HeapObject. |
| 4984 | const int kHeapObjectTag = 1; |
| 4985 | const int kHeapObjectTagSize = 2; |
| 4986 | const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 4987 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4988 | // Tag information for Smi. |
| 4989 | const int kSmiTag = 0; |
| 4990 | const int kSmiTagSize = 1; |
| 4991 | const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 4992 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4993 | template <size_t ptr_size> struct SmiTagging; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4994 | |
| 4995 | // Smi constants for 32-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4996 | template <> struct SmiTagging<4> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4997 | static const int kSmiShiftSize = 0; |
| 4998 | static const int kSmiValueSize = 31; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 4999 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5000 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5001 | // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 5002 | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 5003 | } |
| 5004 | }; |
| 5005 | |
| 5006 | // Smi constants for 64-bit systems. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5007 | template <> struct SmiTagging<8> { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5008 | static const int kSmiShiftSize = 31; |
| 5009 | static const int kSmiValueSize = 32; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5010 | V8_INLINE(static int SmiToInt(internal::Object* value)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5011 | int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 5012 | // Shift down and throw away top 32 bits. |
| 5013 | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 5014 | } |
| 5015 | }; |
| 5016 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5017 | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 5018 | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 5019 | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5020 | |
| 5021 | /** |
| 5022 | * This class exports constants and functionality from within v8 that |
| 5023 | * is necessary to implement inline functions in the v8 api. Don't |
| 5024 | * depend on functions and constants defined here. |
| 5025 | */ |
| 5026 | class Internals { |
| 5027 | public: |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5028 | // These values match non-compiler-dependent values defined within |
| 5029 | // the implementation of v8. |
| 5030 | static const int kHeapObjectMapOffset = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5031 | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5032 | static const int kStringResourceOffset = 3 * kApiPointerSize; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5033 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5034 | static const int kOddballKindOffset = 3 * kApiPointerSize; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5035 | static const int kForeignAddressOffset = kApiPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5036 | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5037 | static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
| 5038 | static const int kContextHeaderSize = 2 * kApiPointerSize; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 5039 | static const int kContextEmbedderDataIndex = 64; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5040 | static const int kFullStringRepresentationMask = 0x07; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5041 | static const int kStringEncodingMask = 0x4; |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 5042 | static const int kExternalTwoByteRepresentationTag = 0x02; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5043 | static const int kExternalAsciiRepresentationTag = 0x06; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5044 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5045 | static const int kIsolateStateOffset = 0; |
| 5046 | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 5047 | static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 5048 | static const int kUndefinedValueRootIndex = 5; |
| 5049 | static const int kNullValueRootIndex = 7; |
| 5050 | static const int kTrueValueRootIndex = 8; |
| 5051 | static const int kFalseValueRootIndex = 9; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5052 | static const int kEmptyStringRootIndex = 118; |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5053 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5054 | static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
| 5055 | static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
| 5056 | static const int kNodeStateMask = 0xf; |
| 5057 | static const int kNodeStateIsWeakValue = 2; |
| 5058 | static const int kNodeStateIsNearDeathValue = 4; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5059 | static const int kNodeIsIndependentShift = 4; |
| 5060 | static const int kNodeIsPartiallyDependentShift = 5; |
| 5061 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5062 | static const int kJSObjectType = 0xae; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5063 | static const int kFirstNonstringType = 0x80; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5064 | static const int kOddballType = 0x83; |
| 5065 | static const int kForeignType = 0x86; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5066 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5067 | static const int kUndefinedOddballKind = 5; |
| 5068 | static const int kNullOddballKind = 3; |
| 5069 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5070 | V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5071 | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 5072 | kHeapObjectTag); |
| 5073 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5074 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5075 | V8_INLINE(static int SmiValue(internal::Object* value)) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5076 | return PlatformSmiTagging::SmiToInt(value); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5079 | V8_INLINE(static int GetInstanceType(internal::Object* obj)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5080 | typedef internal::Object O; |
| 5081 | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 5082 | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 5083 | } |
| 5084 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5085 | V8_INLINE(static int GetOddballKind(internal::Object* obj)) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5086 | typedef internal::Object O; |
| 5087 | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 5088 | } |
| 5089 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5090 | V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5091 | int representation = (instance_type & kFullStringRepresentationMask); |
| 5092 | return representation == kExternalTwoByteRepresentationTag; |
| 5093 | } |
| 5094 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5095 | V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5096 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 5097 | return *reinterpret_cast<int*>(addr) == 1; |
| 5098 | } |
| 5099 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5100 | V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { |
| 5101 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5102 | return *addr & (1 << shift); |
| 5103 | } |
| 5104 | |
| 5105 | V8_INLINE(static void UpdateNodeFlag(internal::Object** obj, |
| 5106 | bool value, int shift)) { |
| 5107 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5108 | uint8_t mask = 1 << shift; |
| 5109 | *addr = (*addr & ~mask) | (value << shift); |
| 5110 | } |
| 5111 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5112 | V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { |
| 5113 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5114 | return *addr & kNodeStateMask; |
| 5115 | } |
| 5116 | |
| 5117 | V8_INLINE(static void UpdateNodeState(internal::Object** obj, |
| 5118 | uint8_t value)) { |
| 5119 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| 5120 | *addr = (*addr & ~kNodeStateMask) | value; |
| 5121 | } |
| 5122 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5123 | V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5124 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5125 | kIsolateEmbedderDataOffset; |
| 5126 | *reinterpret_cast<void**>(addr) = data; |
| 5127 | } |
| 5128 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5129 | V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5130 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
| 5131 | kIsolateEmbedderDataOffset; |
| 5132 | return *reinterpret_cast<void**>(addr); |
| 5133 | } |
| 5134 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5135 | V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate, |
| 5136 | int index)) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5137 | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 5138 | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 5139 | } |
| 5140 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5141 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5142 | V8_INLINE(static T ReadField(Object* ptr, int offset)) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5143 | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 5144 | return *reinterpret_cast<T*>(addr); |
| 5145 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5146 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5147 | template <typename T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5148 | V8_INLINE(static T ReadEmbedderData(Context* context, int index)) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5149 | typedef internal::Object O; |
| 5150 | typedef internal::Internals I; |
| 5151 | O* ctx = *reinterpret_cast<O**>(context); |
| 5152 | int embedder_data_offset = I::kContextHeaderSize + |
| 5153 | (internal::kApiPointerSize * I::kContextEmbedderDataIndex); |
| 5154 | O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); |
| 5155 | int value_offset = |
| 5156 | I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); |
| 5157 | return I::ReadField<T>(embedder_data, value_offset); |
| 5158 | } |
| 5159 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5160 | V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; } |
| 5161 | V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; } |
| 5162 | V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; } |
| 5163 | V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; } |
| 5164 | V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; } |
| 5165 | V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; } |
| 5166 | V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5167 | }; |
| 5168 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 5169 | } // namespace internal |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5170 | |
| 5171 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5172 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5173 | Local<T>::Local() : Handle<T>() { } |
| 5174 | |
| 5175 | |
| 5176 | template <class T> |
| 5177 | Local<T> Local<T>::New(Handle<T> that) { |
| 5178 | if (that.IsEmpty()) return Local<T>(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5179 | T* that_ptr = *that; |
| 5180 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5181 | if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 5182 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5183 | reinterpret_cast<internal::HeapObject*>(*p)))); |
| 5184 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5185 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5190 | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5191 | return New(isolate, that.val_); |
| 5192 | } |
| 5193 | |
| 5194 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5195 | template <class T> |
| 5196 | Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| 5197 | return New(isolate, that.val_); |
| 5198 | } |
| 5199 | |
| 5200 | template <class T> |
| 5201 | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| 5202 | if (that == NULL) return Handle<T>(); |
| 5203 | T* that_ptr = that; |
| 5204 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5205 | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5206 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5207 | } |
| 5208 | #endif |
| 5209 | |
| 5210 | |
| 5211 | template <class T> |
| 5212 | Local<T> Local<T>::New(Isolate* isolate, T* that) { |
| 5213 | if (that == NULL) return Local<T>(); |
| 5214 | T* that_ptr = that; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5215 | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 5216 | return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| 5217 | reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| 5218 | } |
| 5219 | |
| 5220 | |
| 5221 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5222 | Persistent<T> Persistent<T>::New(Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5223 | return New(Isolate::GetCurrent(), that.val_); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | template <class T> |
| 5228 | Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5229 | return New(Isolate::GetCurrent(), that.val_); |
| 5230 | } |
| 5231 | |
| 5232 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5233 | template <class T> |
| 5234 | Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| 5235 | return New(Isolate::GetCurrent(), that.val_); |
| 5236 | } |
| 5237 | #endif |
| 5238 | |
| 5239 | template <class T> |
| 5240 | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { |
| 5241 | if (that == NULL) return Persistent<T>(); |
| 5242 | internal::Object** p = reinterpret_cast<internal::Object**>(that); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5243 | return Persistent<T>(reinterpret_cast<T*>( |
| 5244 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), |
| 5245 | p))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | |
| 5249 | template <class T> |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5250 | bool Persistent<T>::IsIndependent() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5251 | return IsIndependent(Isolate::GetCurrent()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | |
| 5255 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5256 | bool Persistent<T>::IsIndependent(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5257 | typedef internal::Internals I; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5258 | if (this->IsEmpty()) return false; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5259 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5260 | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5261 | I::kNodeIsIndependentShift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | |
| 5265 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5266 | bool Persistent<T>::IsNearDeath() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5267 | return IsNearDeath(Isolate::GetCurrent()); |
| 5268 | } |
| 5269 | |
| 5270 | |
| 5271 | template <class T> |
| 5272 | bool Persistent<T>::IsNearDeath(Isolate* isolate) const { |
| 5273 | typedef internal::Internals I; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5274 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5275 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5276 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5277 | I::kNodeStateIsNearDeathValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | |
| 5281 | template <class T> |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5282 | bool Persistent<T>::IsWeak() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5283 | return IsWeak(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | |
| 5287 | template <class T> |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5288 | bool Persistent<T>::IsWeak(Isolate* isolate) const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5289 | typedef internal::Internals I; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5290 | if (this->IsEmpty()) return false; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5291 | if (!I::IsInitialized(isolate)) return false; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5292 | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5293 | I::kNodeStateIsWeakValue; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | |
| 5297 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5298 | void Persistent<T>::Dispose() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5299 | Dispose(Isolate::GetCurrent()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | |
| 5303 | template <class T> |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5304 | void Persistent<T>::Dispose(Isolate* isolate) { |
| 5305 | if (this->IsEmpty()) return; |
| 5306 | V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5307 | reinterpret_cast<internal::Object**>(this->val_)); |
| 5308 | #ifndef V8_USE_UNSAFE_HANDLES |
| 5309 | val_ = 0; |
| 5310 | #endif |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | |
| 5314 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5315 | template <typename S, typename P> |
| 5316 | void Persistent<T>::MakeWeak( |
| 5317 | Isolate* isolate, |
| 5318 | P* parameters, |
| 5319 | typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| 5320 | TYPE_CHECK(S, T); |
| 5321 | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5322 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5323 | reinterpret_cast<internal::Object**>(this->val_), |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5324 | parameters, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5325 | reinterpret_cast<Revivable>(callback), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5326 | NULL); |
| 5327 | } |
| 5328 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5329 | |
| 5330 | template <class T> |
| 5331 | template <typename P> |
| 5332 | void Persistent<T>::MakeWeak( |
| 5333 | Isolate* isolate, |
| 5334 | P* parameters, |
| 5335 | typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| 5336 | MakeWeak<T, P>(isolate, parameters, callback); |
| 5337 | } |
| 5338 | |
| 5339 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5340 | template <class T> |
| 5341 | void Persistent<T>::MakeWeak(Isolate* isolate, |
| 5342 | void* parameters, |
| 5343 | NearDeathCallback callback) { |
| 5344 | V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5345 | reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5346 | parameters, |
| 5347 | NULL, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5348 | callback); |
| 5349 | } |
| 5350 | |
| 5351 | template <class T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5352 | void Persistent<T>::ClearWeak() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5353 | ClearWeak(Isolate::GetCurrent()); |
| 5354 | } |
| 5355 | |
| 5356 | template <class T> |
| 5357 | void Persistent<T>::ClearWeak(Isolate* isolate) { |
| 5358 | V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5359 | reinterpret_cast<internal::Object**>(this->val_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5362 | template <class T> |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5363 | void Persistent<T>::MarkIndependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5364 | MarkIndependent(Isolate::GetCurrent()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | template <class T> |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5368 | void Persistent<T>::MarkIndependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5369 | typedef internal::Internals I; |
| 5370 | if (this->IsEmpty()) return; |
| 5371 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5372 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5373 | true, |
| 5374 | I::kNodeIsIndependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | template <class T> |
| 5378 | void Persistent<T>::MarkPartiallyDependent() { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5379 | MarkPartiallyDependent(Isolate::GetCurrent()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | template <class T> |
| 5383 | void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5384 | typedef internal::Internals I; |
| 5385 | if (this->IsEmpty()) return; |
| 5386 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5387 | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5388 | true, |
| 5389 | I::kNodeIsPartiallyDependentShift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | template <class T> |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5393 | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5394 | SetWrapperClassId(Isolate::GetCurrent(), class_id); |
| 5395 | } |
| 5396 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 5397 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5398 | template <class T> |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5399 | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| 5400 | Dispose(isolate); |
| 5401 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5402 | *this = *New(isolate, other); |
| 5403 | #else |
| 5404 | if (other.IsEmpty()) { |
| 5405 | this->val_ = NULL; |
| 5406 | return; |
| 5407 | } |
| 5408 | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| 5409 | this->val_ = reinterpret_cast<T*>( |
| 5410 | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| 5411 | #endif |
| 5412 | } |
| 5413 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame^] | 5414 | |
| 5415 | template <class T> |
| 5416 | T* Persistent<T>::ClearAndLeak() { |
| 5417 | T* old; |
| 5418 | #ifdef V8_USE_UNSAFE_HANDLES |
| 5419 | old = **this; |
| 5420 | *this = Persistent<T>(); |
| 5421 | #else |
| 5422 | old = val_; |
| 5423 | val_ = NULL; |
| 5424 | #endif |
| 5425 | return old; |
| 5426 | } |
| 5427 | |
| 5428 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5429 | template <class T> |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5430 | void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5431 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5432 | if (this->IsEmpty()) return; |
| 5433 | if (!I::IsInitialized(isolate)) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5434 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5435 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5436 | *reinterpret_cast<uint16_t*>(addr) = class_id; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5437 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5438 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5439 | template <class T> |
| 5440 | uint16_t Persistent<T>::WrapperClassId() const { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5441 | return WrapperClassId(Isolate::GetCurrent()); |
| 5442 | } |
| 5443 | |
| 5444 | template <class T> |
| 5445 | uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5446 | typedef internal::Internals I; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 5447 | if (this->IsEmpty()) return 0; |
| 5448 | if (!I::IsInitialized(isolate)) return 0; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5449 | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5450 | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; |
| 5451 | return *reinterpret_cast<uint16_t*>(addr); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5454 | Arguments::Arguments(internal::Object** implicit_args, |
| 5455 | internal::Object** values, int length, |
| 5456 | bool is_construct_call) |
| 5457 | : implicit_args_(implicit_args), |
| 5458 | values_(values), |
| 5459 | length_(length), |
| 5460 | is_construct_call_(is_construct_call) { } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5461 | |
| 5462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5463 | Local<Value> Arguments::operator[](int i) const { |
| 5464 | if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 5465 | return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 5466 | } |
| 5467 | |
| 5468 | |
| 5469 | Local<Function> Arguments::Callee() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5470 | return Local<Function>(reinterpret_cast<Function*>( |
| 5471 | &implicit_args_[kCalleeIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | Local<Object> Arguments::This() const { |
| 5476 | return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); |
| 5477 | } |
| 5478 | |
| 5479 | |
| 5480 | Local<Object> Arguments::Holder() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5481 | return Local<Object>(reinterpret_cast<Object*>( |
| 5482 | &implicit_args_[kHolderIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | |
| 5486 | Local<Value> Arguments::Data() const { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5487 | return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5491 | Isolate* Arguments::GetIsolate() const { |
| 5492 | return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); |
| 5493 | } |
| 5494 | |
| 5495 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5496 | bool Arguments::IsConstructCall() const { |
| 5497 | return is_construct_call_; |
| 5498 | } |
| 5499 | |
| 5500 | |
| 5501 | int Arguments::Length() const { |
| 5502 | return length_; |
| 5503 | } |
| 5504 | |
| 5505 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5506 | template <class T> |
| 5507 | Local<T> HandleScope::Close(Handle<T> value) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5508 | internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 5509 | internal::Object** after = RawClose(before); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5510 | return Local<T>(reinterpret_cast<T*>(after)); |
| 5511 | } |
| 5512 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5513 | Handle<Value> ScriptOrigin::ResourceName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5514 | return resource_name_; |
| 5515 | } |
| 5516 | |
| 5517 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5518 | Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5519 | return resource_line_offset_; |
| 5520 | } |
| 5521 | |
| 5522 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5523 | Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5524 | return resource_column_offset_; |
| 5525 | } |
| 5526 | |
| 5527 | |
| 5528 | Handle<Boolean> Boolean::New(bool value) { |
| 5529 | return value ? True() : False(); |
| 5530 | } |
| 5531 | |
| 5532 | |
| 5533 | void Template::Set(const char* name, v8::Handle<Data> value) { |
| 5534 | Set(v8::String::New(name), value); |
| 5535 | } |
| 5536 | |
| 5537 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5538 | Local<Value> Object::GetInternalField(int index) { |
| 5539 | #ifndef V8_ENABLE_CHECKS |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5540 | typedef internal::Object O; |
| 5541 | typedef internal::Internals I; |
| 5542 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5543 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5544 | // 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] | 5545 | if (I::GetInstanceType(obj) == I::kJSObjectType) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5546 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5547 | O* value = I::ReadField<O*>(obj, offset); |
| 5548 | O** result = HandleScope::CreateHandle(value); |
| 5549 | return Local<Value>(reinterpret_cast<Value*>(result)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5550 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5551 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5552 | return SlowGetInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5556 | void* Object::GetAlignedPointerFromInternalField(int index) { |
| 5557 | #ifndef V8_ENABLE_CHECKS |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5558 | typedef internal::Object O; |
| 5559 | typedef internal::Internals I; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5560 | O* obj = *reinterpret_cast<O**>(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5561 | // Fast path: If the object is a plain JSObject, which is the common case, we |
| 5562 | // 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] | 5563 | if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5564 | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5565 | return I::ReadField<void*>(obj, offset); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5566 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5567 | #endif |
| 5568 | return SlowGetAlignedPointerFromInternalField(index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | |
| 5572 | String* String::Cast(v8::Value* value) { |
| 5573 | #ifdef V8_ENABLE_CHECKS |
| 5574 | CheckCast(value); |
| 5575 | #endif |
| 5576 | return static_cast<String*>(value); |
| 5577 | } |
| 5578 | |
| 5579 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5580 | Local<String> String::Empty(Isolate* isolate) { |
| 5581 | typedef internal::Object* S; |
| 5582 | typedef internal::Internals I; |
| 5583 | if (!I::IsInitialized(isolate)) return Empty(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5584 | S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5585 | return Local<String>(reinterpret_cast<String*>(slot)); |
| 5586 | } |
| 5587 | |
| 5588 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5589 | Local<String> String::New(const char* data, int length) { |
| 5590 | return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length); |
| 5591 | } |
| 5592 | |
| 5593 | |
| 5594 | Local<String> String::New(const uint16_t* data, int length) { |
| 5595 | return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length); |
| 5596 | } |
| 5597 | |
| 5598 | |
| 5599 | Local<String> String::NewSymbol(const char* data, int length) { |
| 5600 | return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length); |
| 5601 | } |
| 5602 | |
| 5603 | |
| 5604 | Local<String> String::NewUndetectable(const char* data, int length) { |
| 5605 | return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5606 | } |
| 5607 | |
| 5608 | |
| 5609 | Local<String> String::NewUndetectable(const uint16_t* data, int length) { |
| 5610 | return NewFromTwoByte( |
| 5611 | Isolate::GetCurrent(), data, kUndetectableString, length); |
| 5612 | } |
| 5613 | |
| 5614 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5615 | String::ExternalStringResource* String::GetExternalStringResource() const { |
| 5616 | typedef internal::Object O; |
| 5617 | typedef internal::Internals I; |
| 5618 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5619 | String::ExternalStringResource* result; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5620 | if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5621 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5622 | result = reinterpret_cast<String::ExternalStringResource*>(value); |
| 5623 | } else { |
| 5624 | result = NULL; |
| 5625 | } |
| 5626 | #ifdef V8_ENABLE_CHECKS |
| 5627 | VerifyExternalStringResource(result); |
| 5628 | #endif |
| 5629 | return result; |
| 5630 | } |
| 5631 | |
| 5632 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5633 | String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| 5634 | String::Encoding* encoding_out) const { |
| 5635 | typedef internal::Object O; |
| 5636 | typedef internal::Internals I; |
| 5637 | O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 5638 | int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 5639 | *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| 5640 | ExternalStringResourceBase* resource = NULL; |
| 5641 | if (type == I::kExternalAsciiRepresentationTag || |
| 5642 | type == I::kExternalTwoByteRepresentationTag) { |
| 5643 | void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 5644 | resource = static_cast<ExternalStringResourceBase*>(value); |
| 5645 | } |
| 5646 | #ifdef V8_ENABLE_CHECKS |
| 5647 | VerifyExternalStringResourceBase(resource, *encoding_out); |
| 5648 | #endif |
| 5649 | return resource; |
| 5650 | } |
| 5651 | |
| 5652 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 5653 | bool Value::IsUndefined() const { |
| 5654 | #ifdef V8_ENABLE_CHECKS |
| 5655 | return FullIsUndefined(); |
| 5656 | #else |
| 5657 | return QuickIsUndefined(); |
| 5658 | #endif |
| 5659 | } |
| 5660 | |
| 5661 | bool Value::QuickIsUndefined() const { |
| 5662 | typedef internal::Object O; |
| 5663 | typedef internal::Internals I; |
| 5664 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5665 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5666 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5667 | return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 5668 | } |
| 5669 | |
| 5670 | |
| 5671 | bool Value::IsNull() const { |
| 5672 | #ifdef V8_ENABLE_CHECKS |
| 5673 | return FullIsNull(); |
| 5674 | #else |
| 5675 | return QuickIsNull(); |
| 5676 | #endif |
| 5677 | } |
| 5678 | |
| 5679 | bool Value::QuickIsNull() const { |
| 5680 | typedef internal::Object O; |
| 5681 | typedef internal::Internals I; |
| 5682 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5683 | if (!I::HasHeapObjectTag(obj)) return false; |
| 5684 | if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 5685 | return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 5686 | } |
| 5687 | |
| 5688 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5689 | bool Value::IsString() const { |
| 5690 | #ifdef V8_ENABLE_CHECKS |
| 5691 | return FullIsString(); |
| 5692 | #else |
| 5693 | return QuickIsString(); |
| 5694 | #endif |
| 5695 | } |
| 5696 | |
| 5697 | bool Value::QuickIsString() const { |
| 5698 | typedef internal::Object O; |
| 5699 | typedef internal::Internals I; |
| 5700 | O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 5701 | if (!I::HasHeapObjectTag(obj)) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5702 | return (I::GetInstanceType(obj) < I::kFirstNonstringType); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5706 | Symbol* Symbol::Cast(v8::Value* value) { |
| 5707 | #ifdef V8_ENABLE_CHECKS |
| 5708 | CheckCast(value); |
| 5709 | #endif |
| 5710 | return static_cast<Symbol*>(value); |
| 5711 | } |
| 5712 | |
| 5713 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5714 | Number* Number::Cast(v8::Value* value) { |
| 5715 | #ifdef V8_ENABLE_CHECKS |
| 5716 | CheckCast(value); |
| 5717 | #endif |
| 5718 | return static_cast<Number*>(value); |
| 5719 | } |
| 5720 | |
| 5721 | |
| 5722 | Integer* Integer::Cast(v8::Value* value) { |
| 5723 | #ifdef V8_ENABLE_CHECKS |
| 5724 | CheckCast(value); |
| 5725 | #endif |
| 5726 | return static_cast<Integer*>(value); |
| 5727 | } |
| 5728 | |
| 5729 | |
| 5730 | Date* Date::Cast(v8::Value* value) { |
| 5731 | #ifdef V8_ENABLE_CHECKS |
| 5732 | CheckCast(value); |
| 5733 | #endif |
| 5734 | return static_cast<Date*>(value); |
| 5735 | } |
| 5736 | |
| 5737 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5738 | StringObject* StringObject::Cast(v8::Value* value) { |
| 5739 | #ifdef V8_ENABLE_CHECKS |
| 5740 | CheckCast(value); |
| 5741 | #endif |
| 5742 | return static_cast<StringObject*>(value); |
| 5743 | } |
| 5744 | |
| 5745 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5746 | SymbolObject* SymbolObject::Cast(v8::Value* value) { |
| 5747 | #ifdef V8_ENABLE_CHECKS |
| 5748 | CheckCast(value); |
| 5749 | #endif |
| 5750 | return static_cast<SymbolObject*>(value); |
| 5751 | } |
| 5752 | |
| 5753 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5754 | NumberObject* NumberObject::Cast(v8::Value* value) { |
| 5755 | #ifdef V8_ENABLE_CHECKS |
| 5756 | CheckCast(value); |
| 5757 | #endif |
| 5758 | return static_cast<NumberObject*>(value); |
| 5759 | } |
| 5760 | |
| 5761 | |
| 5762 | BooleanObject* BooleanObject::Cast(v8::Value* value) { |
| 5763 | #ifdef V8_ENABLE_CHECKS |
| 5764 | CheckCast(value); |
| 5765 | #endif |
| 5766 | return static_cast<BooleanObject*>(value); |
| 5767 | } |
| 5768 | |
| 5769 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5770 | RegExp* RegExp::Cast(v8::Value* value) { |
| 5771 | #ifdef V8_ENABLE_CHECKS |
| 5772 | CheckCast(value); |
| 5773 | #endif |
| 5774 | return static_cast<RegExp*>(value); |
| 5775 | } |
| 5776 | |
| 5777 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5778 | Object* Object::Cast(v8::Value* value) { |
| 5779 | #ifdef V8_ENABLE_CHECKS |
| 5780 | CheckCast(value); |
| 5781 | #endif |
| 5782 | return static_cast<Object*>(value); |
| 5783 | } |
| 5784 | |
| 5785 | |
| 5786 | Array* Array::Cast(v8::Value* value) { |
| 5787 | #ifdef V8_ENABLE_CHECKS |
| 5788 | CheckCast(value); |
| 5789 | #endif |
| 5790 | return static_cast<Array*>(value); |
| 5791 | } |
| 5792 | |
| 5793 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5794 | ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { |
| 5795 | #ifdef V8_ENABLE_CHECKS |
| 5796 | CheckCast(value); |
| 5797 | #endif |
| 5798 | return static_cast<ArrayBuffer*>(value); |
| 5799 | } |
| 5800 | |
| 5801 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5802 | TypedArray* TypedArray::Cast(v8::Value* value) { |
| 5803 | #ifdef V8_ENABLE_CHECKS |
| 5804 | CheckCast(value); |
| 5805 | #endif |
| 5806 | return static_cast<TypedArray*>(value); |
| 5807 | } |
| 5808 | |
| 5809 | |
| 5810 | Uint8Array* Uint8Array::Cast(v8::Value* value) { |
| 5811 | #ifdef V8_ENABLE_CHECKS |
| 5812 | CheckCast(value); |
| 5813 | #endif |
| 5814 | return static_cast<Uint8Array*>(value); |
| 5815 | } |
| 5816 | |
| 5817 | |
| 5818 | Int8Array* Int8Array::Cast(v8::Value* value) { |
| 5819 | #ifdef V8_ENABLE_CHECKS |
| 5820 | CheckCast(value); |
| 5821 | #endif |
| 5822 | return static_cast<Int8Array*>(value); |
| 5823 | } |
| 5824 | |
| 5825 | |
| 5826 | Uint16Array* Uint16Array::Cast(v8::Value* value) { |
| 5827 | #ifdef V8_ENABLE_CHECKS |
| 5828 | CheckCast(value); |
| 5829 | #endif |
| 5830 | return static_cast<Uint16Array*>(value); |
| 5831 | } |
| 5832 | |
| 5833 | |
| 5834 | Int16Array* Int16Array::Cast(v8::Value* value) { |
| 5835 | #ifdef V8_ENABLE_CHECKS |
| 5836 | CheckCast(value); |
| 5837 | #endif |
| 5838 | return static_cast<Int16Array*>(value); |
| 5839 | } |
| 5840 | |
| 5841 | |
| 5842 | Uint32Array* Uint32Array::Cast(v8::Value* value) { |
| 5843 | #ifdef V8_ENABLE_CHECKS |
| 5844 | CheckCast(value); |
| 5845 | #endif |
| 5846 | return static_cast<Uint32Array*>(value); |
| 5847 | } |
| 5848 | |
| 5849 | |
| 5850 | Int32Array* Int32Array::Cast(v8::Value* value) { |
| 5851 | #ifdef V8_ENABLE_CHECKS |
| 5852 | CheckCast(value); |
| 5853 | #endif |
| 5854 | return static_cast<Int32Array*>(value); |
| 5855 | } |
| 5856 | |
| 5857 | |
| 5858 | Float32Array* Float32Array::Cast(v8::Value* value) { |
| 5859 | #ifdef V8_ENABLE_CHECKS |
| 5860 | CheckCast(value); |
| 5861 | #endif |
| 5862 | return static_cast<Float32Array*>(value); |
| 5863 | } |
| 5864 | |
| 5865 | |
| 5866 | Float64Array* Float64Array::Cast(v8::Value* value) { |
| 5867 | #ifdef V8_ENABLE_CHECKS |
| 5868 | CheckCast(value); |
| 5869 | #endif |
| 5870 | return static_cast<Float64Array*>(value); |
| 5871 | } |
| 5872 | |
| 5873 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5874 | Function* Function::Cast(v8::Value* value) { |
| 5875 | #ifdef V8_ENABLE_CHECKS |
| 5876 | CheckCast(value); |
| 5877 | #endif |
| 5878 | return static_cast<Function*>(value); |
| 5879 | } |
| 5880 | |
| 5881 | |
| 5882 | External* External::Cast(v8::Value* value) { |
| 5883 | #ifdef V8_ENABLE_CHECKS |
| 5884 | CheckCast(value); |
| 5885 | #endif |
| 5886 | return static_cast<External*>(value); |
| 5887 | } |
| 5888 | |
| 5889 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5890 | Isolate* AccessorInfo::GetIsolate() const { |
| 5891 | return *reinterpret_cast<Isolate**>(&args_[-3]); |
| 5892 | } |
| 5893 | |
| 5894 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5895 | Local<Value> AccessorInfo::Data() const { |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5896 | return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | |
| 5900 | Local<Object> AccessorInfo::This() const { |
| 5901 | return Local<Object>(reinterpret_cast<Object*>(&args_[0])); |
| 5902 | } |
| 5903 | |
| 5904 | |
| 5905 | Local<Object> AccessorInfo::Holder() const { |
| 5906 | return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); |
| 5907 | } |
| 5908 | |
| 5909 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5910 | Handle<Primitive> Undefined(Isolate* isolate) { |
| 5911 | typedef internal::Object* S; |
| 5912 | typedef internal::Internals I; |
| 5913 | if (!I::IsInitialized(isolate)) return Undefined(); |
| 5914 | S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
| 5915 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5916 | } |
| 5917 | |
| 5918 | |
| 5919 | Handle<Primitive> Null(Isolate* isolate) { |
| 5920 | typedef internal::Object* S; |
| 5921 | typedef internal::Internals I; |
| 5922 | if (!I::IsInitialized(isolate)) return Null(); |
| 5923 | S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
| 5924 | return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
| 5925 | } |
| 5926 | |
| 5927 | |
| 5928 | Handle<Boolean> True(Isolate* isolate) { |
| 5929 | typedef internal::Object* S; |
| 5930 | typedef internal::Internals I; |
| 5931 | if (!I::IsInitialized(isolate)) return True(); |
| 5932 | S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
| 5933 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5934 | } |
| 5935 | |
| 5936 | |
| 5937 | Handle<Boolean> False(Isolate* isolate) { |
| 5938 | typedef internal::Object* S; |
| 5939 | typedef internal::Internals I; |
| 5940 | if (!I::IsInitialized(isolate)) return False(); |
| 5941 | S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
| 5942 | return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
| 5943 | } |
| 5944 | |
| 5945 | |
| 5946 | void Isolate::SetData(void* data) { |
| 5947 | typedef internal::Internals I; |
| 5948 | I::SetEmbedderData(this, data); |
| 5949 | } |
| 5950 | |
| 5951 | |
| 5952 | void* Isolate::GetData() { |
| 5953 | typedef internal::Internals I; |
| 5954 | return I::GetEmbedderData(this); |
| 5955 | } |
| 5956 | |
| 5957 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5958 | Local<Value> Context::GetEmbedderData(int index) { |
| 5959 | #ifndef V8_ENABLE_CHECKS |
| 5960 | typedef internal::Object O; |
| 5961 | typedef internal::Internals I; |
| 5962 | O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); |
| 5963 | return Local<Value>(reinterpret_cast<Value*>(result)); |
| 5964 | #else |
| 5965 | return SlowGetEmbedderData(index); |
| 5966 | #endif |
| 5967 | } |
| 5968 | |
| 5969 | |
| 5970 | void* Context::GetAlignedPointerFromEmbedderData(int index) { |
| 5971 | #ifndef V8_ENABLE_CHECKS |
| 5972 | typedef internal::Internals I; |
| 5973 | return I::ReadEmbedderData<void*>(this, index); |
| 5974 | #else |
| 5975 | return SlowGetAlignedPointerFromEmbedderData(index); |
| 5976 | #endif |
| 5977 | } |
| 5978 | |
| 5979 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5980 | /** |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5981 | * \example shell.cc |
| 5982 | * A simple shell that takes a list of expressions on the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5983 | * command-line and executes them. |
| 5984 | */ |
| 5985 | |
| 5986 | |
| 5987 | /** |
| 5988 | * \example process.cc |
| 5989 | */ |
| 5990 | |
| 5991 | |
| 5992 | } // namespace v8 |
| 5993 | |
| 5994 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5995 | #undef V8EXPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5996 | #undef TYPE_CHECK |
| 5997 | |
| 5998 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5999 | #endif // V8_H_ |