[d8] Make exception reporting more resilient.

This makes sure exception reporting done by the debug shell behaves
gracefully even near the stack limit. When line number determination
fails we just fallback to not printing source information.

R=yangguo@chromium.org
TEST=mjsunit/regress/regress-crbug-620253
BUG=chromium:620253

Review-Url: https://codereview.chromium.org/2069543007
Cr-Commit-Position: refs/heads/master@{#37031}
This commit is contained in:
mstarzinger 2016-06-16 03:12:06 -07:00 committed by Commit bot
parent d6b3b7e61c
commit e55384b28e
2 changed files with 27 additions and 17 deletions

View File

@ -925,25 +925,28 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
// Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filename_string = ToCString(filename);
int linenum =
message->GetLineNumber(isolate->GetCurrentContext()).FromJust();
Maybe<int> maybeline = message->GetLineNumber(isolate->GetCurrentContext());
int linenum = maybeline.IsJust() ? maybeline.FromJust() : -1;
printf("%s:%i: %s\n", filename_string, linenum, exception_string);
// Print line of source code.
v8::String::Utf8Value sourceline(
message->GetSourceLine(isolate->GetCurrentContext()).ToLocalChecked());
const char* sourceline_string = ToCString(sourceline);
printf("%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated).
int start =
message->GetStartColumn(isolate->GetCurrentContext()).FromJust();
for (int i = 0; i < start; i++) {
printf(" ");
if (maybeline.IsJust()) {
// Print line of source code.
v8::String::Utf8Value sourceline(
message->GetSourceLine(isolate->GetCurrentContext())
.ToLocalChecked());
const char* sourceline_string = ToCString(sourceline);
printf("%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated).
int start =
message->GetStartColumn(isolate->GetCurrentContext()).FromJust();
for (int i = 0; i < start; i++) {
printf(" ");
}
int end = message->GetEndColumn(isolate->GetCurrentContext()).FromJust();
for (int i = start; i < end; i++) {
printf("^");
}
printf("\n");
}
int end = message->GetEndColumn(isolate->GetCurrentContext()).FromJust();
for (int i = start; i < end; i++) {
printf("^");
}
printf("\n");
Local<Value> stack_trace_string;
if (try_catch->StackTrace(isolate->GetCurrentContext())
.ToLocal(&stack_trace_string) &&

View File

@ -0,0 +1,7 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --throws
load("test/mjsunit/regress/regress-crbug-620253.js");