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 18124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18135 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 18135 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
18136 CompileRun(source); | 18136 CompileRun(source); |
18137 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 18137 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
18138 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); | 18138 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); |
18139 } | 18139 } |
18140 | 18140 |
18141 | 18141 |
18142 v8::PromiseRejectEvent reject_event = v8::kPromiseRejectWithNoHandler; | 18142 v8::PromiseRejectEvent reject_event = v8::kPromiseRejectWithNoHandler; |
18143 int promise_reject_counter = 0; | 18143 int promise_reject_counter = 0; |
18144 int promise_revoke_counter = 0; | 18144 int promise_revoke_counter = 0; |
| 18145 int promise_reject_msg_line_number = -1; |
| 18146 int promise_reject_msg_column_number = -1; |
18145 int promise_reject_line_number = -1; | 18147 int promise_reject_line_number = -1; |
| 18148 int promise_reject_column_number = -1; |
18146 int promise_reject_frame_count = -1; | 18149 int promise_reject_frame_count = -1; |
18147 | 18150 |
18148 void PromiseRejectCallback(v8::PromiseRejectMessage message) { | 18151 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) { |
18149 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) { | 18152 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) { |
18150 promise_reject_counter++; | 18153 promise_reject_counter++; |
18151 CcTest::global()->Set(v8_str("rejected"), message.GetPromise()); | 18154 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise()); |
18152 CcTest::global()->Set(v8_str("value"), message.GetValue()); | 18155 CcTest::global()->Set(v8_str("value"), reject_message.GetValue()); |
18153 v8::Handle<v8::StackTrace> stack_trace = | 18156 v8::Handle<v8::Message> message = |
18154 v8::Exception::CreateMessage(message.GetValue())->GetStackTrace(); | 18157 v8::Exception::CreateMessage(reject_message.GetValue()); |
| 18158 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); |
| 18159 |
| 18160 promise_reject_msg_line_number = message->GetLineNumber(); |
| 18161 promise_reject_msg_column_number = message->GetStartColumn() + 1; |
| 18162 |
18155 if (!stack_trace.IsEmpty()) { | 18163 if (!stack_trace.IsEmpty()) { |
18156 promise_reject_frame_count = stack_trace->GetFrameCount(); | 18164 promise_reject_frame_count = stack_trace->GetFrameCount(); |
18157 if (promise_reject_frame_count > 0) { | 18165 if (promise_reject_frame_count > 0) { |
18158 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); | 18166 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); |
18159 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); | 18167 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); |
| 18168 promise_reject_column_number = stack_trace->GetFrame(0)->GetColumn(); |
18160 } else { | 18169 } else { |
18161 promise_reject_line_number = -1; | 18170 promise_reject_line_number = -1; |
| 18171 promise_reject_column_number = -1; |
18162 } | 18172 } |
18163 } | 18173 } |
18164 } else { | 18174 } else { |
18165 promise_revoke_counter++; | 18175 promise_revoke_counter++; |
18166 CcTest::global()->Set(v8_str("revoked"), message.GetPromise()); | 18176 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise()); |
18167 CHECK(message.GetValue().IsEmpty()); | 18177 CHECK(reject_message.GetValue().IsEmpty()); |
18168 } | 18178 } |
18169 } | 18179 } |
18170 | 18180 |
18171 | 18181 |
18172 v8::Handle<v8::Promise> GetPromise(const char* name) { | 18182 v8::Handle<v8::Promise> GetPromise(const char* name) { |
18173 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); | 18183 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); |
18174 } | 18184 } |
18175 | 18185 |
18176 | 18186 |
18177 v8::Handle<v8::Value> RejectValue() { | 18187 v8::Handle<v8::Value> RejectValue() { |
18178 return CcTest::global()->Get(v8_str("value")); | 18188 return CcTest::global()->Get(v8_str("value")); |
18179 } | 18189 } |
18180 | 18190 |
18181 | 18191 |
18182 void ResetPromiseStates() { | 18192 void ResetPromiseStates() { |
18183 promise_reject_counter = 0; | 18193 promise_reject_counter = 0; |
18184 promise_revoke_counter = 0; | 18194 promise_revoke_counter = 0; |
| 18195 promise_reject_msg_line_number = -1; |
| 18196 promise_reject_msg_column_number = -1; |
18185 promise_reject_line_number = -1; | 18197 promise_reject_line_number = -1; |
| 18198 promise_reject_column_number = -1; |
18186 promise_reject_frame_count = -1; | 18199 promise_reject_frame_count = -1; |
18187 CcTest::global()->Set(v8_str("rejected"), v8_str("")); | 18200 CcTest::global()->Set(v8_str("rejected"), v8_str("")); |
18188 CcTest::global()->Set(v8_str("value"), v8_str("")); | 18201 CcTest::global()->Set(v8_str("value"), v8_str("")); |
18189 CcTest::global()->Set(v8_str("revoked"), v8_str("")); | 18202 CcTest::global()->Set(v8_str("revoked"), v8_str("")); |
18190 } | 18203 } |
18191 | 18204 |
18192 | 18205 |
18193 TEST(PromiseRejectCallback) { | 18206 TEST(PromiseRejectCallback) { |
18194 LocalContext env; | 18207 LocalContext env; |
18195 v8::Isolate* isolate = env->GetIsolate(); | 18208 v8::Isolate* isolate = env->GetIsolate(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18404 " function(res, rej) { \n" | 18417 " function(res, rej) { \n" |
18405 " reference_error; \n" | 18418 " reference_error; \n" |
18406 " } \n" | 18419 " } \n" |
18407 "); \n", | 18420 "); \n", |
18408 "pro", 0, 0); | 18421 "pro", 0, 0); |
18409 CHECK(!GetPromise("t0")->HasHandler()); | 18422 CHECK(!GetPromise("t0")->HasHandler()); |
18410 CHECK_EQ(1, promise_reject_counter); | 18423 CHECK_EQ(1, promise_reject_counter); |
18411 CHECK_EQ(0, promise_revoke_counter); | 18424 CHECK_EQ(0, promise_revoke_counter); |
18412 CHECK_EQ(2, promise_reject_frame_count); | 18425 CHECK_EQ(2, promise_reject_frame_count); |
18413 CHECK_EQ(3, promise_reject_line_number); | 18426 CHECK_EQ(3, promise_reject_line_number); |
| 18427 CHECK_EQ(5, promise_reject_column_number); |
| 18428 CHECK_EQ(3, promise_reject_msg_line_number); |
| 18429 CHECK_EQ(5, promise_reject_msg_column_number); |
18414 | 18430 |
18415 ResetPromiseStates(); | 18431 ResetPromiseStates(); |
18416 | 18432 |
18417 // Create promise u0 and chain u1 to it, which is rejected via throw. | 18433 // Create promise u0 and chain u1 to it, which is rejected via throw. |
18418 CompileRunWithOrigin( | 18434 CompileRunWithOrigin( |
18419 "var u0 = Promise.resolve(); \n" | 18435 "var u0 = Promise.resolve(); \n" |
18420 "var u1 = u0.then( \n" | 18436 "var u1 = u0.then( \n" |
18421 " function() { \n" | 18437 " function() { \n" |
18422 " (function() { \n" | 18438 " (function() { \n" |
18423 " throw new Error(); \n" | 18439 " throw new Error(); \n" |
18424 " })(); \n" | 18440 " })(); \n" |
18425 " } \n" | 18441 " } \n" |
18426 " ); \n", | 18442 " ); \n", |
18427 "pro", 0, 0); | 18443 "pro", 0, 0); |
18428 CHECK(GetPromise("u0")->HasHandler()); | 18444 CHECK(GetPromise("u0")->HasHandler()); |
18429 CHECK(!GetPromise("u1")->HasHandler()); | 18445 CHECK(!GetPromise("u1")->HasHandler()); |
18430 CHECK_EQ(1, promise_reject_counter); | 18446 CHECK_EQ(1, promise_reject_counter); |
18431 CHECK_EQ(0, promise_revoke_counter); | 18447 CHECK_EQ(0, promise_revoke_counter); |
18432 CHECK_EQ(2, promise_reject_frame_count); | 18448 CHECK_EQ(2, promise_reject_frame_count); |
18433 CHECK_EQ(5, promise_reject_line_number); | 18449 CHECK_EQ(5, promise_reject_line_number); |
| 18450 CHECK_EQ(23, promise_reject_column_number); |
| 18451 CHECK_EQ(5, promise_reject_msg_line_number); |
| 18452 CHECK_EQ(23, promise_reject_msg_column_number); |
18434 | 18453 |
18435 // Throw in u3, which handles u1's rejection. | 18454 // Throw in u3, which handles u1's rejection. |
18436 CompileRunWithOrigin( | 18455 CompileRunWithOrigin( |
18437 "function f() { \n" | 18456 "function f() { \n" |
18438 " return (function() { \n" | 18457 " return (function() { \n" |
18439 " return new Error(); \n" | 18458 " return new Error(); \n" |
18440 " })(); \n" | 18459 " })(); \n" |
18441 "} \n" | 18460 "} \n" |
18442 "var u2 = Promise.reject(f()); \n" | 18461 "var u2 = Promise.reject(f()); \n" |
18443 "var u3 = u1.catch( \n" | 18462 "var u3 = u1.catch( \n" |
18444 " function() { \n" | 18463 " function() { \n" |
18445 " return u2; \n" | 18464 " return u2; \n" |
18446 " } \n" | 18465 " } \n" |
18447 " ); \n", | 18466 " ); \n", |
18448 "pro", 0, 0); | 18467 "pro", 0, 0); |
18449 CHECK(GetPromise("u0")->HasHandler()); | 18468 CHECK(GetPromise("u0")->HasHandler()); |
18450 CHECK(GetPromise("u1")->HasHandler()); | 18469 CHECK(GetPromise("u1")->HasHandler()); |
18451 CHECK(GetPromise("u2")->HasHandler()); | 18470 CHECK(GetPromise("u2")->HasHandler()); |
18452 CHECK(!GetPromise("u3")->HasHandler()); | 18471 CHECK(!GetPromise("u3")->HasHandler()); |
18453 CHECK_EQ(3, promise_reject_counter); | 18472 CHECK_EQ(3, promise_reject_counter); |
18454 CHECK_EQ(2, promise_revoke_counter); | 18473 CHECK_EQ(2, promise_revoke_counter); |
18455 CHECK_EQ(3, promise_reject_frame_count); | 18474 CHECK_EQ(3, promise_reject_frame_count); |
18456 CHECK_EQ(3, promise_reject_line_number); | 18475 CHECK_EQ(3, promise_reject_line_number); |
| 18476 CHECK_EQ(12, promise_reject_column_number); |
| 18477 CHECK_EQ(3, promise_reject_msg_line_number); |
| 18478 CHECK_EQ(12, promise_reject_msg_column_number); |
18457 | 18479 |
18458 ResetPromiseStates(); | 18480 ResetPromiseStates(); |
18459 | 18481 |
18460 // Create promise rejected promise v0, which is incorrectly handled by v1 | 18482 // Create promise rejected promise v0, which is incorrectly handled by v1 |
18461 // via chaining cycle. | 18483 // via chaining cycle. |
18462 CompileRunWithOrigin( | 18484 CompileRunWithOrigin( |
18463 "var v0 = Promise.reject(); \n" | 18485 "var v0 = Promise.reject(); \n" |
18464 "var v1 = v0.catch( \n" | 18486 "var v1 = v0.catch( \n" |
18465 " function() { \n" | 18487 " function() { \n" |
18466 " return v1; \n" | 18488 " return v1; \n" |
18467 " } \n" | 18489 " } \n" |
18468 " ); \n", | 18490 " ); \n", |
18469 "pro", 0, 0); | 18491 "pro", 0, 0); |
18470 CHECK(GetPromise("v0")->HasHandler()); | 18492 CHECK(GetPromise("v0")->HasHandler()); |
18471 CHECK(!GetPromise("v1")->HasHandler()); | 18493 CHECK(!GetPromise("v1")->HasHandler()); |
18472 CHECK_EQ(2, promise_reject_counter); | 18494 CHECK_EQ(2, promise_reject_counter); |
18473 CHECK_EQ(1, promise_revoke_counter); | 18495 CHECK_EQ(1, promise_revoke_counter); |
18474 CHECK_EQ(0, promise_reject_frame_count); | 18496 CHECK_EQ(0, promise_reject_frame_count); |
18475 CHECK_EQ(-1, promise_reject_line_number); | 18497 CHECK_EQ(-1, promise_reject_line_number); |
| 18498 CHECK_EQ(-1, promise_reject_column_number); |
| 18499 |
| 18500 ResetPromiseStates(); |
| 18501 |
| 18502 // Create promise t1, which rejects by throwing syntax error from eval. |
| 18503 CompileRunWithOrigin( |
| 18504 "var t1 = new Promise( \n" |
| 18505 " function(res, rej) { \n" |
| 18506 " var content = '\\n\\\n" |
| 18507 " }'; \n" |
| 18508 " eval(content); \n" |
| 18509 " } \n" |
| 18510 "); \n", |
| 18511 "pro", 0, 0); |
| 18512 CHECK(!GetPromise("t1")->HasHandler()); |
| 18513 CHECK_EQ(1, promise_reject_counter); |
| 18514 CHECK_EQ(0, promise_revoke_counter); |
| 18515 CHECK_EQ(2, promise_reject_frame_count); |
| 18516 CHECK_EQ(5, promise_reject_line_number); |
| 18517 CHECK_EQ(10, promise_reject_column_number); |
| 18518 CHECK_EQ(2, promise_reject_msg_line_number); |
| 18519 CHECK_EQ(7, promise_reject_msg_column_number); |
18476 } | 18520 } |
18477 | 18521 |
18478 | 18522 |
18479 void AnalyzeStackOfEvalWithSourceURL( | 18523 void AnalyzeStackOfEvalWithSourceURL( |
18480 const v8::FunctionCallbackInfo<v8::Value>& args) { | 18524 const v8::FunctionCallbackInfo<v8::Value>& args) { |
18481 v8::HandleScope scope(args.GetIsolate()); | 18525 v8::HandleScope scope(args.GetIsolate()); |
18482 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 18526 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
18483 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 18527 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
18484 CHECK_EQ(5, stackTrace->GetFrameCount()); | 18528 CHECK_EQ(5, stackTrace->GetFrameCount()); |
18485 v8::Handle<v8::String> url = v8_str("eval_url"); | 18529 v8::Handle<v8::String> url = v8_str("eval_url"); |
(...skipping 6294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24780 "bar2.js"); | 24824 "bar2.js"); |
24781 } | 24825 } |
24782 | 24826 |
24783 | 24827 |
24784 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { | 24828 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
24785 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 24829 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
24786 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 24830 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
24787 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 24831 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
24788 "bar2.js"); | 24832 "bar2.js"); |
24789 } | 24833 } |
OLD | NEW |