Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index b7f76febe29bb13441912880cae68f1d661ac69f..f1b9d6c31b6e65e94569bd7e7980a50e4ce159bb 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -422,12 +422,6 @@ bool CounterMap::Match(void* key1, void* key2) { |
| } |
| -// Converts a V8 value to a C string. |
| -const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
| - return *value ? *value : "<string conversion failed>"; |
| -} |
| - |
| - |
| ScriptCompiler::CachedData* CompileForCachedData( |
| Local<String> source, Local<Value> name, |
| ScriptCompiler::CompileOptions compile_options) { |
| @@ -1256,12 +1250,17 @@ void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { |
| HandleScope handle_scope(isolate); |
| - Local<Context> context; |
| - bool enter_context = !isolate->InContext(); |
| + Local<Context> context = isolate->GetCurrentContext(); |
| + bool enter_context = context.IsEmpty(); |
| if (enter_context) { |
| context = Local<Context>::New(isolate, evaluation_context_); |
| context->Enter(); |
| } |
| + // Converts a V8 value to a C string. |
| + auto ToCString = [](const v8::String::Utf8Value& value) { |
|
titzer
2016/12/12 11:51:33
Finally a decent use of C++ lambda!
|
| + return *value ? *value : "<string conversion failed>"; |
| + }; |
| + |
| v8::String::Utf8Value exception(try_catch->Exception()); |
| const char* exception_string = ToCString(exception); |
| Local<Message> message = try_catch->Message(); |
| @@ -1269,40 +1268,40 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { |
| // V8 didn't provide any extra information about this error; just |
| // print the exception. |
| printf("%s\n", exception_string); |
| + } else if (message->GetScriptOrigin().Options().IsWasm()) { |
| + // Print <WASM>[(function index)]((function name))+(offset): (message). |
| + int function_index = message->GetLineNumber(context).FromJust() - 1; |
| + int offset = message->GetStartColumn(context).FromJust(); |
| + printf("<WASM>[%d]+%d: %s\n", function_index, offset, exception_string); |
| } else { |
| // Print (filename):(line number): (message). |
| v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); |
| const char* filename_string = ToCString(filename); |
| - Maybe<int> maybeline = message->GetLineNumber(isolate->GetCurrentContext()); |
| - int linenum = maybeline.IsJust() ? maybeline.FromJust() : -1; |
| + int linenum = message->GetLineNumber(context).FromMaybe(-1); |
| printf("%s:%i: %s\n", filename_string, linenum, exception_string); |
| Local<String> sourceline; |
| - if (message->GetSourceLine(isolate->GetCurrentContext()) |
| - .ToLocal(&sourceline)) { |
| + if (message->GetSourceLine(context).ToLocal(&sourceline)) { |
| // Print line of source code. |
| v8::String::Utf8Value sourcelinevalue(sourceline); |
| const char* sourceline_string = ToCString(sourcelinevalue); |
| printf("%s\n", sourceline_string); |
| // Print wavy underline (GetUnderline is deprecated). |
| - int start = |
| - message->GetStartColumn(isolate->GetCurrentContext()).FromJust(); |
| + int start = message->GetStartColumn(context).FromJust(); |
| for (int i = 0; i < start; i++) { |
| printf(" "); |
| } |
| - int end = message->GetEndColumn(isolate->GetCurrentContext()).FromJust(); |
| + int end = message->GetEndColumn(context).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) && |
| - stack_trace_string->IsString()) { |
| - v8::String::Utf8Value stack_trace( |
| - Local<String>::Cast(stack_trace_string)); |
| - printf("%s\n", ToCString(stack_trace)); |
| - } |
| + } |
| + Local<Value> stack_trace_string; |
| + if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) && |
| + stack_trace_string->IsString()) { |
| + v8::String::Utf8Value stack_trace(Local<String>::Cast(stack_trace_string)); |
| + printf("%s\n", ToCString(stack_trace)); |
| } |
| printf("\n"); |
| if (enter_context) context->Exit(); |