| 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/compiler.h" | 10 #include "src/compiler.h" |
| 11 #include "src/debug/debug.h" | 11 #include "src/debug/debug.h" |
| 12 #include "src/frames-inl.h" | 12 #include "src/frames-inl.h" |
| 13 #include "src/globals.h" | 13 #include "src/globals.h" |
| 14 #include "src/isolate-inl.h" | 14 #include "src/isolate-inl.h" |
| 15 #include "src/parsing/parser.h" | 15 #include "src/parsing/parser.h" |
| 16 #include "src/parsing/rewriter.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 | 20 |
| 20 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, | 21 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, |
| 21 ScopeIterator::Option option) | 22 ScopeIterator::Option option) |
| 22 : isolate_(isolate), | 23 : isolate_(isolate), |
| 23 frame_inspector_(frame_inspector), | 24 frame_inspector_(frame_inspector), |
| 24 nested_scope_chain_(4), | 25 nested_scope_chain_(4), |
| 25 seen_script_scope_(false), | 26 seen_script_scope_(false), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 info->set_eval(); | 101 info->set_eval(); |
| 101 info->set_context(Handle<Context>(function->context())); | 102 info->set_context(Handle<Context>(function->context())); |
| 102 // Language mode may be inherited from the eval caller. | 103 // Language mode may be inherited from the eval caller. |
| 103 // Retrieve it from shared function info. | 104 // Retrieve it from shared function info. |
| 104 info->set_language_mode(shared_info->language_mode()); | 105 info->set_language_mode(shared_info->language_mode()); |
| 105 } | 106 } |
| 106 } else { | 107 } else { |
| 107 // Inner function. | 108 // Inner function. |
| 108 info.reset(new ParseInfo(&zone, function)); | 109 info.reset(new ParseInfo(&zone, function)); |
| 109 } | 110 } |
| 110 Scope* scope = NULL; | 111 if (Parser::ParseStatic(info.get()) && Rewriter::Rewrite(info.get())) { |
| 111 if (Compiler::ParseAndAnalyze(info.get())) scope = info->literal()->scope(); | 112 DeclarationScope* scope = info->literal()->scope(); |
| 112 if (!ignore_nested_scopes) RetrieveScopeChain(scope); | 113 if (!ignore_nested_scopes || collect_non_locals) { |
| 113 if (collect_non_locals) CollectNonLocals(scope); | 114 CollectNonLocals(info.get(), scope); |
| 115 } |
| 116 if (!ignore_nested_scopes) { |
| 117 AstNodeFactory ast_node_factory(info.get()->ast_value_factory()); |
| 118 scope->AllocateVariables(info.get(), &ast_node_factory); |
| 119 RetrieveScopeChain(scope); |
| 120 } |
| 121 } else if (!ignore_nested_scopes) { |
| 122 // A failed reparse indicates that the preparser has diverged from the |
| 123 // parser or that the preparse data given to the initial parse has been |
| 124 // faulty. We fail in debug mode but in release mode we only provide the |
| 125 // information we get from the context chain but nothing about |
| 126 // completely stack allocated scopes or stack allocated locals. |
| 127 // Or it could be due to stack overflow. |
| 128 DCHECK(isolate_->has_pending_exception()); |
| 129 failed_ = true; |
| 130 } |
| 114 UnwrapEvaluationContext(); | 131 UnwrapEvaluationContext(); |
| 115 } | 132 } |
| 116 | 133 |
| 117 | 134 |
| 118 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) | 135 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) |
| 119 : isolate_(isolate), | 136 : isolate_(isolate), |
| 120 frame_inspector_(NULL), | 137 frame_inspector_(NULL), |
| 121 context_(function->context()), | 138 context_(function->context()), |
| 122 seen_script_scope_(false), | 139 seen_script_scope_(false), |
| 123 failed_(false) { | 140 failed_(false) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 ->Print(os); | 441 ->Print(os); |
| 425 break; | 442 break; |
| 426 | 443 |
| 427 default: | 444 default: |
| 428 UNREACHABLE(); | 445 UNREACHABLE(); |
| 429 } | 446 } |
| 430 PrintF("\n"); | 447 PrintF("\n"); |
| 431 } | 448 } |
| 432 #endif | 449 #endif |
| 433 | 450 |
| 451 void ScopeIterator::RetrieveScopeChain(DeclarationScope* scope) { |
| 452 DCHECK_NOT_NULL(scope); |
| 453 int source_position = frame_inspector_->GetSourcePosition(); |
| 454 GetNestedScopeChain(isolate_, scope, source_position); |
| 455 } |
| 434 | 456 |
| 435 void ScopeIterator::RetrieveScopeChain(Scope* scope) { | 457 void ScopeIterator::CollectNonLocals(ParseInfo* info, DeclarationScope* scope) { |
| 436 if (scope != NULL) { | 458 DCHECK_NOT_NULL(scope); |
| 437 int source_position = frame_inspector_->GetSourcePosition(); | 459 DCHECK(non_locals_.is_null()); |
| 438 GetNestedScopeChain(isolate_, scope, source_position); | 460 non_locals_ = scope->CollectNonLocals(info, StringSet::New(isolate_)); |
| 439 } else { | |
| 440 // A failed reparse indicates that the preparser has diverged from the | |
| 441 // parser or that the preparse data given to the initial parse has been | |
| 442 // faulty. We fail in debug mode but in release mode we only provide the | |
| 443 // information we get from the context chain but nothing about | |
| 444 // completely stack allocated scopes or stack allocated locals. | |
| 445 // Or it could be due to stack overflow. | |
| 446 DCHECK(isolate_->has_pending_exception()); | |
| 447 failed_ = true; | |
| 448 } | |
| 449 } | 461 } |
| 450 | 462 |
| 451 | 463 |
| 452 void ScopeIterator::CollectNonLocals(Scope* scope) { | |
| 453 if (scope != NULL) { | |
| 454 DCHECK(non_locals_.is_null()); | |
| 455 non_locals_ = scope->CollectNonLocals(StringSet::New(isolate_)); | |
| 456 } | |
| 457 } | |
| 458 | |
| 459 | |
| 460 MaybeHandle<JSObject> ScopeIterator::MaterializeScriptScope() { | 464 MaybeHandle<JSObject> ScopeIterator::MaterializeScriptScope() { |
| 461 Handle<JSGlobalObject> global(CurrentContext()->global_object()); | 465 Handle<JSGlobalObject> global(CurrentContext()->global_object()); |
| 462 Handle<ScriptContextTable> script_contexts( | 466 Handle<ScriptContextTable> script_contexts( |
| 463 global->native_context()->script_context_table()); | 467 global->native_context()->script_context_table()); |
| 464 | 468 |
| 465 Handle<JSObject> script_scope = | 469 Handle<JSObject> script_scope = |
| 466 isolate_->factory()->NewJSObjectWithNullProto(); | 470 isolate_->factory()->NewJSObjectWithNullProto(); |
| 467 | 471 |
| 468 for (int context_index = 0; context_index < script_contexts->used(); | 472 for (int context_index = 0; context_index < script_contexts->used(); |
| 469 context_index++) { | 473 context_index++) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); | 817 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden()); |
| 814 if (beg_pos <= position && position < end_pos) { | 818 if (beg_pos <= position && position < end_pos) { |
| 815 GetNestedScopeChain(isolate, inner_scope, position); | 819 GetNestedScopeChain(isolate, inner_scope, position); |
| 816 return; | 820 return; |
| 817 } | 821 } |
| 818 } | 822 } |
| 819 } | 823 } |
| 820 | 824 |
| 821 } // namespace internal | 825 } // namespace internal |
| 822 } // namespace v8 | 826 } // namespace v8 |
| OLD | NEW |