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

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

Issue 9333001: Include stack trace to error message when constructing a new Error with another Error as argument. (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/messages.js ('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 13520 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 13538 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message,
13539 v8::Handle<v8::Value> data) { 13539 v8::Handle<v8::Value> data) {
13540 // Use the frame where JavaScript is called from. 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(); 13541 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
13543 CHECK(!stack_trace.IsEmpty()); 13542 CHECK(!stack_trace.IsEmpty());
13544 int frame_count = stack_trace->GetFrameCount(); 13543 int frame_count = stack_trace->GetFrameCount();
13545 CHECK_EQ(3, frame_count); 13544 CHECK_EQ(3, frame_count);
13546 int line_number[] = {1, 2, 5}; 13545 int line_number[] = {1, 2, 5};
13547 for (int i = 0; i < frame_count; i++) { 13546 for (int i = 0; i < frame_count; i++) {
13548 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 13547 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
13549 } 13548 }
13550 } 13549 }
13551 13550
(...skipping 21 matching lines...) Expand all
13573 " } \n" 13572 " } \n"
13574 "} \n"; 13573 "} \n";
13575 v8::V8::AddMessageListener(RethrowStackTraceHandler); 13574 v8::V8::AddMessageListener(RethrowStackTraceHandler);
13576 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 13575 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
13577 CompileRun(source); 13576 CompileRun(source);
13578 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 13577 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
13579 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler); 13578 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler);
13580 } 13579 }
13581 13580
13582 13581
13582 static void RethrowWrapStackTraceHandler(v8::Handle<v8::Message> message,
13583 v8::Handle<v8::Value> data) {
13584 // Use the frame where JavaScript is called from.
13585 v8::Handle<v8::String> error_message = message->Get();
13586 CHECK_EQ("Uncaught Error: ReferenceError: error is not defined\n"
13587 " at g (unknown source)\n"
13588 " at f (unknown source)\n"
13589 " at unknown source",
13590 *v8::String::AsciiValue(error_message));
13591 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
13592 CHECK(!stack_trace.IsEmpty());
13593 int frame_count = stack_trace->GetFrameCount();
13594 CHECK_EQ(2, frame_count);
13595 int line_number[] = {3, 10};
13596 for (int i = 0; i < frame_count; i++) {
13597 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
13598 }
13599 }
13600
13601
13602 // Test that we only return the stack trace at the site where the exception
13603 // is first thrown (not where it is rethrown).
13604 TEST(RethrowWrapStackTrace) {
13605 v8::HandleScope scope;
13606 LocalContext env;
13607 // We make sure that
13608 // - the stack trace of the ReferenceError in g() is reported.
13609 // - the stack trace is not overwritten when e1 is rethrown by t().
13610 // - the stack trace of e2 does not overwrite that of e1.
13611 const char* source =
13612 "function g() { error; } \n"
13613 "function f() { g(); } \n"
13614 "function t(e) { throw new Error(e); } \n"
13615 "try { \n"
13616 " f(); \n"
13617 "} catch (e1) { \n"
13618 " try { \n"
13619 " error; \n"
13620 " } catch (e2) { \n"
13621 " t(e1); \n"
13622 " } \n"
13623 "} \n";
13624 v8::V8::AddMessageListener(RethrowWrapStackTraceHandler);
13625 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
13626 CompileRun(source);
13627 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
13628 v8::V8::RemoveMessageListeners(RethrowWrapStackTraceHandler);
13629 }
13630
13631
13583 static void RethrowPrimitiveStackTraceHandler(v8::Handle<v8::Message> message, 13632 static void RethrowPrimitiveStackTraceHandler(v8::Handle<v8::Message> message,
13584 v8::Handle<v8::Value> data) { 13633 v8::Handle<v8::Value> data) {
13585 v8::Handle<v8::String> error_message = message->Get();
13586 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 13634 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
13587 CHECK(!stack_trace.IsEmpty()); 13635 CHECK(!stack_trace.IsEmpty());
13588 int frame_count = stack_trace->GetFrameCount(); 13636 int frame_count = stack_trace->GetFrameCount();
13589 CHECK_EQ(2, frame_count); 13637 CHECK_EQ(2, frame_count);
13590 int line_number[] = {3, 7}; 13638 int line_number[] = {3, 7};
13591 for (int i = 0; i < frame_count; i++) { 13639 for (int i = 0; i < frame_count; i++) {
13592 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 13640 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
13593 } 13641 }
13594 } 13642 }
13595 13643
(...skipping 17 matching lines...) Expand all
13613 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 13661 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
13614 CompileRun(source); 13662 CompileRun(source);
13615 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 13663 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
13616 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler); 13664 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler);
13617 } 13665 }
13618 13666
13619 13667
13620 static void RethrowExistingStackTraceHandler(v8::Handle<v8::Message> message, 13668 static void RethrowExistingStackTraceHandler(v8::Handle<v8::Message> message,
13621 v8::Handle<v8::Value> data) { 13669 v8::Handle<v8::Value> data) {
13622 // Use the frame where JavaScript is called from. 13670 // Use the frame where JavaScript is called from.
13623 v8::Handle<v8::String> error_message = message->Get();
13624 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 13671 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
13625 CHECK(!stack_trace.IsEmpty()); 13672 CHECK(!stack_trace.IsEmpty());
13626 CHECK_EQ(1, stack_trace->GetFrameCount()); 13673 CHECK_EQ(1, stack_trace->GetFrameCount());
13627 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); 13674 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber());
13628 } 13675 }
13629 13676
13630 13677
13631 // Test that the stack trace is captured when the error object is created and 13678 // Test that the stack trace is captured when the error object is created and
13632 // not where it is thrown. 13679 // not where it is thrown.
13633 TEST(RethrowExistingStackTrace) { 13680 TEST(RethrowExistingStackTrace) {
(...skipping 2420 matching lines...) Expand 10 before | Expand all | Expand 10 after
16054 CompileRun("throw 'exception';"); 16101 CompileRun("throw 'exception';");
16055 } 16102 }
16056 16103
16057 16104
16058 TEST(CallCompletedCallbackTwoExceptions) { 16105 TEST(CallCompletedCallbackTwoExceptions) {
16059 v8::HandleScope scope; 16106 v8::HandleScope scope;
16060 LocalContext env; 16107 LocalContext env;
16061 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 16108 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
16062 CompileRun("throw 'first exception';"); 16109 CompileRun("throw 'first exception';");
16063 } 16110 }
OLDNEW
« no previous file with comments | « src/messages.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698