karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +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 | #include "v8.h" |
| 29 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 30 | #include "bootstrapper.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 31 | #include "debug.h" |
| 32 | #include "scopeinfo.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 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 37 | Context* Context::declaration_context() { |
| 38 | Context* current = this; |
| 39 | while (!current->IsFunctionContext() && !current->IsGlobalContext()) { |
| 40 | current = current->previous(); |
| 41 | ASSERT(current->closure() == closure()); |
| 42 | } |
| 43 | return current; |
| 44 | } |
| 45 | |
| 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | JSBuiltinsObject* Context::builtins() { |
| 48 | GlobalObject* object = global(); |
| 49 | if (object->IsJSGlobalObject()) { |
| 50 | return JSGlobalObject::cast(object)->builtins(); |
| 51 | } else { |
| 52 | ASSERT(object->IsJSBuiltinsObject()); |
| 53 | return JSBuiltinsObject::cast(object); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | Context* Context::global_context() { |
| 59 | // Fast case: the global object for this context has been set. In |
| 60 | // that case, the global object has a direct pointer to the global |
| 61 | // context. |
| 62 | if (global()->IsGlobalObject()) { |
| 63 | return global()->global_context(); |
| 64 | } |
kasperl@chromium.org | 7b9eafd | 2009-12-21 15:20:30 +0000 | [diff] [blame] | 65 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | // During bootstrapping, the global object might not be set and we |
| 67 | // have to search the context chain to find the global context. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | ASSERT(Isolate::Current()->bootstrapper()->IsActive()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | Context* current = this; |
| 70 | while (!current->IsGlobalContext()) { |
kasperl@chromium.org | 7b9eafd | 2009-12-21 15:20:30 +0000 | [diff] [blame] | 71 | JSFunction* closure = JSFunction::cast(current->closure()); |
| 72 | current = Context::cast(closure->context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 73 | } |
| 74 | return current; |
| 75 | } |
| 76 | |
| 77 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 78 | JSObject* Context::global_proxy() { |
| 79 | return global_context()->global_proxy_object(); |
| 80 | } |
| 81 | |
| 82 | void Context::set_global_proxy(JSObject* object) { |
| 83 | global_context()->set_global_proxy_object(object); |
| 84 | } |
| 85 | |
| 86 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 87 | Handle<Object> Context::Lookup(Handle<String> name, |
| 88 | ContextLookupFlags flags, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 89 | int* index, |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 90 | PropertyAttributes* attributes, |
| 91 | BindingFlags* binding_flags) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 92 | Isolate* isolate = GetIsolate(); |
| 93 | Handle<Context> context(this, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 96 | *index = -1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | *attributes = ABSENT; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 98 | *binding_flags = MISSING_BINDING; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | |
| 100 | if (FLAG_trace_contexts) { |
| 101 | PrintF("Context::Lookup("); |
| 102 | name->ShortPrint(); |
| 103 | PrintF(")\n"); |
| 104 | } |
| 105 | |
| 106 | do { |
| 107 | if (FLAG_trace_contexts) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 108 | PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | if (context->IsGlobalContext()) PrintF(" (global context)"); |
| 110 | PrintF("\n"); |
| 111 | } |
| 112 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 113 | // 1. Check global objects, subjects of with, and extension objects. |
| 114 | if (context->IsGlobalContext() || |
| 115 | context->IsWithContext() || |
| 116 | (context->IsFunctionContext() && context->has_extension())) { |
| 117 | Handle<JSObject> object(JSObject::cast(context->extension()), isolate); |
| 118 | // Context extension objects needs to behave as if they have no |
| 119 | // prototype. So even if we want to follow prototype chains, we need |
| 120 | // to only do a local lookup for context extension objects. |
| 121 | if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
| 122 | object->IsJSContextExtensionObject()) { |
| 123 | *attributes = object->GetLocalPropertyAttribute(*name); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 124 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 125 | *attributes = object->GetPropertyAttribute(*name); |
| 126 | } |
| 127 | if (*attributes != ABSENT) { |
| 128 | if (FLAG_trace_contexts) { |
| 129 | PrintF("=> found property in context object %p\n", |
| 130 | reinterpret_cast<void*>(*object)); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 131 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 132 | return object; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 136 | // 2. Check the context proper if it has slots. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 137 | if (context->IsFunctionContext() || context->IsBlockContext()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 138 | // Use serialized scope information of functions and blocks to search |
| 139 | // for the context index. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 140 | Handle<ScopeInfo> scope_info; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 141 | if (context->IsFunctionContext()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 142 | scope_info = Handle<ScopeInfo>( |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 143 | context->closure()->shared()->scope_info(), isolate); |
| 144 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 145 | scope_info = Handle<ScopeInfo>( |
| 146 | ScopeInfo::cast(context->extension()), isolate); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 147 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 148 | VariableMode mode; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 149 | InitializationFlag init_flag; |
| 150 | int slot_index = scope_info->ContextSlotIndex(*name, &mode, &init_flag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 151 | ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); |
| 152 | if (slot_index >= 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | if (FLAG_trace_contexts) { |
| 154 | PrintF("=> found local in context slot %d (mode = %d)\n", |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 155 | slot_index, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 157 | *index = slot_index; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | // Note: Fixed context slots are statically allocated by the compiler. |
| 159 | // Statically allocated variables always have a statically known mode, |
| 160 | // which is the mode with which they were declared when added to the |
| 161 | // scope. Thus, the DYNAMIC mode (which corresponds to dynamically |
| 162 | // declared variables that were introduced through declaration nodes) |
| 163 | // must not appear here. |
| 164 | switch (mode) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 165 | case INTERNAL: // Fall through. |
| 166 | case VAR: |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 167 | *attributes = NONE; |
| 168 | *binding_flags = MUTABLE_IS_INITIALIZED; |
| 169 | break; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 170 | case LET: |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 171 | *attributes = NONE; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 172 | *binding_flags = (init_flag == kNeedsInitialization) |
| 173 | ? MUTABLE_CHECK_INITIALIZED : MUTABLE_IS_INITIALIZED; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 174 | break; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 175 | case CONST: |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 176 | *attributes = READ_ONLY; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 177 | *binding_flags = (init_flag == kNeedsInitialization) |
| 178 | ? IMMUTABLE_CHECK_INITIALIZED : IMMUTABLE_IS_INITIALIZED; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 179 | break; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 180 | case CONST_HARMONY: |
| 181 | *attributes = READ_ONLY; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 182 | *binding_flags = (init_flag == kNeedsInitialization) |
| 183 | ? IMMUTABLE_CHECK_INITIALIZED_HARMONY : |
| 184 | IMMUTABLE_IS_INITIALIZED_HARMONY; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 185 | break; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 186 | case DYNAMIC: |
| 187 | case DYNAMIC_GLOBAL: |
| 188 | case DYNAMIC_LOCAL: |
| 189 | case TEMPORARY: |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 190 | UNREACHABLE(); |
| 191 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 192 | } |
| 193 | return context; |
| 194 | } |
| 195 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 196 | // Check the slot corresponding to the intermediate context holding |
| 197 | // only the function name variable. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 198 | if (follow_context_chain && context->IsFunctionContext()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 199 | VariableMode mode; |
| 200 | int function_index = scope_info->FunctionContextSlotIndex(*name, &mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 201 | if (function_index >= 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | if (FLAG_trace_contexts) { |
| 203 | PrintF("=> found intermediate function in context slot %d\n", |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 204 | function_index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 206 | *index = function_index; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | *attributes = READ_ONLY; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 208 | ASSERT(mode == CONST || mode == CONST_HARMONY); |
| 209 | *binding_flags = (mode == CONST) |
| 210 | ? IMMUTABLE_IS_INITIALIZED : IMMUTABLE_IS_INITIALIZED_HARMONY; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | return context; |
| 212 | } |
| 213 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 214 | |
| 215 | } else if (context->IsCatchContext()) { |
| 216 | // Catch contexts have the variable name in the extension slot. |
| 217 | if (name->Equals(String::cast(context->extension()))) { |
| 218 | if (FLAG_trace_contexts) { |
| 219 | PrintF("=> found in catch context\n"); |
| 220 | } |
| 221 | *index = Context::THROWN_OBJECT_INDEX; |
| 222 | *attributes = NONE; |
| 223 | *binding_flags = MUTABLE_IS_INITIALIZED; |
| 224 | return context; |
| 225 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 226 | } |
| 227 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 228 | // 3. Prepare to continue with the previous (next outermost) context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | if (context->IsGlobalContext()) { |
| 230 | follow_context_chain = false; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 231 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 232 | context = Handle<Context>(context->previous(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | } |
| 234 | } while (follow_context_chain); |
| 235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | if (FLAG_trace_contexts) { |
| 237 | PrintF("=> no property/slot found\n"); |
| 238 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 239 | return Handle<Object>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 243 | void Context::AddOptimizedFunction(JSFunction* function) { |
| 244 | ASSERT(IsGlobalContext()); |
| 245 | #ifdef DEBUG |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame^] | 246 | if (FLAG_enable_slow_asserts) { |
| 247 | Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 248 | while (!element->IsUndefined()) { |
| 249 | CHECK(element != function); |
| 250 | element = JSFunction::cast(element)->next_function_link(); |
| 251 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | CHECK(function->next_function_link()->IsUndefined()); |
| 255 | |
| 256 | // Check that the context belongs to the weak global contexts list. |
| 257 | bool found = false; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 258 | Object* context = GetHeap()->global_contexts_list(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 259 | while (!context->IsUndefined()) { |
| 260 | if (context == this) { |
| 261 | found = true; |
| 262 | break; |
| 263 | } |
| 264 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
| 265 | } |
| 266 | CHECK(found); |
| 267 | #endif |
| 268 | function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); |
| 269 | set(OPTIMIZED_FUNCTIONS_LIST, function); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | void Context::RemoveOptimizedFunction(JSFunction* function) { |
| 274 | ASSERT(IsGlobalContext()); |
| 275 | Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 276 | JSFunction* prev = NULL; |
| 277 | while (!element->IsUndefined()) { |
| 278 | JSFunction* element_function = JSFunction::cast(element); |
| 279 | ASSERT(element_function->next_function_link()->IsUndefined() || |
| 280 | element_function->next_function_link()->IsJSFunction()); |
| 281 | if (element_function == function) { |
| 282 | if (prev == NULL) { |
| 283 | set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); |
| 284 | } else { |
| 285 | prev->set_next_function_link(element_function->next_function_link()); |
| 286 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 287 | element_function->set_next_function_link(GetHeap()->undefined_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | prev = element_function; |
| 291 | element = element_function->next_function_link(); |
| 292 | } |
| 293 | UNREACHABLE(); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | Object* Context::OptimizedFunctionsListHead() { |
| 298 | ASSERT(IsGlobalContext()); |
| 299 | return get(OPTIMIZED_FUNCTIONS_LIST); |
| 300 | } |
| 301 | |
| 302 | |
| 303 | void Context::ClearOptimizedFunctions() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 304 | set(OPTIMIZED_FUNCTIONS_LIST, GetHeap()->undefined_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 308 | #ifdef DEBUG |
| 309 | bool Context::IsBootstrappingOrContext(Object* object) { |
| 310 | // During bootstrapping we allow all objects to pass as |
| 311 | // contexts. This is necessary to fix circular dependencies. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 312 | return Isolate::Current()->bootstrapper()->IsActive() || object->IsContext(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
| 316 | bool Context::IsBootstrappingOrGlobalObject(Object* object) { |
| 317 | // During bootstrapping we allow all objects to pass as global |
| 318 | // objects. This is necessary to fix circular dependencies. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 319 | Isolate* isolate = Isolate::Current(); |
| 320 | return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 321 | isolate->bootstrapper()->IsActive() || |
| 322 | object->IsGlobalObject(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 323 | } |
| 324 | #endif |
| 325 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | } } // namespace v8::internal |