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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 case WITH_SCOPE: | 264 case WITH_SCOPE: |
265 DCHECK(context_->IsWithContext() || context_->IsDebugEvaluateContext()); | 265 DCHECK(context_->IsWithContext() || context_->IsDebugEvaluateContext()); |
266 return ScopeTypeWith; | 266 return ScopeTypeWith; |
267 case CATCH_SCOPE: | 267 case CATCH_SCOPE: |
268 DCHECK(context_->IsCatchContext()); | 268 DCHECK(context_->IsCatchContext()); |
269 return ScopeTypeCatch; | 269 return ScopeTypeCatch; |
270 case BLOCK_SCOPE: | 270 case BLOCK_SCOPE: |
271 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); | 271 DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); |
272 return ScopeTypeBlock; | 272 return ScopeTypeBlock; |
273 case EVAL_SCOPE: | 273 case EVAL_SCOPE: |
274 DCHECK(!scope_info->HasContext() || context_->IsFunctionContext()); | 274 DCHECK(!scope_info->HasContext() || context_->IsEvalContext()); |
275 return ScopeTypeEval; | 275 return ScopeTypeEval; |
276 } | 276 } |
277 UNREACHABLE(); | 277 UNREACHABLE(); |
278 } | 278 } |
279 if (context_->IsNativeContext()) { | 279 if (context_->IsNativeContext()) { |
280 DCHECK(context_->global_object()->IsJSGlobalObject()); | 280 DCHECK(context_->global_object()->IsJSGlobalObject()); |
281 // If we are at the native context and have not yet seen script scope, | 281 // If we are at the native context and have not yet seen script scope, |
282 // fake it. | 282 // fake it. |
283 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; | 283 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; |
284 } | 284 } |
285 if (context_->IsFunctionContext()) { | 285 if (context_->IsFunctionContext() || context_->IsEvalContext()) { |
286 return ScopeTypeClosure; | 286 return ScopeTypeClosure; |
287 } | 287 } |
288 if (context_->IsCatchContext()) { | 288 if (context_->IsCatchContext()) { |
289 return ScopeTypeCatch; | 289 return ScopeTypeCatch; |
290 } | 290 } |
291 if (context_->IsBlockContext()) { | 291 if (context_->IsBlockContext()) { |
292 return ScopeTypeBlock; | 292 return ScopeTypeBlock; |
293 } | 293 } |
294 if (context_->IsModuleContext()) { | 294 if (context_->IsModuleContext()) { |
295 return ScopeTypeModule; | 295 return ScopeTypeModule; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 break; | 367 break; |
368 } | 368 } |
369 return false; | 369 return false; |
370 } | 370 } |
371 | 371 |
372 | 372 |
373 Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() { | 373 Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() { |
374 DCHECK(!Done()); | 374 DCHECK(!Done()); |
375 if (!nested_scope_chain_.is_empty()) { | 375 if (!nested_scope_chain_.is_empty()) { |
376 return nested_scope_chain_.last().scope_info; | 376 return nested_scope_chain_.last().scope_info; |
377 } else if (context_->IsBlockContext()) { | 377 } else if (context_->IsBlockContext() || context_->IsFunctionContext() || |
| 378 context_->IsEvalContext()) { |
378 return Handle<ScopeInfo>(context_->scope_info()); | 379 return Handle<ScopeInfo>(context_->scope_info()); |
379 } else if (context_->IsFunctionContext()) { | |
380 return Handle<ScopeInfo>(context_->closure()->shared()->scope_info()); | |
381 } | 380 } |
382 return Handle<ScopeInfo>::null(); | 381 return Handle<ScopeInfo>::null(); |
383 } | 382 } |
384 | 383 |
385 | 384 |
386 Handle<Context> ScopeIterator::CurrentContext() { | 385 Handle<Context> ScopeIterator::CurrentContext() { |
387 DCHECK(!Done()); | 386 DCHECK(!Done()); |
388 if (Type() == ScopeTypeGlobal || Type() == ScopeTypeScript || | 387 if (Type() == ScopeTypeGlobal || Type() == ScopeTypeScript || |
389 nested_scope_chain_.is_empty()) { | 388 nested_scope_chain_.is_empty()) { |
390 return context_; | 389 return context_; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 521 } |
523 | 522 |
524 return local_scope; | 523 return local_scope; |
525 } | 524 } |
526 | 525 |
527 | 526 |
528 // Create a plain JSObject which materializes the closure content for the | 527 // Create a plain JSObject which materializes the closure content for the |
529 // context. | 528 // context. |
530 Handle<JSObject> ScopeIterator::MaterializeClosure() { | 529 Handle<JSObject> ScopeIterator::MaterializeClosure() { |
531 Handle<Context> context = CurrentContext(); | 530 Handle<Context> context = CurrentContext(); |
532 DCHECK(context->IsFunctionContext()); | 531 DCHECK(context->IsFunctionContext() || context->IsEvalContext()); |
533 | 532 |
534 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 533 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
535 Handle<ScopeInfo> scope_info(shared->scope_info()); | 534 Handle<ScopeInfo> scope_info(shared->scope_info()); |
536 | 535 |
537 // Allocate and initialize a JSObject with all the content of this function | 536 // Allocate and initialize a JSObject with all the content of this function |
538 // closure. | 537 // closure. |
539 Handle<JSObject> closure_scope = | 538 Handle<JSObject> closure_scope = |
540 isolate_->factory()->NewJSObjectWithNullProto(); | 539 isolate_->factory()->NewJSObjectWithNullProto(); |
541 | 540 |
542 // Fill all context locals to the context extension. | 541 // Fill all context locals to the context extension. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 variable_name, new_value)) { | 719 variable_name, new_value)) { |
721 return true; | 720 return true; |
722 } | 721 } |
723 | 722 |
724 return false; | 723 return false; |
725 } | 724 } |
726 | 725 |
727 // This method copies structure of MaterializeClosure method above. | 726 // This method copies structure of MaterializeClosure method above. |
728 bool ScopeIterator::SetClosureVariableValue(Handle<String> variable_name, | 727 bool ScopeIterator::SetClosureVariableValue(Handle<String> variable_name, |
729 Handle<Object> new_value) { | 728 Handle<Object> new_value) { |
730 DCHECK(CurrentContext()->IsFunctionContext()); | 729 DCHECK(CurrentContext()->IsFunctionContext() || |
| 730 CurrentContext()->IsEvalContext()); |
731 return SetContextVariableValue(CurrentScopeInfo(), CurrentContext(), | 731 return SetContextVariableValue(CurrentScopeInfo(), CurrentContext(), |
732 variable_name, new_value); | 732 variable_name, new_value); |
733 } | 733 } |
734 | 734 |
735 bool ScopeIterator::SetScriptVariableValue(Handle<String> variable_name, | 735 bool ScopeIterator::SetScriptVariableValue(Handle<String> variable_name, |
736 Handle<Object> new_value) { | 736 Handle<Object> new_value) { |
737 Handle<String> internalized_variable_name = | 737 Handle<String> internalized_variable_name = |
738 isolate_->factory()->InternalizeString(variable_name); | 738 isolate_->factory()->InternalizeString(variable_name); |
739 Handle<Context> context = CurrentContext(); | 739 Handle<Context> context = CurrentContext(); |
740 Handle<ScriptContextTable> script_contexts( | 740 Handle<ScriptContextTable> script_contexts( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 857 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
858 if (beg_pos <= position && position < end_pos) { | 858 if (beg_pos <= position && position < end_pos) { |
859 GetNestedScopeChain(isolate, inner_scope, position); | 859 GetNestedScopeChain(isolate, inner_scope, position); |
860 return; | 860 return; |
861 } | 861 } |
862 } | 862 } |
863 } | 863 } |
864 | 864 |
865 } // namespace internal | 865 } // namespace internal |
866 } // namespace v8 | 866 } // namespace v8 |
OLD | NEW |