Commit 5ebde77e authored by yangguo's avatar yangguo Committed by Commit bot

[debugger] handle stack overflow. Fail silently.

R=jgruber@chromium.org
BUG=v8:5654

Review-Url: https://codereview.chromium.org/2511733002
Cr-Commit-Position: refs/heads/master@{#41139}
parent 4097c850
......@@ -1806,7 +1806,22 @@ class InspectorFrontend final : public v8_inspector::V8Inspector::Channel {
Local<Value> args[] = {message};
MaybeLocal<Value> result = Local<Function>::Cast(callback)->Call(
context, Undefined(isolate_), 1, args);
CHECK(!result.IsEmpty()); // Listeners may not throw.
#ifdef DEBUG
if (try_catch.HasCaught()) {
Local<Object> exception = Local<Object>::Cast(try_catch.Exception());
Local<String> key = v8::String::NewFromUtf8(isolate_, "message",
v8::NewStringType::kNormal)
.ToLocalChecked();
Local<String> expected =
v8::String::NewFromUtf8(isolate_,
"Maximum call stack size exceeded",
v8::NewStringType::kNormal)
.ToLocalChecked();
CHECK(exception->Get(context, key)
.ToLocalChecked()
->StrictEquals(expected));
}
#endif
}
}
......
......@@ -158,8 +158,8 @@ DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate,
// - Look up in the original context.
// - Check the whitelist to find out whether to skip contexts during lookup.
const ScopeIterator::Option option = ScopeIterator::COLLECT_NON_LOCALS;
for (ScopeIterator it(isolate, &frame_inspector, option);
!it.Failed() && !it.Done(); it.Next()) {
for (ScopeIterator it(isolate, &frame_inspector, option); !it.Done();
it.Next()) {
ScopeIterator::ScopeType scope_type = it.Type();
if (scope_type == ScopeIterator::ScopeTypeLocal) {
DCHECK_EQ(FUNCTION_SCOPE, it.CurrentScopeInfo()->scope_type());
......
......@@ -23,8 +23,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;
......@@ -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()) {
......@@ -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,7 +370,7 @@ 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()) {
......@@ -385,7 +383,7 @@ Handle<ScopeInfo> ScopeIterator::CurrentScopeInfo() {
Handle<Context> ScopeIterator::CurrentContext() {
DCHECK(!failed_);
DCHECK(!Done());
if (Type() == ScopeTypeGlobal || Type() == ScopeTypeScript ||
nested_scope_chain_.is_empty()) {
return context_;
......@@ -402,7 +400,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";
......
......@@ -50,12 +50,7 @@ class ScopeIterator {
MUST_USE_RESULT MaybeHandle<JSObject> MaterializeScopeDetails();
// More scopes?
bool Done() {
DCHECK(!failed_);
return context_.is_null();
}
bool Failed() { return failed_; }
bool Done() { return context_.is_null(); }
// Move to the next scope.
void Next();
......@@ -103,7 +98,6 @@ class ScopeIterator {
List<ExtendedScopeInfo> nested_scope_chain_;
Handle<StringSet> non_locals_;
bool seen_script_scope_;
bool failed_;
inline JavaScriptFrame* GetFrame() {
return frame_inspector_->GetArgumentsFrame();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment