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

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

Issue 607913002: Report promise reject with no handler (behind a flag). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more comments 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
« no previous file with comments | « src/runtime/runtime.cc ('k') | test/cctest/test-debug.cc » ('j') | 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 17548 matching lines...) Expand 10 before | Expand all | Expand 10 after
17559 "var e = {__proto__: new Error()} \n" 17559 "var e = {__proto__: new Error()} \n"
17560 "throw e; \n"; 17560 "throw e; \n";
17561 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler); 17561 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler);
17562 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 17562 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
17563 CompileRun(source); 17563 CompileRun(source);
17564 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 17564 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
17565 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 17565 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
17566 } 17566 }
17567 17567
17568 17568
17569 static int promise_message_counter = 0;
17570
17571
17572 static void CheckPromiseInMessage(v8::Handle<v8::Message> message,
17573 v8::Handle<v8::Value> data) {
17574 CHECK(!message->GetPromise().IsEmpty());
17575 v8::ScriptOrigin origin = message->GetScriptOrigin();
17576 promise_message_counter++;
17577 if (promise_message_counter == 1) {
17578 v8::Handle<v8::Value> expected = CcTest::global()->Get(v8_str("p"));
17579 CHECK(expected->Equals(message->GetPromise()));
17580 CHECK(data->Equals(v8_str("p1")));
17581 // The message location should point to the call site of reject.
17582 CHECK(origin.ResourceName()->Equals(v8_str("test1")));
17583 CHECK_EQ(6, message->GetLineNumber());
17584 } else if (promise_message_counter == 2) {
17585 v8::Handle<v8::Value> expected = CcTest::global()->Get(v8_str("q"));
17586 CHECK(expected->Equals(message->GetPromise()));
17587 CHECK(data->Equals(v8_str("q2")));
17588 // There is no valid location when a promise is rejected by returning a
17589 // rejected promise, since the actual rejection happens in internal code.
17590 CHECK(origin.ResourceName()->IsUndefined());
17591 CHECK_EQ(0, message->GetLineNumber());
17592 } else {
17593 CHECK_EQ(3, promise_message_counter);
17594 v8::Handle<v8::Value> expected = CcTest::global()->Get(v8_str("r"));
17595 CHECK(expected->Equals(message->GetPromise()));
17596 CHECK(data->Equals(v8_str("r3")));
17597 // The message location should point to the throw site.
17598 CHECK(origin.ResourceName()->Equals(v8_str("test3")));
17599 CHECK_EQ(3, message->GetLineNumber());
17600 }
17601 }
17602
17603
17604 TEST(PromiseMessage) {
17605 i::FLAG_report_promise_reject = true;
17606 LocalContext env;
17607 v8::Isolate* isolate = env->GetIsolate();
17608 v8::HandleScope scope(isolate);
17609
17610 v8::V8::AddMessageListener(CheckPromiseInMessage);
17611 promise_message_counter = 0;
17612 v8::Handle<v8::Promise> promise;
17613
17614 // Create promise o.
17615 CompileRun(
17616 "var reject; \n"
17617 "var o = new Promise( \n"
17618 " function(res, rej) { \n"
17619 " reject = rej; \n"
17620 " } \n"
17621 "); \n");
17622 promise = v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str("o")));
17623 CHECK(!promise->HasRejectHandler());
17624 CHECK_EQ(0, promise_message_counter);
17625
17626 // Add reject handler to o.
17627 CompileRun("o.catch(function() {});");
17628 CHECK(promise->HasRejectHandler());
17629 CHECK_EQ(0, promise_message_counter);
17630
17631 // Reject o. We expect no message.
17632 CompileRun("reject('o0')");
17633 CHECK(promise->HasRejectHandler());
17634 CHECK_EQ(0, promise_message_counter);
17635
17636 // Create Promise p, which is rejected by calling reject.
17637 CompileRun(
17638 "var p = new Promise( \n"
17639 " function(res, rej) { \n"
17640 " reject = rej; \n"
17641 " } \n"
17642 "); \n"
17643 "reject('p1'); \n //@ sourceURL=test1");
17644 CHECK_EQ(1, promise_message_counter);
17645 // Fetch promise from container. It doesn't have a reject handler.
17646 promise = v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str("p")));
17647 CHECK(!promise->HasRejectHandler());
17648
17649 // Handle the rejection. Promise p should now have a reject handler.
17650 // q is rejected by returning Promise.reject().
17651 CompileRun(
17652 "var q = p.catch( \n"
17653 " function() { \n"
17654 " return Promise.reject('q2'); \n"
17655 " } \n"
17656 "); \n //@ sourceURL=test2");
17657 CHECK_EQ(2, promise_message_counter);
17658 CHECK(promise->HasRejectHandler());
17659 // Fetch promise from container. It doesn't have a reject handler.
17660 promise = v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str("q")));
17661
17662 // Handle the rejection. Promise q should now have a reject handler.
17663 // r is rejected by throwing.
17664 CompileRun(
17665 "var r = p.catch( \n"
17666 " function() { \n"
17667 " throw 'r3'; \n"
17668 " } \n"
17669 "); \n //@ sourceURL=test3");
17670 CHECK_EQ(3, promise_message_counter);
17671 promise = v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str("r")));
17672 }
17673
17674
17569 void AnalyzeStackOfEvalWithSourceURL( 17675 void AnalyzeStackOfEvalWithSourceURL(
17570 const v8::FunctionCallbackInfo<v8::Value>& args) { 17676 const v8::FunctionCallbackInfo<v8::Value>& args) {
17571 v8::HandleScope scope(args.GetIsolate()); 17677 v8::HandleScope scope(args.GetIsolate());
17572 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 17678 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
17573 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 17679 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
17574 CHECK_EQ(5, stackTrace->GetFrameCount()); 17680 CHECK_EQ(5, stackTrace->GetFrameCount());
17575 v8::Handle<v8::String> url = v8_str("eval_url"); 17681 v8::Handle<v8::String> url = v8_str("eval_url");
17576 for (int i = 0; i < 3; i++) { 17682 for (int i = 0; i < 3; i++) {
17577 v8::Handle<v8::String> name = 17683 v8::Handle<v8::String> name =
17578 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17684 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
(...skipping 5815 matching lines...) Expand 10 before | Expand all | Expand 10 after
23394 " var foobXXXXX"; // Too many bytes which look like incomplete chars! 23500 " var foobXXXXX"; // Too many bytes which look like incomplete chars!
23395 char chunk2[] = 23501 char chunk2[] =
23396 "r = 13;\n" 23502 "r = 13;\n"
23397 " return foob\xeb\x91\x80\x80\x80r;\n" 23503 " return foob\xeb\x91\x80\x80\x80r;\n"
23398 "}\n"; 23504 "}\n";
23399 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; 23505 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i];
23400 23506
23401 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23507 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23402 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); 23508 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false);
23403 } 23509 }
OLDNEW
« no previous file with comments | « src/runtime/runtime.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698