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