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/debug/debug.h" | 9 #include "src/debug/debug.h" |
9 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
10 #include "src/globals.h" | 11 #include "src/globals.h" |
11 #include "src/isolate-inl.h" | 12 #include "src/isolate-inl.h" |
12 #include "src/parsing/parser.h" | 13 #include "src/parsing/parser.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, | 18 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 74 } |
74 if (scope_info->scope_type() == FUNCTION_SCOPE) { | 75 if (scope_info->scope_type() == FUNCTION_SCOPE) { |
75 nested_scope_chain_.Add(ExtendedScopeInfo(scope_info, | 76 nested_scope_chain_.Add(ExtendedScopeInfo(scope_info, |
76 shared_info->start_position(), | 77 shared_info->start_position(), |
77 shared_info->end_position())); | 78 shared_info->end_position())); |
78 } | 79 } |
79 if (!collect_non_locals) return; | 80 if (!collect_non_locals) return; |
80 } | 81 } |
81 | 82 |
82 // Reparse the code and analyze the scopes. | 83 // Reparse the code and analyze the scopes. |
83 Scope* scope = NULL; | |
84 // Check whether we are in global, eval or function code. | 84 // Check whether we are in global, eval or function code. |
85 Zone zone(isolate->allocator()); | 85 Zone zone(isolate->allocator()); |
86 base::SmartPointer<ParseInfo> info; | |
86 if (scope_info->scope_type() != FUNCTION_SCOPE) { | 87 if (scope_info->scope_type() != FUNCTION_SCOPE) { |
87 // Global or eval code. | 88 // Global or eval code. |
88 Handle<Script> script(Script::cast(shared_info->script())); | 89 Handle<Script> script(Script::cast(shared_info->script())); |
89 ParseInfo info(&zone, script); | 90 info.Reset(new ParseInfo(&zone, script)); |
91 info->set_toplevel(); | |
90 if (scope_info->scope_type() == SCRIPT_SCOPE) { | 92 if (scope_info->scope_type() == SCRIPT_SCOPE) { |
91 info.set_global(); | 93 info->set_global(); |
92 } else { | 94 } else { |
93 DCHECK(scope_info->scope_type() == EVAL_SCOPE); | 95 DCHECK(scope_info->scope_type() == EVAL_SCOPE); |
94 info.set_eval(); | 96 info->set_eval(); |
95 info.set_context(Handle<Context>(function->context())); | 97 info->set_context(Handle<Context>(function->context())); |
96 } | 98 } |
97 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { | |
98 scope = info.literal()->scope(); | |
99 } | |
100 if (!ignore_nested_scopes) RetrieveScopeChain(scope); | |
101 if (collect_non_locals) CollectNonLocals(scope); | |
102 } else { | 99 } else { |
103 // Function code | 100 // Inner function. |
104 ParseInfo info(&zone, function); | 101 info.Reset(new ParseInfo(&zone, function)); |
105 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { | |
106 scope = info.literal()->scope(); | |
107 } | |
108 if (!ignore_nested_scopes) RetrieveScopeChain(scope); | |
109 if (collect_non_locals) CollectNonLocals(scope); | |
110 } | 102 } |
103 Scope* scope = NULL; | |
104 if (Compiler::ParseAndAnalyze(info.get())) scope = info->literal()->scope(); | |
105 if (!ignore_nested_scopes) RetrieveScopeChain(scope); | |
106 if (collect_non_locals) CollectNonLocals(scope); | |
111 UnwrapEvaluationContext(); | 107 UnwrapEvaluationContext(); |
112 } | 108 } |
113 | 109 |
114 | 110 |
115 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) | 111 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) |
116 : isolate_(isolate), | 112 : isolate_(isolate), |
117 frame_inspector_(NULL), | 113 frame_inspector_(NULL), |
118 context_(function->context()), | 114 context_(function->context()), |
119 seen_script_scope_(false), | 115 seen_script_scope_(false), |
120 failed_(false) { | 116 failed_(false) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 case WITH_SCOPE: | 225 case WITH_SCOPE: |
230 DCHECK(context_->IsWithContext() || context_->IsDebugEvaluateContext()); | 226 DCHECK(context_->IsWithContext() || context_->IsDebugEvaluateContext()); |
231 return ScopeTypeWith; | 227 return ScopeTypeWith; |
232 case CATCH_SCOPE: | 228 case CATCH_SCOPE: |
233 DCHECK(context_->IsCatchContext()); | 229 DCHECK(context_->IsCatchContext()); |
234 return ScopeTypeCatch; | 230 return ScopeTypeCatch; |
235 case BLOCK_SCOPE: | 231 case BLOCK_SCOPE: |
236 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); | 232 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); |
237 return ScopeTypeBlock; | 233 return ScopeTypeBlock; |
238 case EVAL_SCOPE: | 234 case EVAL_SCOPE: |
239 UNREACHABLE(); | 235 DCHECK(!scope_info->HasContext() || context_->IsFunctionContext()); |
236 return ScopeTypeEval; | |
jgruber1
2016/05/11 08:38:06
Should we add a default clause here or alternative
Yang
2016/05/11 11:37:23
The compiler would fail if the switch does not lis
| |
240 } | 237 } |
241 } | 238 } |
242 if (context_->IsNativeContext()) { | 239 if (context_->IsNativeContext()) { |
243 DCHECK(context_->global_object()->IsJSGlobalObject()); | 240 DCHECK(context_->global_object()->IsJSGlobalObject()); |
244 // If we are at the native context and have not yet seen script scope, | 241 // If we are at the native context and have not yet seen script scope, |
245 // fake it. | 242 // fake it. |
246 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; | 243 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; |
247 } | 244 } |
248 if (context_->IsFunctionContext()) { | 245 if (context_->IsFunctionContext()) { |
249 return ScopeTypeClosure; | 246 return ScopeTypeClosure; |
(...skipping 27 matching lines...) Expand all Loading... | |
277 DCHECK(nested_scope_chain_.length() == 1); | 274 DCHECK(nested_scope_chain_.length() == 1); |
278 return MaterializeLocalScope(); | 275 return MaterializeLocalScope(); |
279 case ScopeIterator::ScopeTypeWith: | 276 case ScopeIterator::ScopeTypeWith: |
280 return WithContextExtension(); | 277 return WithContextExtension(); |
281 case ScopeIterator::ScopeTypeCatch: | 278 case ScopeIterator::ScopeTypeCatch: |
282 return MaterializeCatchScope(); | 279 return MaterializeCatchScope(); |
283 case ScopeIterator::ScopeTypeClosure: | 280 case ScopeIterator::ScopeTypeClosure: |
284 // Materialize the content of the closure scope into a JSObject. | 281 // Materialize the content of the closure scope into a JSObject. |
285 return MaterializeClosure(); | 282 return MaterializeClosure(); |
286 case ScopeIterator::ScopeTypeBlock: | 283 case ScopeIterator::ScopeTypeBlock: |
287 return MaterializeBlockScope(); | 284 case ScopeIterator::ScopeTypeEval: |
285 return MaterializeInnerScope(); | |
288 case ScopeIterator::ScopeTypeModule: | 286 case ScopeIterator::ScopeTypeModule: |
289 return MaterializeModuleScope(); | 287 return MaterializeModuleScope(); |
290 } | 288 } |
291 UNREACHABLE(); | 289 UNREACHABLE(); |
292 return Handle<JSObject>(); | 290 return Handle<JSObject>(); |
293 } | 291 } |
294 | 292 |
295 | 293 |
296 bool ScopeIterator::HasContext() { | 294 bool ScopeIterator::HasContext() { |
297 ScopeType type = Type(); | 295 ScopeType type = Type(); |
298 if (type == ScopeTypeBlock || type == ScopeTypeLocal) { | 296 if (type == ScopeTypeBlock || type == ScopeTypeLocal || |
297 type == ScopeTypeEval) { | |
299 if (!nested_scope_chain_.is_empty()) { | 298 if (!nested_scope_chain_.is_empty()) { |
300 return nested_scope_chain_.last().scope_info->HasContext(); | 299 return nested_scope_chain_.last().scope_info->HasContext(); |
301 } | 300 } |
302 } | 301 } |
303 return true; | 302 return true; |
304 } | 303 } |
305 | 304 |
306 | 305 |
307 bool ScopeIterator::SetVariableValue(Handle<String> variable_name, | 306 bool ScopeIterator::SetVariableValue(Handle<String> variable_name, |
308 Handle<Object> new_value) { | 307 Handle<Object> new_value) { |
309 DCHECK(!failed_); | 308 DCHECK(!failed_); |
310 switch (Type()) { | 309 switch (Type()) { |
311 case ScopeIterator::ScopeTypeGlobal: | 310 case ScopeIterator::ScopeTypeGlobal: |
312 break; | 311 break; |
313 case ScopeIterator::ScopeTypeLocal: | 312 case ScopeIterator::ScopeTypeLocal: |
314 return SetLocalVariableValue(variable_name, new_value); | 313 return SetLocalVariableValue(variable_name, new_value); |
315 case ScopeIterator::ScopeTypeWith: | 314 case ScopeIterator::ScopeTypeWith: |
316 break; | 315 break; |
317 case ScopeIterator::ScopeTypeCatch: | 316 case ScopeIterator::ScopeTypeCatch: |
318 return SetCatchVariableValue(variable_name, new_value); | 317 return SetCatchVariableValue(variable_name, new_value); |
319 case ScopeIterator::ScopeTypeClosure: | 318 case ScopeIterator::ScopeTypeClosure: |
320 return SetClosureVariableValue(variable_name, new_value); | 319 return SetClosureVariableValue(variable_name, new_value); |
321 case ScopeIterator::ScopeTypeScript: | 320 case ScopeIterator::ScopeTypeScript: |
322 return SetScriptVariableValue(variable_name, new_value); | 321 return SetScriptVariableValue(variable_name, new_value); |
323 case ScopeIterator::ScopeTypeBlock: | 322 case ScopeIterator::ScopeTypeBlock: |
324 return SetBlockVariableValue(variable_name, new_value); | 323 case ScopeIterator::ScopeTypeEval: |
324 return SetInnerScopeVariableValue(variable_name, new_value); | |
325 case ScopeIterator::ScopeTypeModule: | 325 case ScopeIterator::ScopeTypeModule: |
326 // TODO(2399): should we implement it? | 326 // TODO(2399): should we implement it? |
327 break; | 327 break; |
328 } | 328 } |
329 return false; | 329 return false; |
330 } | 330 } |
331 | 331 |
332 | 332 |
333 Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() { | 333 Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() { |
334 DCHECK(!failed_); | 334 DCHECK(!failed_); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 | 475 |
476 Handle<Context> frame_context = | 476 Handle<Context> frame_context = |
477 Handle<Context>::cast(frame_inspector_->GetContext()); | 477 Handle<Context>::cast(frame_inspector_->GetContext()); |
478 | 478 |
479 HandleScope scope(isolate_); | 479 HandleScope scope(isolate_); |
480 Handle<SharedFunctionInfo> shared(function->shared()); | 480 Handle<SharedFunctionInfo> shared(function->shared()); |
481 Handle<ScopeInfo> scope_info(shared->scope_info()); | 481 Handle<ScopeInfo> scope_info(shared->scope_info()); |
482 | 482 |
483 if (!scope_info->HasContext()) return local_scope; | 483 if (!scope_info->HasContext()) return local_scope; |
484 | 484 |
485 // Third fill all context locals. | 485 // Fill all context locals. |
486 Handle<Context> function_context(frame_context->closure_context()); | 486 Handle<Context> function_context(frame_context->closure_context()); |
487 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); | 487 CopyContextLocalsToScopeObject(scope_info, function_context, local_scope); |
488 | 488 |
489 // Finally copy any properties from the function context extension. | 489 // Finally copy any properties from the function context extension. |
490 // These will be variables introduced by eval. | 490 // These will be variables introduced by eval. |
491 if (function_context->closure() == *function && | 491 if (function_context->closure() == *function && |
492 function_context->has_extension() && | |
493 !function_context->IsNativeContext()) { | 492 !function_context->IsNativeContext()) { |
494 bool success = CopyContextExtensionToScopeObject( | 493 CopyContextExtensionToScopeObject(function_context, local_scope, |
495 handle(function_context->extension_object(), isolate_), local_scope, | 494 INCLUDE_PROTOS); |
496 INCLUDE_PROTOS); | |
497 if (!success) return MaybeHandle<JSObject>(); | |
498 } | 495 } |
499 | 496 |
500 return local_scope; | 497 return local_scope; |
501 } | 498 } |
502 | 499 |
503 | 500 |
504 // Create a plain JSObject which materializes the closure content for the | 501 // Create a plain JSObject which materializes the closure content for the |
505 // context. | 502 // context. |
506 Handle<JSObject> ScopeIterator::MaterializeClosure() { | 503 Handle<JSObject> ScopeIterator::MaterializeClosure() { |
507 Handle<Context> context = CurrentContext(); | 504 Handle<Context> context = CurrentContext(); |
508 DCHECK(context->IsFunctionContext()); | 505 DCHECK(context->IsFunctionContext()); |
509 | 506 |
510 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 507 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
511 Handle<ScopeInfo> scope_info(shared->scope_info()); | 508 Handle<ScopeInfo> scope_info(shared->scope_info()); |
512 | 509 |
513 // Allocate and initialize a JSObject with all the content of this function | 510 // Allocate and initialize a JSObject with all the content of this function |
514 // closure. | 511 // closure. |
515 Handle<JSObject> closure_scope = | 512 Handle<JSObject> closure_scope = |
516 isolate_->factory()->NewJSObjectWithNullProto(); | 513 isolate_->factory()->NewJSObjectWithNullProto(); |
517 | 514 |
518 // Fill all context locals to the context extension. | 515 // Fill all context locals to the context extension. |
519 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); | 516 CopyContextLocalsToScopeObject(scope_info, context, closure_scope); |
520 | 517 |
521 // Finally copy any properties from the function context extension. This will | 518 // Finally copy any properties from the function context extension. This will |
522 // be variables introduced by eval. | 519 // be variables introduced by eval. |
523 if (context->has_extension()) { | 520 CopyContextExtensionToScopeObject(context, closure_scope, OWN_ONLY); |
524 bool success = CopyContextExtensionToScopeObject( | |
525 handle(context->extension_object(), isolate_), closure_scope, OWN_ONLY); | |
526 DCHECK(success); | |
527 USE(success); | |
528 } | |
529 | 521 |
530 return closure_scope; | 522 return closure_scope; |
531 } | 523 } |
532 | 524 |
533 | 525 |
534 // Create a plain JSObject which materializes the scope for the specified | 526 // Create a plain JSObject which materializes the scope for the specified |
535 // catch context. | 527 // catch context. |
536 Handle<JSObject> ScopeIterator::MaterializeCatchScope() { | 528 Handle<JSObject> ScopeIterator::MaterializeCatchScope() { |
537 Handle<Context> context = CurrentContext(); | 529 Handle<Context> context = CurrentContext(); |
538 DCHECK(context->IsCatchContext()); | 530 DCHECK(context->IsCatchContext()); |
(...skipping 14 matching lines...) Expand all Loading... | |
553 Handle<Context> context = CurrentContext(); | 545 Handle<Context> context = CurrentContext(); |
554 DCHECK(context->IsWithContext()); | 546 DCHECK(context->IsWithContext()); |
555 if (context->extension_receiver()->IsJSProxy()) { | 547 if (context->extension_receiver()->IsJSProxy()) { |
556 return isolate_->factory()->NewJSObjectWithNullProto(); | 548 return isolate_->factory()->NewJSObjectWithNullProto(); |
557 } | 549 } |
558 return handle(JSObject::cast(context->extension_receiver())); | 550 return handle(JSObject::cast(context->extension_receiver())); |
559 } | 551 } |
560 | 552 |
561 // Create a plain JSObject which materializes the block scope for the specified | 553 // Create a plain JSObject which materializes the block scope for the specified |
562 // block context. | 554 // block context. |
563 Handle<JSObject> ScopeIterator::MaterializeBlockScope() { | 555 Handle<JSObject> ScopeIterator::MaterializeInnerScope() { |
564 Handle<JSObject> block_scope = | 556 Handle<JSObject> inner_scope = |
565 isolate_->factory()->NewJSObjectWithNullProto(); | 557 isolate_->factory()->NewJSObjectWithNullProto(); |
566 | 558 |
567 Handle<Context> context = Handle<Context>::null(); | 559 Handle<Context> context = Handle<Context>::null(); |
568 if (!nested_scope_chain_.is_empty()) { | 560 if (!nested_scope_chain_.is_empty()) { |
569 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; | 561 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; |
570 frame_inspector_->MaterializeStackLocals(block_scope, scope_info); | 562 frame_inspector_->MaterializeStackLocals(inner_scope, scope_info); |
571 if (scope_info->HasContext()) context = CurrentContext(); | 563 if (scope_info->HasContext()) context = CurrentContext(); |
572 } else { | 564 } else { |
573 context = CurrentContext(); | 565 context = CurrentContext(); |
574 } | 566 } |
575 | 567 |
576 if (!context.is_null()) { | 568 if (!context.is_null()) { |
577 // Fill all context locals. | 569 // Fill all context locals. |
578 CopyContextLocalsToScopeObject(handle(context->scope_info()), | 570 CopyContextLocalsToScopeObject(CurrentScopeInfo(), context, inner_scope); |
579 context, block_scope); | 571 CopyContextExtensionToScopeObject(context, inner_scope, OWN_ONLY); |
580 // Fill all extension variables. | |
581 if (context->extension_object() != nullptr) { | |
582 bool success = CopyContextExtensionToScopeObject( | |
583 handle(context->extension_object()), block_scope, OWN_ONLY); | |
584 DCHECK(success); | |
585 USE(success); | |
586 } | |
587 } | 572 } |
588 return block_scope; | 573 return inner_scope; |
589 } | 574 } |
590 | 575 |
591 | 576 |
592 // Create a plain JSObject which materializes the module scope for the specified | 577 // Create a plain JSObject which materializes the module scope for the specified |
593 // module context. | 578 // module context. |
594 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { | 579 MaybeHandle<JSObject> ScopeIterator::MaterializeModuleScope() { |
595 Handle<Context> context = CurrentContext(); | 580 Handle<Context> context = CurrentContext(); |
596 DCHECK(context->IsModuleContext()); | 581 DCHECK(context->IsModuleContext()); |
597 Handle<ScopeInfo> scope_info(context->scope_info()); | 582 Handle<ScopeInfo> scope_info(context->scope_info()); |
598 | 583 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 | 673 |
689 if (scope_info->HasContext() && | 674 if (scope_info->HasContext() && |
690 SetContextVariableValue(scope_info, CurrentContext(), variable_name, | 675 SetContextVariableValue(scope_info, CurrentContext(), variable_name, |
691 new_value)) { | 676 new_value)) { |
692 return true; | 677 return true; |
693 } | 678 } |
694 | 679 |
695 return result; | 680 return result; |
696 } | 681 } |
697 | 682 |
698 bool ScopeIterator::SetBlockVariableValue(Handle<String> variable_name, | 683 bool ScopeIterator::SetInnerScopeVariableValue(Handle<String> variable_name, |
699 Handle<Object> new_value) { | 684 Handle<Object> new_value) { |
700 Handle<ScopeInfo> scope_info = CurrentScopeInfo(); | 685 Handle<ScopeInfo> scope_info = CurrentScopeInfo(); |
686 DCHECK(scope_info->scope_type() == BLOCK_SCOPE || | |
687 scope_info->scope_type() == EVAL_SCOPE); | |
701 JavaScriptFrame* frame = GetFrame(); | 688 JavaScriptFrame* frame = GetFrame(); |
702 | 689 |
703 // Setting stack locals of optimized frames is not supported. | 690 // Setting stack locals of optimized frames is not supported. |
704 if (SetStackVariableValue(scope_info, frame, variable_name, new_value)) { | 691 if (SetStackVariableValue(scope_info, frame, variable_name, new_value)) { |
705 return true; | 692 return true; |
706 } | 693 } |
707 | 694 |
708 if (HasContext() && SetContextVariableValue(scope_info, CurrentContext(), | 695 if (HasContext() && SetContextVariableValue(scope_info, CurrentContext(), |
709 variable_name, new_value)) { | 696 variable_name, new_value)) { |
710 return true; | 697 return true; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 Handle<Object> value = Handle<Object>(context->get(context_index), isolate); | 752 Handle<Object> value = Handle<Object>(context->get(context_index), isolate); |
766 // Reflect variables under TDZ as undefined in scope object. | 753 // Reflect variables under TDZ as undefined in scope object. |
767 if (value->IsTheHole()) continue; | 754 if (value->IsTheHole()) continue; |
768 // This should always succeed. | 755 // This should always succeed. |
769 // TODO(verwaest): Use AddDataProperty instead. | 756 // TODO(verwaest): Use AddDataProperty instead. |
770 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) | 757 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, name, value, NONE) |
771 .Check(); | 758 .Check(); |
772 } | 759 } |
773 } | 760 } |
774 | 761 |
775 bool ScopeIterator::CopyContextExtensionToScopeObject( | 762 void ScopeIterator::CopyContextExtensionToScopeObject( |
776 Handle<JSObject> extension, Handle<JSObject> scope_object, | 763 Handle<Context> context, Handle<JSObject> scope_object, |
777 KeyCollectionType type) { | 764 KeyCollectionType type) { |
778 Handle<FixedArray> keys; | 765 if (!context->has_extension()) return; |
779 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 766 Handle<JSObject> extension(context->extension_object()); |
780 isolate_, keys, JSReceiver::GetKeys(extension, type, ENUMERABLE_STRINGS), | 767 Handle<FixedArray> keys = |
781 false); | 768 JSReceiver::GetKeys(extension, type, ENUMERABLE_STRINGS) |
769 .ToHandleChecked(); | |
782 | 770 |
783 for (int i = 0; i < keys->length(); i++) { | 771 for (int i = 0; i < keys->length(); i++) { |
784 // Names of variables introduced by eval are strings. | 772 // Names of variables introduced by eval are strings. |
785 DCHECK(keys->get(i)->IsString()); | 773 DCHECK(keys->get(i)->IsString()); |
786 Handle<String> key(String::cast(keys->get(i))); | 774 Handle<String> key(String::cast(keys->get(i))); |
787 Handle<Object> value; | 775 Handle<Object> value = |
788 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 776 Object::GetPropertyOrElement(extension, key).ToHandleChecked(); |
789 isolate_, value, Object::GetPropertyOrElement(extension, key), false); | 777 JSObject::SetOwnPropertyIgnoreAttributes(scope_object, key, value, NONE) |
790 RETURN_ON_EXCEPTION_VALUE( | 778 .Check(); |
791 isolate_, JSObject::SetOwnPropertyIgnoreAttributes( | |
792 scope_object, key, value, NONE), false); | |
793 } | 779 } |
794 return true; | |
795 } | 780 } |
796 | 781 |
797 void ScopeIterator::GetNestedScopeChain(Isolate* isolate, Scope* scope, | 782 void ScopeIterator::GetNestedScopeChain(Isolate* isolate, Scope* scope, |
798 int position) { | 783 int position) { |
799 if (!scope->is_eval_scope() && !scope->is_hidden()) { | 784 if (!scope->is_hidden()) { |
800 nested_scope_chain_.Add(ExtendedScopeInfo(scope->GetScopeInfo(isolate), | 785 nested_scope_chain_.Add(ExtendedScopeInfo(scope->GetScopeInfo(isolate), |
801 scope->start_position(), | 786 scope->start_position(), |
802 scope->end_position())); | 787 scope->end_position())); |
803 } | 788 } |
804 for (int i = 0; i < scope->inner_scopes()->length(); i++) { | 789 for (int i = 0; i < scope->inner_scopes()->length(); i++) { |
805 Scope* inner_scope = scope->inner_scopes()->at(i); | 790 Scope* inner_scope = scope->inner_scopes()->at(i); |
806 int beg_pos = inner_scope->start_position(); | 791 int beg_pos = inner_scope->start_position(); |
807 int end_pos = inner_scope->end_position(); | 792 int end_pos = inner_scope->end_position(); |
808 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 793 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
809 if (beg_pos <= position && position < end_pos) { | 794 if (beg_pos <= position && position < end_pos) { |
810 GetNestedScopeChain(isolate, inner_scope, position); | 795 GetNestedScopeChain(isolate, inner_scope, position); |
811 return; | 796 return; |
812 } | 797 } |
813 } | 798 } |
814 } | 799 } |
815 | 800 |
816 } // namespace internal | 801 } // namespace internal |
817 } // namespace v8 | 802 } // namespace v8 |
OLD | NEW |