| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
| 8 #include "src/debug.h" | 8 #include "src/debug.h" |
| 9 #include "src/scopeinfo.h" | 9 #include "src/scopeinfo.h" |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 bool ScriptContextTable::Lookup(Handle<ScriptContextTable> table, | 36 bool ScriptContextTable::Lookup(Handle<ScriptContextTable> table, |
| 37 Handle<String> name, LookupResult* result) { | 37 Handle<String> name, LookupResult* result) { |
| 38 for (int i = 0; i < table->used(); i++) { | 38 for (int i = 0; i < table->used(); i++) { |
| 39 Handle<Context> context = GetContext(table, i); | 39 Handle<Context> context = GetContext(table, i); |
| 40 DCHECK(context->IsScriptContext()); | 40 DCHECK(context->IsScriptContext()); |
| 41 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 41 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
| 42 int slot_index = ScopeInfo::ContextSlotIndex( | 42 int slot_index = ScopeInfo::ContextSlotIndex( |
| 43 scope_info, name, &result->mode, &result->init_flag, | 43 scope_info, name, &result->mode, &result->location, &result->init_flag, |
| 44 &result->maybe_assigned_flag); | 44 &result->maybe_assigned_flag); |
| 45 | 45 |
| 46 if (slot_index >= 0) { | 46 if (slot_index >= 0 && result->location == VariableLocation::CONTEXT) { |
| 47 result->context_index = i; | 47 result->context_index = i; |
| 48 result->slot_index = slot_index; | 48 result->slot_index = slot_index; |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 Context* Context::declaration_context() { | 56 Context* Context::declaration_context() { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // for the context index. | 280 // for the context index. |
| 281 Handle<ScopeInfo> scope_info; | 281 Handle<ScopeInfo> scope_info; |
| 282 if (context->IsFunctionContext()) { | 282 if (context->IsFunctionContext()) { |
| 283 scope_info = Handle<ScopeInfo>( | 283 scope_info = Handle<ScopeInfo>( |
| 284 context->closure()->shared()->scope_info(), isolate); | 284 context->closure()->shared()->scope_info(), isolate); |
| 285 } else { | 285 } else { |
| 286 scope_info = Handle<ScopeInfo>( | 286 scope_info = Handle<ScopeInfo>( |
| 287 ScopeInfo::cast(context->extension()), isolate); | 287 ScopeInfo::cast(context->extension()), isolate); |
| 288 } | 288 } |
| 289 VariableMode mode; | 289 VariableMode mode; |
| 290 VariableLocation location; |
| 290 InitializationFlag init_flag; | 291 InitializationFlag init_flag; |
| 291 // TODO(sigurds) Figure out whether maybe_assigned_flag should | 292 // TODO(sigurds) Figure out whether maybe_assigned_flag should |
| 292 // be used to compute binding_flags. | 293 // be used to compute binding_flags. |
| 293 MaybeAssignedFlag maybe_assigned_flag; | 294 MaybeAssignedFlag maybe_assigned_flag; |
| 294 int slot_index = ScopeInfo::ContextSlotIndex( | 295 int slot_index = ScopeInfo::ContextSlotIndex( |
| 295 scope_info, name, &mode, &init_flag, &maybe_assigned_flag); | 296 scope_info, name, &mode, &location, &init_flag, &maybe_assigned_flag); |
| 296 DCHECK(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); | 297 DCHECK(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); |
| 297 if (slot_index >= 0) { | 298 if (slot_index >= 0 && location == VariableLocation::CONTEXT) { |
| 298 if (FLAG_trace_contexts) { | 299 if (FLAG_trace_contexts) { |
| 299 PrintF("=> found local in context slot %d (mode = %d)\n", | 300 PrintF("=> found local in context slot %d (mode = %d)\n", |
| 300 slot_index, mode); | 301 slot_index, mode); |
| 301 } | 302 } |
| 302 *index = slot_index; | 303 *index = slot_index; |
| 303 GetAttributesAndBindingFlags(mode, init_flag, attributes, | 304 GetAttributesAndBindingFlags(mode, init_flag, attributes, |
| 304 binding_flags); | 305 binding_flags); |
| 305 return context; | 306 return context; |
| 306 } | 307 } |
| 307 | 308 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 346 } |
| 346 } while (follow_context_chain); | 347 } while (follow_context_chain); |
| 347 | 348 |
| 348 if (FLAG_trace_contexts) { | 349 if (FLAG_trace_contexts) { |
| 349 PrintF("=> no property/slot found\n"); | 350 PrintF("=> no property/slot found\n"); |
| 350 } | 351 } |
| 351 return Handle<Object>::null(); | 352 return Handle<Object>::null(); |
| 352 } | 353 } |
| 353 | 354 |
| 354 | 355 |
| 356 void Context::InitializeGlobalSlots() { |
| 357 DCHECK(IsScriptContext()); |
| 358 DisallowHeapAllocation no_gc; |
| 359 |
| 360 ScopeInfo* scope_info = ScopeInfo::cast(extension()); |
| 361 |
| 362 int context_globals = scope_info->ContextGlobalCount(); |
| 363 if (context_globals > 0) { |
| 364 PropertyCell* empty_cell = GetHeap()->empty_property_cell(); |
| 365 |
| 366 int context_locals = scope_info->ContextLocalCount(); |
| 367 int index = Context::MIN_CONTEXT_SLOTS + context_locals; |
| 368 for (int i = 0; i < context_globals; i++) { |
| 369 // Clear both read and write slots. |
| 370 set(index++, empty_cell); |
| 371 set(index++, empty_cell); |
| 372 } |
| 373 } |
| 374 } |
| 375 |
| 376 |
| 355 void Context::AddOptimizedFunction(JSFunction* function) { | 377 void Context::AddOptimizedFunction(JSFunction* function) { |
| 356 DCHECK(IsNativeContext()); | 378 DCHECK(IsNativeContext()); |
| 357 #ifdef ENABLE_SLOW_DCHECKS | 379 #ifdef ENABLE_SLOW_DCHECKS |
| 358 if (FLAG_enable_slow_asserts) { | 380 if (FLAG_enable_slow_asserts) { |
| 359 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); | 381 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); |
| 360 while (!element->IsUndefined()) { | 382 while (!element->IsUndefined()) { |
| 361 CHECK(element != function); | 383 CHECK(element != function); |
| 362 element = JSFunction::cast(element)->next_function_link(); | 384 element = JSFunction::cast(element)->next_function_link(); |
| 363 } | 385 } |
| 364 } | 386 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // During bootstrapping we allow all objects to pass as global | 511 // During bootstrapping we allow all objects to pass as global |
| 490 // objects. This is necessary to fix circular dependencies. | 512 // objects. This is necessary to fix circular dependencies. |
| 491 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 513 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 492 isolate->bootstrapper()->IsActive() || | 514 isolate->bootstrapper()->IsActive() || |
| 493 object->IsGlobalObject(); | 515 object->IsGlobalObject(); |
| 494 } | 516 } |
| 495 #endif | 517 #endif |
| 496 | 518 |
| 497 } // namespace internal | 519 } // namespace internal |
| 498 } // namespace v8 | 520 } // namespace v8 |
| OLD | NEW |