diff options
Diffstat (limited to 'deps/v8/src/debug/debug-scopes.cc')
-rw-r--r-- | deps/v8/src/debug/debug-scopes.cc | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/deps/v8/src/debug/debug-scopes.cc b/deps/v8/src/debug/debug-scopes.cc index c84d32ae7d..3434a83088 100644 --- a/deps/v8/src/debug/debug-scopes.cc +++ b/deps/v8/src/debug/debug-scopes.cc @@ -6,13 +6,14 @@ #include <memory> +#include "src/ast/ast.h" #include "src/ast/scopes.h" #include "src/debug/debug.h" #include "src/frames-inl.h" #include "src/globals.h" #include "src/isolate-inl.h" #include "src/parsing/parse-info.h" -#include "src/parsing/parser.h" +#include "src/parsing/parsing.h" #include "src/parsing/rewriter.h" namespace v8 { @@ -23,8 +24,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, : isolate_(isolate), frame_inspector_(frame_inspector), nested_scope_chain_(4), - seen_script_scope_(false), - failed_(false) { + seen_script_scope_(false) { if (!frame_inspector->GetContext()->IsContext()) { // Optimized frame, context or function cannot be materialized. Give up. return; @@ -61,10 +61,9 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, // inspect the function scope. // This can only happen if we set a break point inside right before the // return, which requires a debug info to be available. - Handle<DebugInfo> debug_info(shared_info->GetDebugInfo()); // Find the break point where execution has stopped. - BreakLocation location = BreakLocation::FromFrame(debug_info, GetFrame()); + BreakLocation location = BreakLocation::FromFrame(GetFrame()); ignore_nested_scopes = location.IsReturn(); } @@ -110,7 +109,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, // Inner function. info.reset(new ParseInfo(&zone, shared_info)); } - if (Parser::ParseStatic(info.get()) && Rewriter::Rewrite(info.get())) { + if (parsing::ParseAny(info.get()) && Rewriter::Rewrite(info.get())) { DeclarationScope* scope = info->literal()->scope(); if (!ignore_nested_scopes || collect_non_locals) { CollectNonLocals(info.get(), scope); @@ -119,26 +118,26 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, DeclarationScope::Analyze(info.get(), AnalyzeMode::kDebugger); RetrieveScopeChain(scope); } - } else if (!ignore_nested_scopes) { + } else { // A failed reparse indicates that the preparser has diverged from the // parser or that the preparse data given to the initial parse has been // faulty. We fail in debug mode but in release mode we only provide the // information we get from the context chain but nothing about // completely stack allocated scopes or stack allocated locals. // Or it could be due to stack overflow. - DCHECK(isolate_->has_pending_exception()); - failed_ = true; + // Silently fail by presenting an empty context chain. + CHECK(isolate_->has_pending_exception()); + isolate_->clear_pending_exception(); + context_ = Handle<Context>(); } UnwrapEvaluationContext(); } - ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) : isolate_(isolate), frame_inspector_(NULL), context_(function->context()), - seen_script_scope_(false), - failed_(false) { + seen_script_scope_(false) { if (!function->shared()->IsSubjectToDebugging()) context_ = Handle<Context>(); UnwrapEvaluationContext(); } @@ -148,8 +147,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, : isolate_(isolate), frame_inspector_(NULL), context_(generator->context()), - seen_script_scope_(false), - failed_(false) { + seen_script_scope_(false) { if (!generator->function()->shared()->IsSubjectToDebugging()) { context_ = Handle<Context>(); } @@ -212,7 +210,7 @@ MUST_USE_RESULT MaybeHandle<JSObject> ScopeIterator::MaterializeScopeDetails() { void ScopeIterator::Next() { - DCHECK(!failed_); + DCHECK(!Done()); ScopeType scope_type = Type(); if (scope_type == ScopeTypeGlobal) { // The global scope is always the last in the chain. @@ -249,7 +247,7 @@ void ScopeIterator::Next() { // Return the type of the current scope. ScopeIterator::ScopeType ScopeIterator::Type() { - DCHECK(!failed_); + DCHECK(!Done()); if (!nested_scope_chain_.is_empty()) { Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; switch (scope_info->scope_type()) { @@ -272,7 +270,7 @@ ScopeIterator::ScopeType ScopeIterator::Type() { DCHECK(!scope_info->HasContext() || context_->IsBlockContext()); return ScopeTypeBlock; case EVAL_SCOPE: - DCHECK(!scope_info->HasContext() || context_->IsFunctionContext()); + DCHECK(!scope_info->HasContext() || context_->IsEvalContext()); return ScopeTypeEval; } UNREACHABLE(); @@ -283,7 +281,7 @@ ScopeIterator::ScopeType ScopeIterator::Type() { // fake it. return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript; } - if (context_->IsFunctionContext()) { + if (context_->IsFunctionContext() || context_->IsEvalContext()) { return ScopeTypeClosure; } if (context_->IsCatchContext()) { @@ -304,7 +302,7 @@ ScopeIterator::ScopeType ScopeIterator::Type() { MaybeHandle<JSObject> ScopeIterator::ScopeObject() { - DCHECK(!failed_); + DCHECK(!Done()); switch (Type()) { case ScopeIterator::ScopeTypeGlobal: return Handle<JSObject>(CurrentContext()->global_proxy()); @@ -346,7 +344,7 @@ bool ScopeIterator::HasContext() { bool ScopeIterator::SetVariableValue(Handle<String> variable_name, Handle<Object> new_value) { - DCHECK(!failed_); + DCHECK(!Done()); switch (Type()) { case ScopeIterator::ScopeTypeGlobal: break; @@ -372,20 +370,19 @@ bool ScopeIterator::SetVariableValue(Handle<String> variable_name, Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() { - DCHECK(!failed_); + DCHECK(!Done()); if (!nested_scope_chain_.is_empty()) { return nested_scope_chain_.last().scope_info; - } else if (context_->IsBlockContext()) { + } else if (context_->IsBlockContext() || context_->IsFunctionContext() || + context_->IsEvalContext()) { return Handle<ScopeInfo>(context_->scope_info()); - } else if (context_->IsFunctionContext()) { - return Handle<ScopeInfo>(context_->closure()->shared()->scope_info()); } return Handle<ScopeInfo>::null(); } Handle<Context> ScopeIterator::CurrentContext() { - DCHECK(!failed_); + DCHECK(!Done()); if (Type() == ScopeTypeGlobal || Type() == ScopeTypeScript || nested_scope_chain_.is_empty()) { return context_; @@ -402,7 +399,7 @@ Handle<StringSet> ScopeIterator::GetNonLocals() { return non_locals_; } // Debug print of the content of the current scope. void ScopeIterator::DebugPrint() { OFStream os(stdout); - DCHECK(!failed_); + DCHECK(!Done()); switch (Type()) { case ScopeIterator::ScopeTypeGlobal: os << "Global:\n"; @@ -530,7 +527,7 @@ MaybeHandle<JSObject> ScopeIterator::MaterializeLocalScope() { // context. Handle<JSObject> ScopeIterator::MaterializeClosure() { Handle<Context> context = CurrentContext(); - DCHECK(context->IsFunctionContext()); + DCHECK(context->IsFunctionContext() || context->IsEvalContext()); Handle<SharedFunctionInfo> shared(context->closure()->shared()); Handle<ScopeInfo> scope_info(shared->scope_info()); @@ -728,18 +725,21 @@ bool ScopeIterator::SetInnerScopeVariableValue(Handle<String> variable_name, // This method copies structure of MaterializeClosure method above. bool ScopeIterator::SetClosureVariableValue(Handle<String> variable_name, Handle<Object> new_value) { - DCHECK(CurrentContext()->IsFunctionContext()); + DCHECK(CurrentContext()->IsFunctionContext() || + CurrentContext()->IsEvalContext()); return SetContextVariableValue(CurrentScopeInfo(), CurrentContext(), variable_name, new_value); } bool ScopeIterator::SetScriptVariableValue(Handle<String> variable_name, Handle<Object> new_value) { + Handle<String> internalized_variable_name = + isolate_->factory()->InternalizeString(variable_name); Handle<Context> context = CurrentContext(); Handle<ScriptContextTable> script_contexts( context->global_object()->native_context()->script_context_table()); ScriptContextTable::LookupResult lookup_result; - if (ScriptContextTable::Lookup(script_contexts, variable_name, + if (ScriptContextTable::Lookup(script_contexts, internalized_variable_name, &lookup_result)) { Handle<Context> script_context = ScriptContextTable::GetContext( script_contexts, lookup_result.context_index); @@ -838,8 +838,12 @@ void ScopeIterator::GetNestedScopeChain(Isolate* isolate, Scope* scope, int position) { if (scope->is_function_scope()) { // Do not collect scopes of nested inner functions inside the current one. + // Nested arrow functions could have the same end positions. Handle<JSFunction> function = frame_inspector_->GetFunction(); - if (scope->end_position() < function->shared()->end_position()) return; + if (scope->start_position() > function->shared()->start_position() && + scope->end_position() <= function->shared()->end_position()) { + return; + } } if (scope->is_hidden()) { // We need to add this chain element in case the scope has a context |