| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 PrintF("=> found intermediate function in context slot %d\n", | 180 PrintF("=> found intermediate function in context slot %d\n", |
| 181 index); | 181 index); |
| 182 } | 182 } |
| 183 *index_ = index; | 183 *index_ = index; |
| 184 *attributes = READ_ONLY; | 184 *attributes = READ_ONLY; |
| 185 return context; | 185 return context; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 // proceed with enclosing context | 190 // Proceed with the previous context. |
| 191 if (context->IsGlobalContext()) { | 191 if (context->IsGlobalContext()) { |
| 192 follow_context_chain = false; | 192 follow_context_chain = false; |
| 193 } else if (context->IsFunctionContext()) { | |
| 194 context = Handle<Context>(context->closure()->context(), isolate); | |
| 195 } else { | 193 } else { |
| 196 context = Handle<Context>(context->previous(), isolate); | 194 context = Handle<Context>(context->previous(), isolate); |
| 197 } | 195 } |
| 198 } while (follow_context_chain); | 196 } while (follow_context_chain); |
| 199 | 197 |
| 200 // slot not found | 198 // slot not found |
| 201 if (FLAG_trace_contexts) { | 199 if (FLAG_trace_contexts) { |
| 202 PrintF("=> no property/slot found\n"); | 200 PrintF("=> no property/slot found\n"); |
| 203 } | 201 } |
| 204 return Handle<Object>::null(); | 202 return Handle<Object>::null(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 227 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 225 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 228 if (index >= 0) return false; | 226 if (index >= 0) return false; |
| 229 | 227 |
| 230 // Check parameter locals. | 228 // Check parameter locals. |
| 231 int param_index = scope_info->ParameterIndex(*name); | 229 int param_index = scope_info->ParameterIndex(*name); |
| 232 if (param_index >= 0) return false; | 230 if (param_index >= 0) return false; |
| 233 | 231 |
| 234 // Check context only holding the function name variable. | 232 // Check context only holding the function name variable. |
| 235 index = scope_info->FunctionContextSlotIndex(*name); | 233 index = scope_info->FunctionContextSlotIndex(*name); |
| 236 if (index >= 0) return false; | 234 if (index >= 0) return false; |
| 237 context = Context::cast(context->closure()->context()); | 235 context = context->previous(); |
| 238 } | 236 } |
| 239 | 237 |
| 240 // No local or potential with statement found so the variable is | 238 // No local or potential with statement found so the variable is |
| 241 // global unless it is shadowed by an eval-introduced variable. | 239 // global unless it is shadowed by an eval-introduced variable. |
| 242 return true; | 240 return true; |
| 243 } | 241 } |
| 244 | 242 |
| 245 | 243 |
| 246 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_eval, | 244 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_eval, |
| 247 bool* outer_scope_calls_non_strict_eval) { | 245 bool* outer_scope_calls_non_strict_eval) { |
| 248 Context* context = this; | 246 // Skip up the context chain checking all the function contexts to see |
| 249 while (true) { | 247 // whether they call eval. |
| 248 Context* context = fcontext(); |
| 249 while (!context->IsGlobalContext()) { |
| 250 Handle<SerializedScopeInfo> scope_info( | 250 Handle<SerializedScopeInfo> scope_info( |
| 251 context->closure()->shared()->scope_info()); | 251 context->closure()->shared()->scope_info()); |
| 252 if (scope_info->CallsEval()) { | 252 if (scope_info->CallsEval()) { |
| 253 *outer_scope_calls_eval = true; | 253 *outer_scope_calls_eval = true; |
| 254 if (!scope_info->IsStrictMode()) { | 254 if (!scope_info->IsStrictMode()) { |
| 255 // No need to go further since the answers will not change | 255 // No need to go further since the answers will not change |
| 256 // from here. | 256 // from here. |
| 257 *outer_scope_calls_non_strict_eval = true; | 257 *outer_scope_calls_non_strict_eval = true; |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 if (context->IsGlobalContext()) break; | 261 context = context->previous()->fcontext(); |
| 262 context = Context::cast(context->closure()->context()); | |
| 263 } | 262 } |
| 264 } | 263 } |
| 265 | 264 |
| 266 | 265 |
| 267 void Context::AddOptimizedFunction(JSFunction* function) { | 266 void Context::AddOptimizedFunction(JSFunction* function) { |
| 268 ASSERT(IsGlobalContext()); | 267 ASSERT(IsGlobalContext()); |
| 269 #ifdef DEBUG | 268 #ifdef DEBUG |
| 270 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); | 269 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 271 while (!element->IsUndefined()) { | 270 while (!element->IsUndefined()) { |
| 272 CHECK(element != function); | 271 CHECK(element != function); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // During bootstrapping we allow all objects to pass as global | 338 // During bootstrapping we allow all objects to pass as global |
| 340 // objects. This is necessary to fix circular dependencies. | 339 // objects. This is necessary to fix circular dependencies. |
| 341 Isolate* isolate = Isolate::Current(); | 340 Isolate* isolate = Isolate::Current(); |
| 342 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 341 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 343 isolate->bootstrapper()->IsActive() || | 342 isolate->bootstrapper()->IsActive() || |
| 344 object->IsGlobalObject(); | 343 object->IsGlobalObject(); |
| 345 } | 344 } |
| 346 #endif | 345 #endif |
| 347 | 346 |
| 348 } } // namespace v8::internal | 347 } } // namespace v8::internal |
| OLD | NEW |