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, |
| 89 | int* index_, |
| 90 | PropertyAttributes* attributes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | Isolate* isolate = GetIsolate(); |
| 92 | Handle<Context> context(this, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
| 95 | *index_ = -1; |
| 96 | *attributes = ABSENT; |
| 97 | |
| 98 | if (FLAG_trace_contexts) { |
| 99 | PrintF("Context::Lookup("); |
| 100 | name->ShortPrint(); |
| 101 | PrintF(")\n"); |
| 102 | } |
| 103 | |
| 104 | do { |
| 105 | if (FLAG_trace_contexts) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 106 | PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | if (context->IsGlobalContext()) PrintF(" (global context)"); |
| 108 | PrintF("\n"); |
| 109 | } |
| 110 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 111 | // Check extension/with/global object. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame^] | 112 | if (!context->IsBlockContext() && context->has_extension()) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 113 | if (context->IsCatchContext()) { |
| 114 | // Catch contexts have the variable name in the extension slot. |
| 115 | if (name->Equals(String::cast(context->extension()))) { |
| 116 | if (FLAG_trace_contexts) { |
| 117 | PrintF("=> found in catch context\n"); |
| 118 | } |
| 119 | *index_ = Context::THROWN_OBJECT_INDEX; |
| 120 | *attributes = NONE; |
| 121 | return context; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 123 | } else { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame^] | 124 | ASSERT(context->IsGlobalContext() || |
| 125 | context->IsFunctionContext() || |
| 126 | context->IsWithContext()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 127 | // Global, function, and with contexts may have an object in the |
| 128 | // extension slot. |
| 129 | Handle<JSObject> extension(JSObject::cast(context->extension()), |
| 130 | isolate); |
| 131 | // Context extension objects needs to behave as if they have no |
| 132 | // prototype. So even if we want to follow prototype chains, we |
| 133 | // need to only do a local lookup for context extension objects. |
| 134 | if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
| 135 | extension->IsJSContextExtensionObject()) { |
| 136 | *attributes = extension->GetLocalPropertyAttribute(*name); |
| 137 | } else { |
| 138 | *attributes = extension->GetPropertyAttribute(*name); |
| 139 | } |
| 140 | if (*attributes != ABSENT) { |
| 141 | // property found |
| 142 | if (FLAG_trace_contexts) { |
| 143 | PrintF("=> found property in context object %p\n", |
| 144 | reinterpret_cast<void*>(*extension)); |
| 145 | } |
| 146 | return extension; |
| 147 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame^] | 151 | // Check serialized scope information of functions and blocks. Only |
| 152 | // functions can have parameters, and a function name. |
| 153 | if (context->IsFunctionContext() || context->IsBlockContext()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 154 | // We may have context-local slots. Check locals in the context. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame^] | 155 | Handle<SerializedScopeInfo> scope_info; |
| 156 | if (context->IsFunctionContext()) { |
| 157 | scope_info = Handle<SerializedScopeInfo>( |
| 158 | context->closure()->shared()->scope_info(), isolate); |
| 159 | } else { |
| 160 | ASSERT(context->IsBlockContext()); |
| 161 | scope_info = Handle<SerializedScopeInfo>( |
| 162 | SerializedScopeInfo::cast(context->extension()), isolate); |
| 163 | } |
| 164 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | Variable::Mode mode; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 166 | int index = scope_info->ContextSlotIndex(*name, &mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 168 | if (index >= 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | if (FLAG_trace_contexts) { |
| 170 | PrintF("=> found local in context slot %d (mode = %d)\n", |
| 171 | index, mode); |
| 172 | } |
| 173 | *index_ = index; |
| 174 | // Note: Fixed context slots are statically allocated by the compiler. |
| 175 | // Statically allocated variables always have a statically known mode, |
| 176 | // which is the mode with which they were declared when added to the |
| 177 | // scope. Thus, the DYNAMIC mode (which corresponds to dynamically |
| 178 | // declared variables that were introduced through declaration nodes) |
| 179 | // must not appear here. |
| 180 | switch (mode) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 181 | case Variable::INTERNAL: // Fall through. |
| 182 | case Variable::VAR: |
| 183 | *attributes = NONE; |
| 184 | break; |
| 185 | case Variable::CONST: |
| 186 | *attributes = READ_ONLY; |
| 187 | break; |
| 188 | case Variable::DYNAMIC: |
| 189 | case Variable::DYNAMIC_GLOBAL: |
| 190 | case Variable::DYNAMIC_LOCAL: |
| 191 | case Variable::TEMPORARY: |
| 192 | UNREACHABLE(); |
| 193 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | } |
| 195 | return context; |
| 196 | } |
| 197 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 198 | // Check the slot corresponding to the intermediate context holding |
| 199 | // only the function name variable. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | if (follow_context_chain) { |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 201 | int index = scope_info->FunctionContextSlotIndex(*name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | if (index >= 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | if (FLAG_trace_contexts) { |
| 204 | PrintF("=> found intermediate function in context slot %d\n", |
| 205 | index); |
| 206 | } |
| 207 | *index_ = index; |
| 208 | *attributes = READ_ONLY; |
| 209 | return context; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 214 | // Proceed with the previous context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | if (context->IsGlobalContext()) { |
| 216 | follow_context_chain = false; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 217 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 218 | context = Handle<Context>(context->previous(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | } |
| 220 | } while (follow_context_chain); |
| 221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | if (FLAG_trace_contexts) { |
| 223 | PrintF("=> no property/slot found\n"); |
| 224 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 225 | return Handle<Object>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 229 | bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { |
| 230 | Context* context = this; |
| 231 | |
| 232 | // Check that there is no local with the given name in contexts |
| 233 | // before the global context and check that there are no context |
| 234 | // extension objects (conservative check for with statements). |
| 235 | while (!context->IsGlobalContext()) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 236 | // Check if the context is a catch or with context, or has introduced |
| 237 | // bindings by calling non-strict eval. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 238 | if (context->has_extension()) return false; |
| 239 | |
| 240 | // Not a with context so it must be a function context. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 241 | ASSERT(context->IsFunctionContext()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 242 | |
| 243 | // Check non-parameter locals. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 244 | Handle<SerializedScopeInfo> scope_info( |
| 245 | context->closure()->shared()->scope_info()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 246 | Variable::Mode mode; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 247 | int index = scope_info->ContextSlotIndex(*name, &mode); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 248 | ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 249 | if (index >= 0) return false; |
| 250 | |
| 251 | // Check parameter locals. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 252 | int param_index = scope_info->ParameterIndex(*name); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 253 | if (param_index >= 0) return false; |
| 254 | |
| 255 | // Check context only holding the function name variable. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 256 | index = scope_info->FunctionContextSlotIndex(*name); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 257 | if (index >= 0) return false; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 258 | context = context->previous(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // No local or potential with statement found so the variable is |
| 262 | // global unless it is shadowed by an eval-introduced variable. |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 267 | void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_eval, |
| 268 | bool* outer_scope_calls_non_strict_eval) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 269 | // Skip up the context chain checking all the function contexts to see |
| 270 | // whether they call eval. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 271 | Context* context = this; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 272 | while (!context->IsGlobalContext()) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 273 | if (context->IsFunctionContext()) { |
| 274 | Handle<SerializedScopeInfo> scope_info( |
| 275 | context->closure()->shared()->scope_info()); |
| 276 | if (scope_info->CallsEval()) { |
| 277 | *outer_scope_calls_eval = true; |
| 278 | if (!scope_info->IsStrictMode()) { |
| 279 | // No need to go further since the answers will not change from |
| 280 | // here. |
| 281 | *outer_scope_calls_non_strict_eval = true; |
| 282 | return; |
| 283 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 286 | context = context->previous(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | void Context::AddOptimizedFunction(JSFunction* function) { |
| 292 | ASSERT(IsGlobalContext()); |
| 293 | #ifdef DEBUG |
| 294 | Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 295 | while (!element->IsUndefined()) { |
| 296 | CHECK(element != function); |
| 297 | element = JSFunction::cast(element)->next_function_link(); |
| 298 | } |
| 299 | |
| 300 | CHECK(function->next_function_link()->IsUndefined()); |
| 301 | |
| 302 | // Check that the context belongs to the weak global contexts list. |
| 303 | bool found = false; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 304 | Object* context = GetHeap()->global_contexts_list(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 305 | while (!context->IsUndefined()) { |
| 306 | if (context == this) { |
| 307 | found = true; |
| 308 | break; |
| 309 | } |
| 310 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
| 311 | } |
| 312 | CHECK(found); |
| 313 | #endif |
| 314 | function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); |
| 315 | set(OPTIMIZED_FUNCTIONS_LIST, function); |
| 316 | } |
| 317 | |
| 318 | |
| 319 | void Context::RemoveOptimizedFunction(JSFunction* function) { |
| 320 | ASSERT(IsGlobalContext()); |
| 321 | Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 322 | JSFunction* prev = NULL; |
| 323 | while (!element->IsUndefined()) { |
| 324 | JSFunction* element_function = JSFunction::cast(element); |
| 325 | ASSERT(element_function->next_function_link()->IsUndefined() || |
| 326 | element_function->next_function_link()->IsJSFunction()); |
| 327 | if (element_function == function) { |
| 328 | if (prev == NULL) { |
| 329 | set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); |
| 330 | } else { |
| 331 | prev->set_next_function_link(element_function->next_function_link()); |
| 332 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 333 | element_function->set_next_function_link(GetHeap()->undefined_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | prev = element_function; |
| 337 | element = element_function->next_function_link(); |
| 338 | } |
| 339 | UNREACHABLE(); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | Object* Context::OptimizedFunctionsListHead() { |
| 344 | ASSERT(IsGlobalContext()); |
| 345 | return get(OPTIMIZED_FUNCTIONS_LIST); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | void Context::ClearOptimizedFunctions() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | set(OPTIMIZED_FUNCTIONS_LIST, GetHeap()->undefined_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 354 | #ifdef DEBUG |
| 355 | bool Context::IsBootstrappingOrContext(Object* object) { |
| 356 | // During bootstrapping we allow all objects to pass as |
| 357 | // contexts. This is necessary to fix circular dependencies. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 358 | return Isolate::Current()->bootstrapper()->IsActive() || object->IsContext(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
| 362 | bool Context::IsBootstrappingOrGlobalObject(Object* object) { |
| 363 | // During bootstrapping we allow all objects to pass as global |
| 364 | // objects. This is necessary to fix circular dependencies. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 365 | Isolate* isolate = Isolate::Current(); |
| 366 | return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 367 | isolate->bootstrapper()->IsActive() || |
| 368 | object->IsGlobalObject(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 369 | } |
| 370 | #endif |
| 371 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 372 | } } // namespace v8::internal |