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

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

Issue 885043002: [V8] Added line, column and script symbols for SyntaxError (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/parser.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 18124 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
18146 int promise_reject_frame_count = -1; 18148 int promise_reject_frame_count = -1;
18147 18149
18148 void PromiseRejectCallback(v8::PromiseRejectMessage message) { 18150 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) {
18149 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) { 18151 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) {
18150 promise_reject_counter++; 18152 promise_reject_counter++;
18151 CcTest::global()->Set(v8_str("rejected"), message.GetPromise()); 18153 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise());
18152 CcTest::global()->Set(v8_str("value"), message.GetValue()); 18154 CcTest::global()->Set(v8_str("value"), reject_message.GetValue());
18153 v8::Handle<v8::StackTrace> stack_trace = 18155 v8::Handle<v8::Message> message =
18154 v8::Exception::CreateMessage(message.GetValue())->GetStackTrace(); 18156 v8::Exception::CreateMessage(reject_message.GetValue());
18157 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
18158
18159 promise_reject_msg_line_number = message->GetLineNumber();
18160 promise_reject_msg_column_number = message->GetStartColumn() + 1;
18161
18155 if (!stack_trace.IsEmpty()) { 18162 if (!stack_trace.IsEmpty()) {
18156 promise_reject_frame_count = stack_trace->GetFrameCount(); 18163 promise_reject_frame_count = stack_trace->GetFrameCount();
18157 if (promise_reject_frame_count > 0) { 18164 if (promise_reject_frame_count > 0) {
18158 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); 18165 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro")));
18159 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); 18166 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber();
yurys 2015/02/02 09:38:31 Consider adding promise_reject_line_number here an
kozy 2015/02/02 10:09:33 Done.
18160 } else { 18167 } else {
18161 promise_reject_line_number = -1; 18168 promise_reject_line_number = -1;
18162 } 18169 }
18163 } 18170 }
18164 } else { 18171 } else {
18165 promise_revoke_counter++; 18172 promise_revoke_counter++;
18166 CcTest::global()->Set(v8_str("revoked"), message.GetPromise()); 18173 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise());
18167 CHECK(message.GetValue().IsEmpty()); 18174 CHECK(reject_message.GetValue().IsEmpty());
18168 } 18175 }
18169 } 18176 }
18170 18177
18171 18178
18172 v8::Handle<v8::Promise> GetPromise(const char* name) { 18179 v8::Handle<v8::Promise> GetPromise(const char* name) {
18173 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); 18180 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name)));
18174 } 18181 }
18175 18182
18176 18183
18177 v8::Handle<v8::Value> RejectValue() { 18184 v8::Handle<v8::Value> RejectValue() {
18178 return CcTest::global()->Get(v8_str("value")); 18185 return CcTest::global()->Get(v8_str("value"));
18179 } 18186 }
18180 18187
18181 18188
18182 void ResetPromiseStates() { 18189 void ResetPromiseStates() {
18183 promise_reject_counter = 0; 18190 promise_reject_counter = 0;
18184 promise_revoke_counter = 0; 18191 promise_revoke_counter = 0;
18192 promise_reject_msg_line_number = -1;
18193 promise_reject_msg_column_number = -1;
18185 promise_reject_line_number = -1; 18194 promise_reject_line_number = -1;
18186 promise_reject_frame_count = -1; 18195 promise_reject_frame_count = -1;
18187 CcTest::global()->Set(v8_str("rejected"), v8_str("")); 18196 CcTest::global()->Set(v8_str("rejected"), v8_str(""));
18188 CcTest::global()->Set(v8_str("value"), v8_str("")); 18197 CcTest::global()->Set(v8_str("value"), v8_str(""));
18189 CcTest::global()->Set(v8_str("revoked"), v8_str("")); 18198 CcTest::global()->Set(v8_str("revoked"), v8_str(""));
18190 } 18199 }
18191 18200
18192 18201
18193 TEST(PromiseRejectCallback) { 18202 TEST(PromiseRejectCallback) {
18194 LocalContext env; 18203 LocalContext env;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
18404 " function(res, rej) { \n" 18413 " function(res, rej) { \n"
18405 " reference_error; \n" 18414 " reference_error; \n"
18406 " } \n" 18415 " } \n"
18407 "); \n", 18416 "); \n",
18408 "pro", 0, 0); 18417 "pro", 0, 0);
18409 CHECK(!GetPromise("t0")->HasHandler()); 18418 CHECK(!GetPromise("t0")->HasHandler());
18410 CHECK_EQ(1, promise_reject_counter); 18419 CHECK_EQ(1, promise_reject_counter);
18411 CHECK_EQ(0, promise_revoke_counter); 18420 CHECK_EQ(0, promise_revoke_counter);
18412 CHECK_EQ(2, promise_reject_frame_count); 18421 CHECK_EQ(2, promise_reject_frame_count);
18413 CHECK_EQ(3, promise_reject_line_number); 18422 CHECK_EQ(3, promise_reject_line_number);
18423 CHECK_EQ(3, promise_reject_msg_line_number);
18424 CHECK_EQ(5, promise_reject_msg_column_number);
18414 18425
18415 ResetPromiseStates(); 18426 ResetPromiseStates();
18416 18427
18417 // Create promise u0 and chain u1 to it, which is rejected via throw. 18428 // Create promise u0 and chain u1 to it, which is rejected via throw.
18418 CompileRunWithOrigin( 18429 CompileRunWithOrigin(
18419 "var u0 = Promise.resolve(); \n" 18430 "var u0 = Promise.resolve(); \n"
18420 "var u1 = u0.then( \n" 18431 "var u1 = u0.then( \n"
18421 " function() { \n" 18432 " function() { \n"
18422 " (function() { \n" 18433 " (function() { \n"
18423 " throw new Error(); \n" 18434 " throw new Error(); \n"
18424 " })(); \n" 18435 " })(); \n"
18425 " } \n" 18436 " } \n"
18426 " ); \n", 18437 " ); \n",
18427 "pro", 0, 0); 18438 "pro", 0, 0);
18428 CHECK(GetPromise("u0")->HasHandler()); 18439 CHECK(GetPromise("u0")->HasHandler());
18429 CHECK(!GetPromise("u1")->HasHandler()); 18440 CHECK(!GetPromise("u1")->HasHandler());
18430 CHECK_EQ(1, promise_reject_counter); 18441 CHECK_EQ(1, promise_reject_counter);
18431 CHECK_EQ(0, promise_revoke_counter); 18442 CHECK_EQ(0, promise_revoke_counter);
18432 CHECK_EQ(2, promise_reject_frame_count); 18443 CHECK_EQ(2, promise_reject_frame_count);
18433 CHECK_EQ(5, promise_reject_line_number); 18444 CHECK_EQ(5, promise_reject_line_number);
18445 CHECK_EQ(5, promise_reject_msg_line_number);
18446 CHECK_EQ(23, promise_reject_msg_column_number);
18434 18447
18435 // Throw in u3, which handles u1's rejection. 18448 // Throw in u3, which handles u1's rejection.
18436 CompileRunWithOrigin( 18449 CompileRunWithOrigin(
18437 "function f() { \n" 18450 "function f() { \n"
18438 " return (function() { \n" 18451 " return (function() { \n"
18439 " return new Error(); \n" 18452 " return new Error(); \n"
18440 " })(); \n" 18453 " })(); \n"
18441 "} \n" 18454 "} \n"
18442 "var u2 = Promise.reject(f()); \n" 18455 "var u2 = Promise.reject(f()); \n"
18443 "var u3 = u1.catch( \n" 18456 "var u3 = u1.catch( \n"
18444 " function() { \n" 18457 " function() { \n"
18445 " return u2; \n" 18458 " return u2; \n"
18446 " } \n" 18459 " } \n"
18447 " ); \n", 18460 " ); \n",
18448 "pro", 0, 0); 18461 "pro", 0, 0);
18449 CHECK(GetPromise("u0")->HasHandler()); 18462 CHECK(GetPromise("u0")->HasHandler());
18450 CHECK(GetPromise("u1")->HasHandler()); 18463 CHECK(GetPromise("u1")->HasHandler());
18451 CHECK(GetPromise("u2")->HasHandler()); 18464 CHECK(GetPromise("u2")->HasHandler());
18452 CHECK(!GetPromise("u3")->HasHandler()); 18465 CHECK(!GetPromise("u3")->HasHandler());
18453 CHECK_EQ(3, promise_reject_counter); 18466 CHECK_EQ(3, promise_reject_counter);
18454 CHECK_EQ(2, promise_revoke_counter); 18467 CHECK_EQ(2, promise_revoke_counter);
18455 CHECK_EQ(3, promise_reject_frame_count); 18468 CHECK_EQ(3, promise_reject_frame_count);
18456 CHECK_EQ(3, promise_reject_line_number); 18469 CHECK_EQ(3, promise_reject_line_number);
18470 CHECK_EQ(3, promise_reject_msg_line_number);
18471 CHECK_EQ(12, promise_reject_msg_column_number);
18457 18472
18458 ResetPromiseStates(); 18473 ResetPromiseStates();
18459 18474
18460 // Create promise rejected promise v0, which is incorrectly handled by v1 18475 // Create promise rejected promise v0, which is incorrectly handled by v1
18461 // via chaining cycle. 18476 // via chaining cycle.
18462 CompileRunWithOrigin( 18477 CompileRunWithOrigin(
18463 "var v0 = Promise.reject(); \n" 18478 "var v0 = Promise.reject(); \n"
18464 "var v1 = v0.catch( \n" 18479 "var v1 = v0.catch( \n"
18465 " function() { \n" 18480 " function() { \n"
18466 " return v1; \n" 18481 " return v1; \n"
18467 " } \n" 18482 " } \n"
18468 " ); \n", 18483 " ); \n",
18469 "pro", 0, 0); 18484 "pro", 0, 0);
18470 CHECK(GetPromise("v0")->HasHandler()); 18485 CHECK(GetPromise("v0")->HasHandler());
18471 CHECK(!GetPromise("v1")->HasHandler()); 18486 CHECK(!GetPromise("v1")->HasHandler());
18472 CHECK_EQ(2, promise_reject_counter); 18487 CHECK_EQ(2, promise_reject_counter);
18473 CHECK_EQ(1, promise_revoke_counter); 18488 CHECK_EQ(1, promise_revoke_counter);
18474 CHECK_EQ(0, promise_reject_frame_count); 18489 CHECK_EQ(0, promise_reject_frame_count);
18475 CHECK_EQ(-1, promise_reject_line_number); 18490 CHECK_EQ(-1, promise_reject_line_number);
18491
18492 ResetPromiseStates();
18493
18494 // Create promise t1, which rejects by throwing syntax error from eval.
18495 CompileRunWithOrigin(
18496 "var t1 = new Promise( \n"
18497 " function(res, rej) { \n"
18498 " var content = '\\n\\\n"
18499 " }'; \n"
18500 " eval(content); \n"
18501 " } \n"
18502 "); \n",
18503 "pro", 0, 0);
18504 CHECK(!GetPromise("t1")->HasHandler());
18505 CHECK_EQ(1, promise_reject_counter);
18506 CHECK_EQ(0, promise_revoke_counter);
18507 CHECK_EQ(2, promise_reject_frame_count);
18508 CHECK_EQ(5, promise_reject_line_number);
18509 CHECK_EQ(2, promise_reject_msg_line_number);
18510 CHECK_EQ(7, promise_reject_msg_column_number);
18476 } 18511 }
18477 18512
18478 18513
18479 void AnalyzeStackOfEvalWithSourceURL( 18514 void AnalyzeStackOfEvalWithSourceURL(
18480 const v8::FunctionCallbackInfo<v8::Value>& args) { 18515 const v8::FunctionCallbackInfo<v8::Value>& args) {
18481 v8::HandleScope scope(args.GetIsolate()); 18516 v8::HandleScope scope(args.GetIsolate());
18482 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 18517 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
18483 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 18518 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
18484 CHECK_EQ(5, stackTrace->GetFrameCount()); 18519 CHECK_EQ(5, stackTrace->GetFrameCount());
18485 v8::Handle<v8::String> url = v8_str("eval_url"); 18520 v8::Handle<v8::String> url = v8_str("eval_url");
(...skipping 6294 matching lines...) Expand 10 before | Expand all | Expand 10 after
24780 "bar2.js"); 24815 "bar2.js");
24781 } 24816 }
24782 24817
24783 24818
24784 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { 24819 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
24785 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", 24820 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
24786 " sourceMappingURL=bar2.js\n", "foo();", NULL}; 24821 " sourceMappingURL=bar2.js\n", "foo();", NULL};
24787 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, 24822 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
24788 "bar2.js"); 24823 "bar2.js");
24789 } 24824 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698