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

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

Issue 630373003: Add stack trace to the promise reject callback. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
« src/isolate.cc ('K') | « 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 17613 matching lines...) Expand 10 before | Expand all | Expand 10 after
17624 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 17624 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
17625 CompileRun(source); 17625 CompileRun(source);
17626 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 17626 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
17627 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 17627 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
17628 } 17628 }
17629 17629
17630 17630
17631 v8::PromiseRejectEvent reject_event = v8::kPromiseRejectWithNoHandler; 17631 v8::PromiseRejectEvent reject_event = v8::kPromiseRejectWithNoHandler;
17632 int promise_reject_counter = 0; 17632 int promise_reject_counter = 0;
17633 int promise_revoke_counter = 0; 17633 int promise_revoke_counter = 0;
17634 int promise_reject_line_number = -1;
17635 int promise_reject_frame_count = -1;
17634 17636
17635 void PromiseRejectCallback(v8::Handle<v8::Promise> promise, 17637 void PromiseRejectCallback(v8::Handle<v8::Promise> promise,
17638 v8::PromiseRejectEvent event,
17636 v8::Handle<v8::Value> value, 17639 v8::Handle<v8::Value> value,
17637 v8::PromiseRejectEvent event) { 17640 v8::Handle<v8::StackTrace> stack_trace) {
17638 if (event == v8::kPromiseRejectWithNoHandler) { 17641 if (event == v8::kPromiseRejectWithNoHandler) {
17639 promise_reject_counter++; 17642 promise_reject_counter++;
17640 CcTest::global()->Set(v8_str("rejected"), promise); 17643 CcTest::global()->Set(v8_str("rejected"), promise);
17641 CcTest::global()->Set(v8_str("value"), value); 17644 CcTest::global()->Set(v8_str("value"), value);
17645 if (!stack_trace.IsEmpty()) {
17646 promise_reject_frame_count = stack_trace->GetFrameCount();
17647 if (promise_reject_frame_count > 0) {
17648 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro")));
17649 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber();
17650 } else {
17651 promise_reject_line_number = -1;
17652 }
17653 }
17642 } else { 17654 } else {
17643 promise_revoke_counter++; 17655 promise_revoke_counter++;
17644 CcTest::global()->Set(v8_str("revoked"), promise); 17656 CcTest::global()->Set(v8_str("revoked"), promise);
17645 CHECK(value.IsEmpty()); 17657 CHECK(value.IsEmpty());
17658 CHECK(stack_trace.IsEmpty());
17646 } 17659 }
17647 } 17660 }
17648 17661
17649 17662
17650 v8::Handle<v8::Promise> GetPromise(const char* name) { 17663 v8::Handle<v8::Promise> GetPromise(const char* name) {
17651 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); 17664 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name)));
17652 } 17665 }
17653 17666
17654 17667
17655 v8::Handle<v8::Value> RejectValue() { 17668 v8::Handle<v8::Value> RejectValue() {
17656 return CcTest::global()->Get(v8_str("value")); 17669 return CcTest::global()->Get(v8_str("value"));
17657 } 17670 }
17658 17671
17659 17672
17660 void ResetPromiseStates() { 17673 void ResetPromiseStates() {
17661 promise_reject_counter = 0; 17674 promise_reject_counter = 0;
17662 promise_revoke_counter = 0; 17675 promise_revoke_counter = 0;
17676 promise_reject_line_number = -1;
17677 promise_reject_frame_count = -1;
17663 CcTest::global()->Set(v8_str("rejected"), v8_str("")); 17678 CcTest::global()->Set(v8_str("rejected"), v8_str(""));
17664 CcTest::global()->Set(v8_str("value"), v8_str("")); 17679 CcTest::global()->Set(v8_str("value"), v8_str(""));
17665 CcTest::global()->Set(v8_str("revoked"), v8_str("")); 17680 CcTest::global()->Set(v8_str("revoked"), v8_str(""));
17666 } 17681 }
17667 17682
17668 17683
17669 TEST(PromiseRejectCallback) { 17684 TEST(PromiseRejectCallback) {
17670 LocalContext env; 17685 LocalContext env;
17671 v8::Isolate* isolate = env->GetIsolate(); 17686 v8::Isolate* isolate = env->GetIsolate();
17672 v8::HandleScope scope(isolate); 17687 v8::HandleScope scope(isolate);
17673 17688
17674 isolate->SetPromiseRejectCallback(PromiseRejectCallback); 17689 isolate->SetPromiseRejectCallback(PromiseRejectCallback);
17675 17690
17676 ResetPromiseStates(); 17691 ResetPromiseStates();
17677 17692
17678 // Create promise p0. 17693 // Create promise p0.
17679 CompileRun( 17694 CompileRun(
17680 "var reject; \n" 17695 "var reject; \n"
17681 "var p0 = new Promise( \n" 17696 "var p0 = new Promise( \n"
17682 " function(res, rej) { \n" 17697 " function(res, rej) { \n"
17683 " reject = rej; \n" 17698 " reject = rej; \n"
17684 " } \n" 17699 " } \n"
17685 "); \n"); 17700 "); \n");
17686 CHECK(!GetPromise("p0")->HasHandler()); 17701 CHECK(!GetPromise("p0")->HasHandler());
17687 CHECK_EQ(0, promise_reject_counter); 17702 CHECK_EQ(0, promise_reject_counter);
17688 CHECK_EQ(0, promise_revoke_counter); 17703 CHECK_EQ(0, promise_revoke_counter);
17689 17704
17690 // Add resolve handler (and default reject handler) to p0. 17705 // Add resolve handler (and default reject handler) to p0.
17691 CompileRun("var p1 = p0.then(function(){});"); 17706 CompileRun("var p1 = p0.then(function(){});");
(...skipping 27 matching lines...) Expand all
17719 CHECK_EQ(2, promise_reject_counter); 17734 CHECK_EQ(2, promise_reject_counter);
17720 CHECK_EQ(1, promise_revoke_counter); 17735 CHECK_EQ(1, promise_revoke_counter);
17721 CHECK(GetPromise("rejected")->Equals(GetPromise("p2"))); 17736 CHECK(GetPromise("rejected")->Equals(GetPromise("p2")));
17722 CHECK(RejectValue()->Equals(v8_str("ppp"))); 17737 CHECK(RejectValue()->Equals(v8_str("ppp")));
17723 CHECK(GetPromise("revoked")->Equals(GetPromise("p1"))); 17738 CHECK(GetPromise("revoked")->Equals(GetPromise("p1")));
17724 17739
17725 ResetPromiseStates(); 17740 ResetPromiseStates();
17726 17741
17727 // Create promise q0. 17742 // Create promise q0.
17728 CompileRun( 17743 CompileRun(
17729 "var q0 = new Promise( \n" 17744 "var q0 = new Promise( \n"
17730 " function(res, rej) { \n" 17745 " function(res, rej) { \n"
17731 " reject = rej; \n" 17746 " reject = rej; \n"
17732 " } \n" 17747 " } \n"
17733 "); \n"); 17748 "); \n");
17734 CHECK(!GetPromise("q0")->HasHandler()); 17749 CHECK(!GetPromise("q0")->HasHandler());
17735 CHECK_EQ(0, promise_reject_counter); 17750 CHECK_EQ(0, promise_reject_counter);
17736 CHECK_EQ(0, promise_revoke_counter); 17751 CHECK_EQ(0, promise_revoke_counter);
17737 17752
17738 // Add reject handler to q0. 17753 // Add reject handler to q0.
17739 CompileRun("var q1 = q0.catch(function() {});"); 17754 CompileRun("var q1 = q0.catch(function() {});");
(...skipping 25 matching lines...) Expand all
17765 CHECK(!GetPromise("q2")->HasHandler()); 17780 CHECK(!GetPromise("q2")->HasHandler());
17766 CHECK(GetPromise("q_")->HasHandler()); 17781 CHECK(GetPromise("q_")->HasHandler());
17767 CHECK_EQ(2, promise_reject_counter); 17782 CHECK_EQ(2, promise_reject_counter);
17768 CHECK_EQ(1, promise_revoke_counter); 17783 CHECK_EQ(1, promise_revoke_counter);
17769 CHECK(GetPromise("rejected")->Equals(GetPromise("q2"))); 17784 CHECK(GetPromise("rejected")->Equals(GetPromise("q2")));
17770 CHECK(GetPromise("revoked")->Equals(GetPromise("q_"))); 17785 CHECK(GetPromise("revoked")->Equals(GetPromise("q_")));
17771 CHECK(RejectValue()->Equals(v8_str("qqq"))); 17786 CHECK(RejectValue()->Equals(v8_str("qqq")));
17772 17787
17773 // Add a reject handler to the resolved q1, which rejects by throwing. 17788 // Add a reject handler to the resolved q1, which rejects by throwing.
17774 CompileRun( 17789 CompileRun(
17775 "var q3 = q1.then( \n" 17790 "var q3 = q1.then( \n"
17776 " function() { \n" 17791 " function() { \n"
17777 " throw 'qqqq'; \n" 17792 " throw 'qqqq'; \n"
17778 " } \n" 17793 " } \n"
17779 "); \n"); 17794 "); \n");
17780 CHECK(GetPromise("q0")->HasHandler()); 17795 CHECK(GetPromise("q0")->HasHandler());
17781 CHECK(GetPromise("q1")->HasHandler()); 17796 CHECK(GetPromise("q1")->HasHandler());
17782 CHECK(!GetPromise("q2")->HasHandler()); 17797 CHECK(!GetPromise("q2")->HasHandler());
17783 CHECK(!GetPromise("q3")->HasHandler()); 17798 CHECK(!GetPromise("q3")->HasHandler());
17784 CHECK_EQ(3, promise_reject_counter); 17799 CHECK_EQ(3, promise_reject_counter);
17785 CHECK_EQ(1, promise_revoke_counter); 17800 CHECK_EQ(1, promise_revoke_counter);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
17861 17876
17862 // Reject s0. 17877 // Reject s0.
17863 CompileRun("reject('sss')"); 17878 CompileRun("reject('sss')");
17864 CHECK(GetPromise("s0")->HasHandler()); 17879 CHECK(GetPromise("s0")->HasHandler());
17865 CHECK(!GetPromise("s1")->HasHandler()); 17880 CHECK(!GetPromise("s1")->HasHandler());
17866 CHECK(!GetPromise("s2")->HasHandler()); 17881 CHECK(!GetPromise("s2")->HasHandler());
17867 CHECK(!GetPromise("s3")->HasHandler()); 17882 CHECK(!GetPromise("s3")->HasHandler());
17868 CHECK_EQ(3, promise_reject_counter); 17883 CHECK_EQ(3, promise_reject_counter);
17869 CHECK_EQ(0, promise_revoke_counter); 17884 CHECK_EQ(0, promise_revoke_counter);
17870 CHECK(RejectValue()->Equals(v8_str("sss"))); 17885 CHECK(RejectValue()->Equals(v8_str("sss")));
17886
17887 // Test stack frames.
17888 V8::SetCaptureStackTraceForUncaughtExceptions(true);
17889
17890 ResetPromiseStates();
17891
17892 // Create promise t0, which is rejected in the constructor with an error.
17893 CompileRunWithOrigin(
17894 "var t0 = new Promise( \n"
17895 " function(res, rej) { \n"
17896 " reference_error; \n"
17897 " } \n"
17898 "); \n",
17899 "pro", 0, 0);
17900 CHECK(!GetPromise("t0")->HasHandler());
17901 CHECK_EQ(1, promise_reject_counter);
17902 CHECK_EQ(0, promise_revoke_counter);
17903 CHECK_EQ(2, promise_reject_frame_count);
17904 CHECK_EQ(3, promise_reject_line_number);
17905
17906 ResetPromiseStates();
17907
17908 // Create promise u0 and chain u1 to it, which is rejected via throw.
17909 CompileRunWithOrigin(
17910 "var u0 = Promise.resolve(); \n"
17911 "var u1 = u0.then( \n"
17912 " function() { \n"
17913 " (function() { \n"
17914 " throw new Error(); \n"
17915 " })(); \n"
17916 " } \n"
17917 " ); \n",
17918 "pro", 0, 0);
17919 CHECK(GetPromise("u0")->HasHandler());
17920 CHECK(!GetPromise("u1")->HasHandler());
17921 CHECK_EQ(1, promise_reject_counter);
17922 CHECK_EQ(0, promise_revoke_counter);
17923 CHECK_EQ(2, promise_reject_frame_count);
17924 CHECK_EQ(5, promise_reject_line_number);
17925
17926 // Throw in u3, which handles u1's rejection.
17927 CompileRunWithOrigin(
17928 "function f() { \n"
17929 " return (function() { \n"
17930 " return new Error(); \n"
17931 " })(); \n"
17932 "} \n"
17933 "var u2 = Promise.reject(f()); \n"
17934 "var u3 = u1.catch( \n"
17935 " function() { \n"
17936 " return u2; \n"
17937 " } \n"
17938 " ); \n",
17939 "pro", 0, 0);
17940 CHECK(GetPromise("u0")->HasHandler());
17941 CHECK(GetPromise("u1")->HasHandler());
17942 CHECK(GetPromise("u2")->HasHandler());
17943 CHECK(!GetPromise("u3")->HasHandler());
17944 CHECK_EQ(3, promise_reject_counter);
17945 CHECK_EQ(2, promise_revoke_counter);
17946 CHECK_EQ(3, promise_reject_frame_count);
17947 CHECK_EQ(3, promise_reject_line_number);
17948
17949 ResetPromiseStates();
17950
17951 // Create promise rejected promise v0, which is incorrectly handled by v1
17952 // via chaining cycle.
17953 CompileRunWithOrigin(
17954 "var v0 = Promise.reject(); \n"
17955 "var v1 = v0.catch( \n"
17956 " function() { \n"
17957 " return v1; \n"
17958 " } \n"
17959 " ); \n",
17960 "pro", 0, 0);
17961 CHECK(GetPromise("v0")->HasHandler());
17962 CHECK(!GetPromise("v1")->HasHandler());
17963 CHECK_EQ(2, promise_reject_counter);
17964 CHECK_EQ(1, promise_revoke_counter);
17965 CHECK_EQ(0, promise_reject_frame_count);
aandrey 2014/10/07 10:49:05 CHECK_EQ(-1, promise_reject_line_number);
17871 } 17966 }
17872 17967
17873 17968
17874 void AnalyzeStackOfEvalWithSourceURL( 17969 void AnalyzeStackOfEvalWithSourceURL(
17875 const v8::FunctionCallbackInfo<v8::Value>& args) { 17970 const v8::FunctionCallbackInfo<v8::Value>& args) {
17876 v8::HandleScope scope(args.GetIsolate()); 17971 v8::HandleScope scope(args.GetIsolate());
17877 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 17972 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
17878 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 17973 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
17879 CHECK_EQ(5, stackTrace->GetFrameCount()); 17974 CHECK_EQ(5, stackTrace->GetFrameCount());
17880 v8::Handle<v8::String> url = v8_str("eval_url"); 17975 v8::Handle<v8::String> url = v8_str("eval_url");
(...skipping 5819 matching lines...) Expand 10 before | Expand all | Expand 10 after
23700 " var foobXXXXX"; // Too many bytes which look like incomplete chars! 23795 " var foobXXXXX"; // Too many bytes which look like incomplete chars!
23701 char chunk2[] = 23796 char chunk2[] =
23702 "r = 13;\n" 23797 "r = 13;\n"
23703 " return foob\xeb\x91\x80\x80\x80r;\n" 23798 " return foob\xeb\x91\x80\x80\x80r;\n"
23704 "}\n"; 23799 "}\n";
23705 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; 23800 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i];
23706 23801
23707 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23802 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23708 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); 23803 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false);
23709 } 23804 }
OLDNEW
« src/isolate.cc ('K') | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698