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

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

Issue 9310063: When rethrowing an exception, print the stack trace of its original site instead of rethrow site. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 months 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 13517 matching lines...) Expand 10 before | Expand all | Expand 10 after
13528 " 'isConstructor'];\n" 13528 " 'isConstructor'];\n"
13529 "for (var i = 0; i < setters.length; i++) {\n" 13529 "for (var i = 0; i < setters.length; i++) {\n"
13530 " var prop = setters[i];\n" 13530 " var prop = setters[i];\n"
13531 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" 13531 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n"
13532 "}\n"); 13532 "}\n");
13533 CompileRun("throw 'exception';"); 13533 CompileRun("throw 'exception';");
13534 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 13534 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
13535 } 13535 }
13536 13536
13537 13537
13538 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message,
13539 v8::Handle<v8::Value> data) {
13540 // Use the frame where JavaScript is called from.
13541 v8::Handle<v8::String> error_message = message->Get();
13542 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
13543 CHECK(!stack_trace.IsEmpty());
13544 int frame_count = stack_trace->GetFrameCount();
13545 CHECK_EQ(3, frame_count);
13546 int line_number[] = {1, 2, 5};
13547 for (int i = 0; i < frame_count; i++) {
13548 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
13549 }
13550 }
13551
13552
13553 // Test that we only return the stack trace at the site where the exception
13554 // is first thrown (not where it is rethrown).
13555 TEST(RethrowStackTrace) {
13556 v8::HandleScope scope;
13557 LocalContext env;
13558 const char* source =
13559 "function g() { error; } \n"
13560 "function f() { g(); } \n"
13561 "function t(e) { throw(e); } \n"
13562 "try { \n"
13563 " f(); \n"
13564 "} catch (e1) { \n"
13565 " t(e1); \n"
13566 "} \n";
13567 v8::V8::AddMessageListener(RethrowStackTraceHandler);
13568 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
13569 CompileRun(source);
13570 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
13571 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler);
13572 }
13573
13574
13538 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { 13575 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) {
13539 v8::HandleScope scope; 13576 v8::HandleScope scope;
13540 v8::Handle<v8::StackTrace> stackTrace = 13577 v8::Handle<v8::StackTrace> stackTrace =
13541 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 13578 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
13542 CHECK_EQ(5, stackTrace->GetFrameCount()); 13579 CHECK_EQ(5, stackTrace->GetFrameCount());
13543 v8::Handle<v8::String> url = v8_str("eval_url"); 13580 v8::Handle<v8::String> url = v8_str("eval_url");
13544 for (int i = 0; i < 3; i++) { 13581 for (int i = 0; i < 3; i++) {
13545 v8::Handle<v8::String> name = 13582 v8::Handle<v8::String> name =
13546 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 13583 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
13547 CHECK(!name.IsEmpty()); 13584 CHECK(!name.IsEmpty());
(...skipping 2397 matching lines...) Expand 10 before | Expand all | Expand 10 after
15945 CompileRun("throw 'exception';"); 15982 CompileRun("throw 'exception';");
15946 } 15983 }
15947 15984
15948 15985
15949 TEST(CallCompletedCallbackTwoExceptions) { 15986 TEST(CallCompletedCallbackTwoExceptions) {
15950 v8::HandleScope scope; 15987 v8::HandleScope scope;
15951 LocalContext env; 15988 LocalContext env;
15952 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 15989 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
15953 CompileRun("throw 'first exception';"); 15990 CompileRun("throw 'first exception';");
15954 } 15991 }
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