jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
| 28 | #ifndef V8_HANDLES_H_ |
| 29 | #define V8_HANDLES_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 32 | #include "apiutils.h" |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 33 | #include "objects.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | // A Handle provides a reference to an object that survives relocation by |
| 40 | // the garbage collector. |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 41 | // Handles are only valid within a HandleScope. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | // When a handle is created for an object a cell is allocated in the heap. |
| 43 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 44 | template<typename T> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | class Handle { |
| 46 | public: |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 47 | INLINE(explicit Handle(T** location)) { location_ = location; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | INLINE(explicit Handle(T* obj)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 49 | INLINE(Handle(T* obj, Isolate* isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
| 51 | INLINE(Handle()) : location_(NULL) {} |
| 52 | |
| 53 | // Constructor for handling automatic up casting. |
| 54 | // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. |
| 55 | template <class S> Handle(Handle<S> handle) { |
| 56 | #ifdef DEBUG |
| 57 | T* a = NULL; |
| 58 | S* b = NULL; |
| 59 | a = b; // Fake assignment to enforce type checks. |
| 60 | USE(a); |
| 61 | #endif |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 62 | location_ = reinterpret_cast<T**>(handle.location_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | } |
| 64 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 65 | INLINE(T* operator->() const) { return operator*(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | |
| 67 | // Check if this handle refers to the exact same object as the other handle. |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 68 | INLINE(bool is_identical_to(const Handle<T> other) const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | |
| 70 | // Provides the C++ dereference operator. |
| 71 | INLINE(T* operator*() const); |
| 72 | |
| 73 | // Returns the address to where the raw pointer is stored. |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 74 | INLINE(T** location() const); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | |
| 76 | template <class S> static Handle<T> cast(Handle<S> that) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 77 | T::cast(*reinterpret_cast<T**>(that.location_)); |
| 78 | return Handle<T>(reinterpret_cast<T**>(that.location_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static Handle<T> null() { return Handle<T>(); } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | bool is_null() const { return location_ == NULL; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 83 | |
| 84 | // Closes the given scope, but lets this handle escape. See |
| 85 | // implementation in api.h. |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 86 | inline Handle<T> EscapeFrom(v8::HandleScope* scope); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 88 | #ifdef DEBUG |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 89 | enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK }; |
| 90 | |
| 91 | bool IsDereferenceAllowed(DereferenceCheckMode mode) const; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 92 | #endif // DEBUG |
| 93 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | private: |
| 95 | T** location_; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 96 | |
| 97 | // Handles of different classes are allowed to access each other's location_. |
| 98 | template<class S> friend class Handle; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 102 | // Convenience wrapper. |
| 103 | template<class T> |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 104 | inline Handle<T> handle(T* t, Isolate* isolate) { |
| 105 | return Handle<T>(t, isolate); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 109 | // Convenience wrapper. |
| 110 | template<class T> |
| 111 | inline Handle<T> handle(T* t) { |
| 112 | return Handle<T>(t, t->GetIsolate()); |
| 113 | } |
| 114 | |
| 115 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 116 | class DeferredHandles; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 117 | class HandleScopeImplementer; |
| 118 | |
| 119 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 120 | // A stack-allocated class that governs a number of local handles. |
| 121 | // After a handle scope has been created, all local handles will be |
| 122 | // allocated within that handle scope until either the handle scope is |
| 123 | // deleted or another handle scope is created. If there is already a |
| 124 | // handle scope and a new one is created, all allocations will take |
| 125 | // place in the new handle scope until it is deleted. After that, |
| 126 | // new handles will again be allocated in the original handle scope. |
| 127 | // |
| 128 | // After the handle scope of a local handle has been deleted the |
| 129 | // garbage collector will no longer track the object stored in the |
| 130 | // handle and may deallocate it. The behavior of accessing a handle |
| 131 | // for which the handle scope has been deleted is undefined. |
| 132 | class HandleScope { |
| 133 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 134 | explicit inline HandleScope(Isolate* isolate); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 135 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 136 | inline ~HandleScope(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 137 | |
| 138 | // Counts the number of allocated handles. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 139 | static int NumberOfHandles(Isolate* isolate); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 140 | |
| 141 | // Creates a new handle with the given value. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 142 | template <typename T> |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 143 | static inline T** CreateHandle(Isolate* isolate, T* value); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 144 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 145 | // Deallocates any extensions used by the current scope. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 146 | static void DeleteExtensions(Isolate* isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 147 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 148 | static Address current_next_address(Isolate* isolate); |
| 149 | static Address current_limit_address(Isolate* isolate); |
| 150 | static Address current_level_address(Isolate* isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 151 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 152 | // Closes the HandleScope (invalidating all handles |
| 153 | // created in the scope of the HandleScope) and returns |
| 154 | // a Handle backed by the parent scope holding the |
| 155 | // value of the argument handle. |
| 156 | template <typename T> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 157 | Handle<T> CloseAndEscape(Handle<T> handle_value); |
| 158 | |
| 159 | Isolate* isolate() { return isolate_; } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 160 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 161 | private: |
| 162 | // Prevent heap allocation or illegal handle scopes. |
| 163 | HandleScope(const HandleScope&); |
| 164 | void operator=(const HandleScope&); |
| 165 | void* operator new(size_t size); |
| 166 | void operator delete(void* size_t); |
| 167 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 168 | Isolate* isolate_; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 169 | Object** prev_next_; |
| 170 | Object** prev_limit_; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 171 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 172 | // Close the handle scope resetting limits to a previous state. |
| 173 | static inline void CloseScope(Isolate* isolate, |
| 174 | Object** prev_next, |
| 175 | Object** prev_limit); |
| 176 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 177 | // Extend the handle scope making room for more handles. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 178 | static internal::Object** Extend(Isolate* isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 179 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 180 | #ifdef ENABLE_HANDLE_ZAPPING |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 181 | // Zaps the handles in the half-open interval [start, end). |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 182 | static void ZapRange(Object** start, Object** end); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 183 | #endif |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 184 | |
| 185 | friend class v8::HandleScope; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 186 | friend class v8::internal::DeferredHandles; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 187 | friend class v8::internal::HandleScopeImplementer; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 188 | friend class v8::internal::Isolate; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 192 | class DeferredHandles; |
| 193 | |
| 194 | |
| 195 | class DeferredHandleScope { |
| 196 | public: |
| 197 | explicit DeferredHandleScope(Isolate* isolate); |
| 198 | // The DeferredHandles object returned stores the Handles created |
| 199 | // since the creation of this DeferredHandleScope. The Handles are |
| 200 | // alive as long as the DeferredHandles object is alive. |
| 201 | DeferredHandles* Detach(); |
| 202 | ~DeferredHandleScope(); |
| 203 | |
| 204 | private: |
| 205 | Object** prev_limit_; |
| 206 | Object** prev_next_; |
| 207 | HandleScopeImplementer* impl_; |
| 208 | |
| 209 | #ifdef DEBUG |
| 210 | bool handles_detached_; |
| 211 | int prev_level_; |
| 212 | #endif |
| 213 | |
| 214 | friend class HandleScopeImplementer; |
| 215 | }; |
| 216 | |
| 217 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 218 | // ---------------------------------------------------------------------------- |
| 219 | // Handle operations. |
| 220 | // They might invoke garbage collection. The result is an handle to |
| 221 | // an object of expected type, or the handle is an error if running out |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 222 | // of space or encountering an internal error. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 224 | // Flattens a string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | void FlattenString(Handle<String> str); |
| 226 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 227 | // Flattens a string and returns the underlying external or sequential |
| 228 | // string. |
| 229 | Handle<String> FlattenGetString(Handle<String> str); |
| 230 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 231 | Handle<Object> SetProperty(Isolate* isolate, |
| 232 | Handle<Object> object, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | Handle<Object> key, |
| 234 | Handle<Object> value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 235 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 236 | StrictModeFlag strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 238 | Handle<Object> ForceSetProperty(Handle<JSObject> object, |
| 239 | Handle<Object> key, |
| 240 | Handle<Object> value, |
| 241 | PropertyAttributes attributes); |
| 242 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 243 | Handle<Object> DeleteProperty(Handle<JSObject> object, Handle<Object> key); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 244 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 245 | Handle<Object> ForceDeleteProperty(Handle<JSObject> object, Handle<Object> key); |
| 246 | |
| 247 | Handle<Object> HasProperty(Handle<JSReceiver> obj, Handle<Object> key); |
| 248 | |
| 249 | Handle<Object> GetProperty(Handle<JSReceiver> obj, const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 251 | Handle<Object> GetProperty(Isolate* isolate, |
| 252 | Handle<Object> obj, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | Handle<Object> key); |
| 254 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 255 | Handle<Object> LookupSingleCharacterStringFromCode(Isolate* isolate, |
| 256 | uint32_t index); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 257 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 258 | Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray>, |
| 259 | Handle<JSArray> array); |
| 260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | // Get the JS object corresponding to the given script; create it |
| 262 | // if none exists. |
| 263 | Handle<JSValue> GetScriptWrapper(Handle<Script> script); |
| 264 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 265 | // Script line number computations. Note that the line number is zero-based. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 266 | void InitScriptLineEnds(Handle<Script> script); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 267 | // For string calculates an array of line end positions. If the string |
| 268 | // does not end with a new line character, this character may optionally be |
| 269 | // imagined. |
| 270 | Handle<FixedArray> CalculateLineEnds(Handle<String> string, |
| 271 | bool with_imaginary_last_new_line); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 272 | int GetScriptLineNumber(Handle<Script> script, int code_position); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 273 | // The safe version does not make heap allocations but may work much slower. |
| 274 | int GetScriptLineNumberSafe(Handle<Script> script, int code_position); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 275 | int GetScriptColumnNumber(Handle<Script> script, int code_position); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 276 | Handle<Object> GetScriptNameOrSourceURL(Handle<Script> script); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 277 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | // Computes the enumerable keys from interceptors. Used for debug mirrors and |
| 279 | // by GetKeysInFixedArrayFor below. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 280 | v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | Handle<JSObject> object); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 282 | v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | Handle<JSObject> object); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 284 | |
| 285 | enum KeyCollectionType { LOCAL_ONLY, INCLUDE_PROTOS }; |
| 286 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | // Computes the enumerable keys for a JSObject. Used for implementing |
| 288 | // "for (n in object) { }". |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 289 | Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object, |
| 290 | KeyCollectionType type, |
| 291 | bool* threw); |
| 292 | Handle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 293 | Handle<FixedArray> ReduceFixedArrayTo(Handle<FixedArray> array, int length); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 294 | Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, |
| 295 | bool cache_result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | |
| 297 | // Computes the union of keys and return the result. |
| 298 | // Used for implementing "for (n in object) { }" |
| 299 | Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first, |
| 300 | Handle<FixedArray> second); |
| 301 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 302 | // Sets the expected number of properties for the function's instances. |
| 303 | void SetExpectedNofProperties(Handle<JSFunction> func, int nof); |
| 304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | // Sets the expected number of properties based on estimate from compiler. |
| 306 | void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared, |
| 307 | int estimate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | |
| 309 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 310 | Handle<JSGlobalProxy> ReinitializeJSGlobalProxy( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 311 | Handle<JSFunction> constructor, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 312 | Handle<JSGlobalProxy> global); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 314 | Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table, |
| 315 | Handle<Object> key); |
| 316 | |
| 317 | Handle<ObjectHashSet> ObjectHashSetRemove(Handle<ObjectHashSet> table, |
| 318 | Handle<Object> key); |
| 319 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 320 | Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 321 | Handle<Object> key, |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 322 | Handle<Object> value); |
| 323 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 324 | void AddWeakObjectToCodeDependency(Heap* heap, |
| 325 | Handle<Object> object, |
| 326 | Handle<Code> code); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 327 | |
| 328 | // Seal off the current HandleScope so that new handles can only be created |
| 329 | // if a new HandleScope is entered. |
| 330 | class SealHandleScope BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | public: |
| 332 | #ifndef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 333 | explicit SealHandleScope(Isolate* isolate) {} |
| 334 | ~SealHandleScope() {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 335 | #else |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 336 | explicit inline SealHandleScope(Isolate* isolate); |
| 337 | inline ~SealHandleScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | private: |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 339 | Isolate* isolate_; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 340 | Object** limit_; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 341 | int level_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | #endif |
| 343 | }; |
| 344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | } } // namespace v8::internal |
| 346 | |
| 347 | #endif // V8_HANDLES_H_ |