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