Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: src/d8.cc

Issue 2563673002: [wasm] Generate correct locations for error messages (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/d8.h ('k') | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 <errno.h> 5 #include <errno.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ShellOptions Shell::options; 415 ShellOptions Shell::options;
416 base::OnceType Shell::quit_once_ = V8_ONCE_INIT; 416 base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
417 417
418 bool CounterMap::Match(void* key1, void* key2) { 418 bool CounterMap::Match(void* key1, void* key2) {
419 const char* name1 = reinterpret_cast<const char*>(key1); 419 const char* name1 = reinterpret_cast<const char*>(key1);
420 const char* name2 = reinterpret_cast<const char*>(key2); 420 const char* name2 = reinterpret_cast<const char*>(key2);
421 return strcmp(name1, name2) == 0; 421 return strcmp(name1, name2) == 0;
422 } 422 }
423 423
424 424
425 // Converts a V8 value to a C string.
426 const char* Shell::ToCString(const v8::String::Utf8Value& value) {
427 return *value ? *value : "<string conversion failed>";
428 }
429
430
431 ScriptCompiler::CachedData* CompileForCachedData( 425 ScriptCompiler::CachedData* CompileForCachedData(
432 Local<String> source, Local<Value> name, 426 Local<String> source, Local<Value> name,
433 ScriptCompiler::CompileOptions compile_options) { 427 ScriptCompiler::CompileOptions compile_options) {
434 int source_length = source->Length(); 428 int source_length = source->Length();
435 uint16_t* source_buffer = new uint16_t[source_length]; 429 uint16_t* source_buffer = new uint16_t[source_length];
436 source->Write(source_buffer, 0, source_length); 430 source->Write(source_buffer, 0, source_length);
437 int name_length = 0; 431 int name_length = 0;
438 uint16_t* name_buffer = NULL; 432 uint16_t* name_buffer = NULL;
439 if (name->IsString()) { 433 if (name->IsString()) {
440 Local<String> name_string = Local<String>::Cast(name); 434 Local<String> name_string = Local<String>::Cast(name);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 1243
1250 void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) { 1244 void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
1251 args.GetReturnValue().Set( 1245 args.GetReturnValue().Set(
1252 String::NewFromUtf8(args.GetIsolate(), V8::GetVersion(), 1246 String::NewFromUtf8(args.GetIsolate(), V8::GetVersion(),
1253 NewStringType::kNormal).ToLocalChecked()); 1247 NewStringType::kNormal).ToLocalChecked());
1254 } 1248 }
1255 1249
1256 1250
1257 void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { 1251 void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
1258 HandleScope handle_scope(isolate); 1252 HandleScope handle_scope(isolate);
1259 Local<Context> context; 1253 Local<Context> context = isolate->GetCurrentContext();
1260 bool enter_context = !isolate->InContext(); 1254 bool enter_context = context.IsEmpty();
1261 if (enter_context) { 1255 if (enter_context) {
1262 context = Local<Context>::New(isolate, evaluation_context_); 1256 context = Local<Context>::New(isolate, evaluation_context_);
1263 context->Enter(); 1257 context->Enter();
1264 } 1258 }
1259 // Converts a V8 value to a C string.
1260 auto ToCString = [](const v8::String::Utf8Value& value) {
titzer 2016/12/12 11:51:33 Finally a decent use of C++ lambda!
1261 return *value ? *value : "<string conversion failed>";
1262 };
1263
1265 v8::String::Utf8Value exception(try_catch->Exception()); 1264 v8::String::Utf8Value exception(try_catch->Exception());
1266 const char* exception_string = ToCString(exception); 1265 const char* exception_string = ToCString(exception);
1267 Local<Message> message = try_catch->Message(); 1266 Local<Message> message = try_catch->Message();
1268 if (message.IsEmpty()) { 1267 if (message.IsEmpty()) {
1269 // V8 didn't provide any extra information about this error; just 1268 // V8 didn't provide any extra information about this error; just
1270 // print the exception. 1269 // print the exception.
1271 printf("%s\n", exception_string); 1270 printf("%s\n", exception_string);
1271 } else if (message->GetScriptOrigin().Options().IsWasm()) {
1272 // Print <WASM>[(function index)]((function name))+(offset): (message).
1273 int function_index = message->GetLineNumber(context).FromJust() - 1;
1274 int offset = message->GetStartColumn(context).FromJust();
1275 printf("<WASM>[%d]+%d: %s\n", function_index, offset, exception_string);
1272 } else { 1276 } else {
1273 // Print (filename):(line number): (message). 1277 // Print (filename):(line number): (message).
1274 v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); 1278 v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
1275 const char* filename_string = ToCString(filename); 1279 const char* filename_string = ToCString(filename);
1276 Maybe<int> maybeline = message->GetLineNumber(isolate->GetCurrentContext()); 1280 int linenum = message->GetLineNumber(context).FromMaybe(-1);
1277 int linenum = maybeline.IsJust() ? maybeline.FromJust() : -1;
1278 printf("%s:%i: %s\n", filename_string, linenum, exception_string); 1281 printf("%s:%i: %s\n", filename_string, linenum, exception_string);
1279 Local<String> sourceline; 1282 Local<String> sourceline;
1280 if (message->GetSourceLine(isolate->GetCurrentContext()) 1283 if (message->GetSourceLine(context).ToLocal(&sourceline)) {
1281 .ToLocal(&sourceline)) {
1282 // Print line of source code. 1284 // Print line of source code.
1283 v8::String::Utf8Value sourcelinevalue(sourceline); 1285 v8::String::Utf8Value sourcelinevalue(sourceline);
1284 const char* sourceline_string = ToCString(sourcelinevalue); 1286 const char* sourceline_string = ToCString(sourcelinevalue);
1285 printf("%s\n", sourceline_string); 1287 printf("%s\n", sourceline_string);
1286 // Print wavy underline (GetUnderline is deprecated). 1288 // Print wavy underline (GetUnderline is deprecated).
1287 int start = 1289 int start = message->GetStartColumn(context).FromJust();
1288 message->GetStartColumn(isolate->GetCurrentContext()).FromJust();
1289 for (int i = 0; i < start; i++) { 1290 for (int i = 0; i < start; i++) {
1290 printf(" "); 1291 printf(" ");
1291 } 1292 }
1292 int end = message->GetEndColumn(isolate->GetCurrentContext()).FromJust(); 1293 int end = message->GetEndColumn(context).FromJust();
1293 for (int i = start; i < end; i++) { 1294 for (int i = start; i < end; i++) {
1294 printf("^"); 1295 printf("^");
1295 } 1296 }
1296 printf("\n"); 1297 printf("\n");
1297 } 1298 }
1298 Local<Value> stack_trace_string; 1299 }
1299 if (try_catch->StackTrace(isolate->GetCurrentContext()) 1300 Local<Value> stack_trace_string;
1300 .ToLocal(&stack_trace_string) && 1301 if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) &&
1301 stack_trace_string->IsString()) { 1302 stack_trace_string->IsString()) {
1302 v8::String::Utf8Value stack_trace( 1303 v8::String::Utf8Value stack_trace(Local<String>::Cast(stack_trace_string));
1303 Local<String>::Cast(stack_trace_string)); 1304 printf("%s\n", ToCString(stack_trace));
1304 printf("%s\n", ToCString(stack_trace));
1305 }
1306 } 1305 }
1307 printf("\n"); 1306 printf("\n");
1308 if (enter_context) context->Exit(); 1307 if (enter_context) context->Exit();
1309 } 1308 }
1310 1309
1311 1310
1312 int32_t* Counter::Bind(const char* name, bool is_histogram) { 1311 int32_t* Counter::Bind(const char* name, bool is_histogram) {
1313 int i; 1312 int i;
1314 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 1313 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
1315 name_[i] = static_cast<char>(name[i]); 1314 name_[i] = static_cast<char>(name[i]);
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 } 3020 }
3022 3021
3023 } // namespace v8 3022 } // namespace v8
3024 3023
3025 3024
3026 #ifndef GOOGLE3 3025 #ifndef GOOGLE3
3027 int main(int argc, char* argv[]) { 3026 int main(int argc, char* argv[]) {
3028 return v8::Shell::Main(argc, argv); 3027 return v8::Shell::Main(argc, argv);
3029 } 3028 }
3030 #endif 3029 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698