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