| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/debug/debug-scopes.h" | 5 #include "src/debug/debug-scopes.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 487 |
| 488 // Fill all context locals. | 488 // Fill all context locals. |
| 489 Handle<Context> function_context(frame_context->closure_context()); | 489 Handle<Context> function_context(frame_context->closure_context()); |
| 490 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); | 490 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); |
| 491 | 491 |
| 492 // Finally copy any properties from the function context extension. | 492 // Finally copy any properties from the function context extension. |
| 493 // These will be variables introduced by eval. | 493 // These will be variables introduced by eval. |
| 494 if (function_context->closure() == *function && | 494 if (function_context->closure() == *function && |
| 495 !function_context->IsNativeContext()) { | 495 !function_context->IsNativeContext()) { |
| 496 CopyContextExtensionToScopeObject(function_context, local_scope, | 496 CopyContextExtensionToScopeObject(function_context, local_scope, |
| 497 INCLUDE_PROTOS); | 497 KeyCollectionMode::kIncludePrototypes); |
| 498 } | 498 } |
| 499 | 499 |
| 500 return local_scope; | 500 return local_scope; |
| 501 } | 501 } |
| 502 | 502 |
| 503 | 503 |
| 504 // Create a plain JSObject which materializes the closure content for the | 504 // Create a plain JSObject which materializes the closure content for the |
| 505 // context. | 505 // context. |
| 506 Handle<JSObject> ScopeIterator::MaterializeClosure() { | 506 Handle<JSObject> ScopeIterator::MaterializeClosure() { |
| 507 Handle<Context> context = CurrentContext(); | 507 Handle<Context> context = CurrentContext(); |
| 508 DCHECK(context->IsFunctionContext()); | 508 DCHECK(context->IsFunctionContext()); |
| 509 | 509 |
| 510 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 510 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
| 511 Handle<ScopeInfo> scope_info(shared->scope_info()); | 511 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 512 | 512 |
| 513 // Allocate and initialize a JSObject with all the content of this function | 513 // Allocate and initialize a JSObject with all the content of this function |
| 514 // closure. | 514 // closure. |
| 515 Handle<JSObject> closure_scope = | 515 Handle<JSObject> closure_scope = |
| 516 isolate_->factory()->NewJSObjectWithNullProto(); | 516 isolate_->factory()->NewJSObjectWithNullProto(); |
| 517 | 517 |
| 518 // Fill all context locals to the context extension. | 518 // Fill all context locals to the context extension. |
| 519 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); | 519 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); |
| 520 | 520 |
| 521 // Finally copy any properties from the function context extension. This will | 521 // Finally copy any properties from the function context extension. This will |
| 522 // be variables introduced by eval. | 522 // be variables introduced by eval. |
| 523 CopyContextExtensionToScopeObject(context, closure_scope, OWN_ONLY); | 523 CopyContextExtensionToScopeObject(context, closure_scope, |
| 524 KeyCollectionMode::kOwnOnly); |
| 524 | 525 |
| 525 return closure_scope; | 526 return closure_scope; |
| 526 } | 527 } |
| 527 | 528 |
| 528 | 529 |
| 529 // Create a plain JSObject which materializes the scope for the specified | 530 // Create a plain JSObject which materializes the scope for the specified |
| 530 // catch context. | 531 // catch context. |
| 531 Handle<JSObject> ScopeIterator::MaterializeCatchScope() { | 532 Handle<JSObject> ScopeIterator::MaterializeCatchScope() { |
| 532 Handle<Context> context = CurrentContext(); | 533 Handle<Context> context = CurrentContext(); |
| 533 DCHECK(context->IsCatchContext()); | 534 DCHECK(context->IsCatchContext()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 564 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; | 565 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; |
| 565 frame_inspector_->MaterializeStackLocals(inner_scope, scope_info); | 566 frame_inspector_->MaterializeStackLocals(inner_scope, scope_info); |
| 566 if (scope_info->HasContext()) context = CurrentContext(); | 567 if (scope_info->HasContext()) context = CurrentContext(); |
| 567 } else { | 568 } else { |
| 568 context = CurrentContext(); | 569 context = CurrentContext(); |
| 569 } | 570 } |
| 570 | 571 |
| 571 if (!context.is_null()) { | 572 if (!context.is_null()) { |
| 572 // Fill all context locals. | 573 // Fill all context locals. |
| 573 CopyContextLocalsToScopeObject(CurrentScopeInfo(), context, inner_scope); | 574 CopyContextLocalsToScopeObject(CurrentScopeInfo(), context, inner_scope); |
| 574 CopyContextExtensionToScopeObject(context, inner_scope, OWN_ONLY); | 575 CopyContextExtensionToScopeObject(context, inner_scope, |
| 576 KeyCollectionMode::kOwnOnly); |
| 575 } | 577 } |
| 576 return inner_scope; | 578 return inner_scope; |
| 577 } | 579 } |
| 578 | 580 |
| 579 | 581 |
| 580 // Create a plain JSObject which materializes the module scope for the specified | 582 // Create a plain JSObject which materializes the module scope for the specified |
| 581 // module context. | 583 // module context. |
| 582 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { | 584 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { |
| 583 Handle<Context> context = CurrentContext(); | 585 Handle<Context> context = CurrentContext(); |
| 584 DCHECK(context->IsModuleContext()); | 586 DCHECK(context->IsModuleContext()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 if (value->IsTheHole()) continue; | 759 if (value->IsTheHole()) continue; |
| 758 // This should always succeed. | 760 // This should always succeed. |
| 759 // TODO(verwaest): Use AddDataProperty instead. | 761 // TODO(verwaest): Use AddDataProperty instead. |
| 760 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) | 762 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) |
| 761 .Check(); | 763 .Check(); |
| 762 } | 764 } |
| 763 } | 765 } |
| 764 | 766 |
| 765 void ScopeIterator::CopyContextExtensionToScopeObject( | 767 void ScopeIterator::CopyContextExtensionToScopeObject( |
| 766 Handle<Context> context, Handle<JSObject> scope_object, | 768 Handle<Context> context, Handle<JSObject> scope_object, |
| 767 KeyCollectionType type) { | 769 KeyCollectionMode mode) { |
| 768 if (context->extension_object() == nullptr) return; | 770 if (context->extension_object() == nullptr) return; |
| 769 Handle<JSObject> extension(context->extension_object()); | 771 Handle<JSObject> extension(context->extension_object()); |
| 770 Handle<FixedArray> keys = | 772 Handle<FixedArray> keys = |
| 771 KeyAccumulator::GetKeys(extension, type, ENUMERABLE_STRINGS) | 773 KeyAccumulator::GetKeys(extension, mode, ENUMERABLE_STRINGS) |
| 772 .ToHandleChecked(); | 774 .ToHandleChecked(); |
| 773 | 775 |
| 774 for (int i = 0; i < keys->length(); i++) { | 776 for (int i = 0; i < keys->length(); i++) { |
| 775 // Names of variables introduced by eval are strings. | 777 // Names of variables introduced by eval are strings. |
| 776 DCHECK(keys->get(i)->IsString()); | 778 DCHECK(keys->get(i)->IsString()); |
| 777 Handle<String> key(String::cast(keys->get(i))); | 779 Handle<String> key(String::cast(keys->get(i))); |
| 778 Handle<Object> value = | 780 Handle<Object> value = |
| 779 Object::GetPropertyOrElement(extension, key).ToHandleChecked(); | 781 Object::GetPropertyOrElement(extension, key).ToHandleChecked(); |
| 780 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, key, value, NONE) | 782 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, key, value, NONE) |
| 781 .Check(); | 783 .Check(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 800 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 802 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
| 801 if (beg_pos <= position && position < end_pos) { | 803 if (beg_pos <= position && position < end_pos) { |
| 802 GetNestedScopeChain(isolate, inner_scope, position); | 804 GetNestedScopeChain(isolate, inner_scope, position); |
| 803 return; | 805 return; |
| 804 } | 806 } |
| 805 } | 807 } |
| 806 } | 808 } |
| 807 | 809 |
| 808 } // namespace internal | 810 } // namespace internal |
| 809 } // namespace v8 | 811 } // namespace v8 |
| OLD | NEW |