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/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Third fill all context locals. | 469 // Third fill all context locals. |
470 Handle<Context> function_context(frame_context->closure_context()); | 470 Handle<Context> function_context(frame_context->closure_context()); |
471 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); | 471 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); |
472 | 472 |
473 // Finally copy any properties from the function context extension. | 473 // Finally copy any properties from the function context extension. |
474 // These will be variables introduced by eval. | 474 // These will be variables introduced by eval. |
475 if (function_context->closure() == *function && | 475 if (function_context->closure() == *function && |
476 function_context->has_extension() && | 476 function_context->has_extension() && |
477 !function_context->IsNativeContext()) { | 477 !function_context->IsNativeContext()) { |
478 bool success = CopyContextExtensionToScopeObject( | 478 bool success = CopyContextExtensionToScopeObject( |
479 handle(function_context->extension_object(), isolate_), | 479 handle(function_context->extension_object(), isolate_), local_scope, |
480 local_scope, JSReceiver::INCLUDE_PROTOS); | 480 INCLUDE_PROTOS); |
481 if (!success) return MaybeHandle<JSObject>(); | 481 if (!success) return MaybeHandle<JSObject>(); |
482 } | 482 } |
483 | 483 |
484 return local_scope; | 484 return local_scope; |
485 } | 485 } |
486 | 486 |
487 | 487 |
488 // Create a plain JSObject which materializes the closure content for the | 488 // Create a plain JSObject which materializes the closure content for the |
489 // context. | 489 // context. |
490 Handle<JSObject> ScopeIterator::MaterializeClosure() { | 490 Handle<JSObject> ScopeIterator::MaterializeClosure() { |
491 Handle<Context> context = CurrentContext(); | 491 Handle<Context> context = CurrentContext(); |
492 DCHECK(context->IsFunctionContext()); | 492 DCHECK(context->IsFunctionContext()); |
493 | 493 |
494 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 494 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
495 Handle<ScopeInfo> scope_info(shared->scope_info()); | 495 Handle<ScopeInfo> scope_info(shared->scope_info()); |
496 | 496 |
497 // Allocate and initialize a JSObject with all the content of this function | 497 // Allocate and initialize a JSObject with all the content of this function |
498 // closure. | 498 // closure. |
499 Handle<JSObject> closure_scope = | 499 Handle<JSObject> closure_scope = |
500 isolate_->factory()->NewJSObject(isolate_->object_function()); | 500 isolate_->factory()->NewJSObject(isolate_->object_function()); |
501 | 501 |
502 // Fill all context locals to the context extension. | 502 // Fill all context locals to the context extension. |
503 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); | 503 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); |
504 | 504 |
505 // Finally copy any properties from the function context extension. This will | 505 // Finally copy any properties from the function context extension. This will |
506 // be variables introduced by eval. | 506 // be variables introduced by eval. |
507 if (context->has_extension()) { | 507 if (context->has_extension()) { |
508 bool success = CopyContextExtensionToScopeObject( | 508 bool success = CopyContextExtensionToScopeObject( |
509 handle(context->extension_object(), isolate_), closure_scope, | 509 handle(context->extension_object(), isolate_), closure_scope, OWN_ONLY); |
510 JSReceiver::OWN_ONLY); | |
511 DCHECK(success); | 510 DCHECK(success); |
512 USE(success); | 511 USE(success); |
513 } | 512 } |
514 | 513 |
515 return closure_scope; | 514 return closure_scope; |
516 } | 515 } |
517 | 516 |
518 | 517 |
519 // Create a plain JSObject which materializes the scope for the specified | 518 // Create a plain JSObject which materializes the scope for the specified |
520 // catch context. | 519 // catch context. |
(...skipping 27 matching lines...) Expand all Loading... |
548 context = CurrentContext(); | 547 context = CurrentContext(); |
549 } | 548 } |
550 | 549 |
551 if (!context.is_null()) { | 550 if (!context.is_null()) { |
552 // Fill all context locals. | 551 // Fill all context locals. |
553 CopyContextLocalsToScopeObject(handle(context->scope_info()), | 552 CopyContextLocalsToScopeObject(handle(context->scope_info()), |
554 context, block_scope); | 553 context, block_scope); |
555 // Fill all extension variables. | 554 // Fill all extension variables. |
556 if (context->extension_object() != nullptr) { | 555 if (context->extension_object() != nullptr) { |
557 bool success = CopyContextExtensionToScopeObject( | 556 bool success = CopyContextExtensionToScopeObject( |
558 handle(context->extension_object()), block_scope, | 557 handle(context->extension_object()), block_scope, OWN_ONLY); |
559 JSReceiver::OWN_ONLY); | |
560 DCHECK(success); | 558 DCHECK(success); |
561 USE(success); | 559 USE(success); |
562 } | 560 } |
563 } | 561 } |
564 return block_scope; | 562 return block_scope; |
565 } | 563 } |
566 | 564 |
567 | 565 |
568 // Create a plain JSObject which materializes the module scope for the specified | 566 // Create a plain JSObject which materializes the module scope for the specified |
569 // module context. | 567 // module context. |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 if (value->IsTheHole()) continue; | 785 if (value->IsTheHole()) continue; |
788 // This should always succeed. | 786 // This should always succeed. |
789 // TODO(verwaest): Use AddDataProperty instead. | 787 // TODO(verwaest): Use AddDataProperty instead. |
790 JSObject::SetOwnPropertyIgnoreAttributes( | 788 JSObject::SetOwnPropertyIgnoreAttributes( |
791 scope_object, handle(String::cast(scope_info->get(i + start))), value, | 789 scope_object, handle(String::cast(scope_info->get(i + start))), value, |
792 NONE) | 790 NONE) |
793 .Check(); | 791 .Check(); |
794 } | 792 } |
795 } | 793 } |
796 | 794 |
797 | |
798 bool ScopeIterator::CopyContextExtensionToScopeObject( | 795 bool ScopeIterator::CopyContextExtensionToScopeObject( |
799 Handle<JSObject> extension, Handle<JSObject> scope_object, | 796 Handle<JSObject> extension, Handle<JSObject> scope_object, |
800 JSReceiver::KeyCollectionType type) { | 797 KeyCollectionType type) { |
801 Handle<FixedArray> keys; | 798 Handle<FixedArray> keys; |
802 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 799 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
803 isolate_, keys, JSReceiver::GetKeys(extension, type, ENUMERABLE_STRINGS), | 800 isolate_, keys, JSReceiver::GetKeys(extension, type, ENUMERABLE_STRINGS), |
804 false); | 801 false); |
805 | 802 |
806 for (int i = 0; i < keys->length(); i++) { | 803 for (int i = 0; i < keys->length(); i++) { |
807 // Names of variables introduced by eval are strings. | 804 // Names of variables introduced by eval are strings. |
808 DCHECK(keys->get(i)->IsString()); | 805 DCHECK(keys->get(i)->IsString()); |
809 Handle<String> key(String::cast(keys->get(i))); | 806 Handle<String> key(String::cast(keys->get(i))); |
810 Handle<Object> value; | 807 Handle<Object> value; |
811 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 808 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
812 isolate_, value, Object::GetPropertyOrElement(extension, key), false); | 809 isolate_, value, Object::GetPropertyOrElement(extension, key), false); |
813 RETURN_ON_EXCEPTION_VALUE( | 810 RETURN_ON_EXCEPTION_VALUE( |
814 isolate_, JSObject::SetOwnPropertyIgnoreAttributes( | 811 isolate_, JSObject::SetOwnPropertyIgnoreAttributes( |
815 scope_object, key, value, NONE), false); | 812 scope_object, key, value, NONE), false); |
816 } | 813 } |
817 return true; | 814 return true; |
818 } | 815 } |
819 | 816 |
820 } // namespace internal | 817 } // namespace internal |
821 } // namespace v8 | 818 } // namespace v8 |
OLD | NEW |