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

Side by Side Diff: test/cctest/test-api.cc

Issue 674423002: Get stack trace for uncaught exceptions/promise rejections from the simple stack when available. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | no next file » | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 17609 matching lines...) Expand 10 before | Expand all | Expand 10 after
17620 v8::Handle<Value> detailed_result( 17620 v8::Handle<Value> detailed_result(
17621 detailed_script->BindToCurrentContext()->Run()); 17621 detailed_script->BindToCurrentContext()->Run());
17622 CHECK(!detailed_result.IsEmpty()); 17622 CHECK(!detailed_result.IsEmpty());
17623 CHECK(detailed_result->IsObject()); 17623 CHECK(detailed_result->IsObject());
17624 } 17624 }
17625 17625
17626 17626
17627 static void StackTraceForUncaughtExceptionListener( 17627 static void StackTraceForUncaughtExceptionListener(
17628 v8::Handle<v8::Message> message, 17628 v8::Handle<v8::Message> message,
17629 v8::Handle<Value>) { 17629 v8::Handle<Value>) {
17630 report_count++;
17630 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 17631 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
17631 CHECK_EQ(2, stack_trace->GetFrameCount()); 17632 CHECK_EQ(2, stack_trace->GetFrameCount());
17632 checkStackFrame("origin", "foo", 2, 3, false, false, 17633 checkStackFrame("origin", "foo", 2, 3, false, false,
17633 stack_trace->GetFrame(0)); 17634 stack_trace->GetFrame(0));
17634 checkStackFrame("origin", "bar", 5, 3, false, false, 17635 checkStackFrame("origin", "bar", 5, 3, false, false,
17635 stack_trace->GetFrame(1)); 17636 stack_trace->GetFrame(1));
17636 } 17637 }
17637 17638
17638 17639
17639 TEST(CaptureStackTraceForUncaughtException) { 17640 TEST(CaptureStackTraceForUncaughtException) {
(...skipping 10 matching lines...) Expand all
17650 "function bar() {\n" 17651 "function bar() {\n"
17651 " foo();\n" 17652 " foo();\n"
17652 "};", 17653 "};",
17653 "origin"); 17654 "origin");
17654 v8::Local<v8::Object> global = env->Global(); 17655 v8::Local<v8::Object> global = env->Global();
17655 Local<Value> trouble = global->Get(v8_str("bar")); 17656 Local<Value> trouble = global->Get(v8_str("bar"));
17656 CHECK(trouble->IsFunction()); 17657 CHECK(trouble->IsFunction());
17657 Function::Cast(*trouble)->Call(global, 0, NULL); 17658 Function::Cast(*trouble)->Call(global, 0, NULL);
17658 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 17659 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
17659 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); 17660 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
17661 CHECK_EQ(1, report_count);
17660 } 17662 }
17661 17663
17662 17664
17665 TEST(GetStackTraceForUncaughtExceptionFromSimpleStackTrace) {
17666 report_count = 0;
17667 LocalContext env;
17668 v8::HandleScope scope(env->GetIsolate());
17669
17670 // Create an Error object first.
17671 CompileRunWithOrigin(
17672 "function foo() {\n"
17673 "e=new Error('err');\n"
17674 "};\n"
17675 "function bar() {\n"
17676 " foo();\n"
17677 "};\n"
17678 "var e;",
17679 "origin");
17680 v8::Local<v8::Object> global = env->Global();
17681 Local<Value> trouble = global->Get(v8_str("bar"));
17682 CHECK(trouble->IsFunction());
17683 Function::Cast(*trouble)->Call(global, 0, NULL);
17684
17685 // Enable capturing detailed stack trace late, and throw the exception.
17686 // The detailed stack trace should be extracted from the simple stack.
17687 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener);
17688 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
17689 CompileRunWithOrigin("throw e", "origin");
17690 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
17691 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
17692 CHECK_EQ(1, report_count);
17693 }
17694
17695
17663 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { 17696 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
17664 LocalContext env; 17697 LocalContext env;
17665 v8::HandleScope scope(env->GetIsolate()); 17698 v8::HandleScope scope(env->GetIsolate());
17666 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 17699 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true,
17667 1024, 17700 1024,
17668 v8::StackTrace::kDetailed); 17701 v8::StackTrace::kDetailed);
17669 17702
17670 CompileRun( 17703 CompileRun(
17671 "var setters = ['column', 'lineNumber', 'scriptName',\n" 17704 "var setters = ['column', 'lineNumber', 'scriptName',\n"
17672 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n" 17705 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
(...skipping 6312 matching lines...) Expand 10 before | Expand all | Expand 10 after
23985 char chunk2[] = 24018 char chunk2[] =
23986 "XX\xec\x92\x81r = 13;\n" 24019 "XX\xec\x92\x81r = 13;\n"
23987 " return foob\xec\x92\x81\xec\x92\x81r;\n" 24020 " return foob\xec\x92\x81\xec\x92\x81r;\n"
23988 "}\n"; 24021 "}\n";
23989 chunk1[strlen(chunk1) - 1] = reference[0]; 24022 chunk1[strlen(chunk1) - 1] = reference[0];
23990 chunk2[0] = reference[1]; 24023 chunk2[0] = reference[1];
23991 chunk2[1] = reference[2]; 24024 chunk2[1] = reference[2];
23992 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 24025 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23993 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 24026 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
23994 } 24027 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698