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

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

Issue 696703002: Follow up to fix v8::Exception::GetMessage() actually do what it was intended to. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 8532 matching lines...) Expand 10 before | Expand all | Expand 10 after
8543 CHECK(error->IsObject()); 8543 CHECK(error->IsObject());
8544 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 8544 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
8545 info.GetIsolate()->ThrowException(error); 8545 info.GetIsolate()->ThrowException(error);
8546 info.GetReturnValue().SetUndefined(); 8546 info.GetReturnValue().SetUndefined();
8547 } 8547 }
8548 8548
8549 8549
8550 THREADED_TEST(ExceptionGetMessage) { 8550 THREADED_TEST(ExceptionGetMessage) {
8551 LocalContext context; 8551 LocalContext context;
8552 v8::HandleScope scope(context->GetIsolate()); 8552 v8::HandleScope scope(context->GetIsolate());
8553 v8::Handle<String> foo_str = v8_str("foo");
8554 v8::Handle<String> message_str = v8_str("message");
8553 8555
8554 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 8556 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
8555 8557
8556 Local<v8::FunctionTemplate> fun = 8558 Local<v8::FunctionTemplate> fun =
8557 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); 8559 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception);
8558 v8::Local<v8::Object> global = context->Global(); 8560 v8::Local<v8::Object> global = context->Global();
8559 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); 8561 global->Set(v8_str("throwV8Exception"), fun->GetFunction());
8560 8562
8561 TryCatch try_catch; 8563 TryCatch try_catch;
8562 CompileRun( 8564 CompileRun(
8563 "function f1() {\n" 8565 "function f1() {\n"
8564 " throwV8Exception();\n" 8566 " throwV8Exception();\n"
8565 "};\n" 8567 "};\n"
8566 "f1();"); 8568 "f1();");
8567 CHECK(try_catch.HasCaught()); 8569 CHECK(try_catch.HasCaught());
8568 8570
8569 v8::Handle<v8::Value> error = try_catch.Exception(); 8571 v8::Handle<v8::Value> error = try_catch.Exception();
8570 v8::Handle<String> foo_str = v8_str("foo");
8571 v8::Handle<String> message_str = v8_str("message");
8572 CHECK(error->IsObject()); 8572 CHECK(error->IsObject());
8573 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); 8573 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str));
8574 8574
8575 v8::Handle<v8::Message> message = v8::Exception::GetMessage(error); 8575 v8::Handle<v8::Message> message = v8::Exception::GetMessage(error);
8576 CHECK(!message.IsEmpty()); 8576 CHECK(!message.IsEmpty());
8577 CHECK_EQ(2, message->GetLineNumber()); 8577 CHECK_EQ(2, message->GetLineNumber());
8578 CHECK_EQ(2, message->GetStartColumn()); 8578 CHECK_EQ(2, message->GetStartColumn());
8579 8579
8580 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); 8580 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace();
8581 CHECK(!stackTrace.IsEmpty()); 8581 CHECK(!stackTrace.IsEmpty());
8582 CHECK_EQ(2, stackTrace->GetFrameCount()); 8582 CHECK_EQ(2, stackTrace->GetFrameCount());
8583 8583
8584 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 8584 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
8585
8586 // Now check message location when SetCaptureStackTraceForUncaughtExceptions
8587 // is false.
8588 try_catch.Reset();
8589
8590 CompileRun(
8591 "function f2() {\n"
8592 " return throwV8Exception();\n"
8593 "};\n"
8594 "f2();");
8595 CHECK(try_catch.HasCaught());
8596
8597 error = try_catch.Exception();
8598 CHECK(error->IsObject());
8599 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str));
8600
8601 message = v8::Exception::GetMessage(error);
8602 CHECK(!message.IsEmpty());
8603 CHECK_EQ(2, message->GetLineNumber());
8604 CHECK_EQ(9, message->GetStartColumn());
8605
8606 // Should be empty stack trace.
8607 stackTrace = message->GetStackTrace();
8608 CHECK(stackTrace.IsEmpty());
8585 } 8609 }
8586 8610
8587 8611
8588 static void YGetter(Local<String> name, 8612 static void YGetter(Local<String> name,
8589 const v8::PropertyCallbackInfo<v8::Value>& info) { 8613 const v8::PropertyCallbackInfo<v8::Value>& info) {
8590 ApiTestFuzzer::Fuzz(); 8614 ApiTestFuzzer::Fuzz();
8591 info.GetReturnValue().Set(v8_num(10)); 8615 info.GetReturnValue().Set(v8_num(10));
8592 } 8616 }
8593 8617
8594 8618
(...skipping 15450 matching lines...) Expand 10 before | Expand all | Expand 10 after
24045 char chunk2[] = 24069 char chunk2[] =
24046 "XX\xec\x92\x81r = 13;\n" 24070 "XX\xec\x92\x81r = 13;\n"
24047 " return foob\xec\x92\x81\xec\x92\x81r;\n" 24071 " return foob\xec\x92\x81\xec\x92\x81r;\n"
24048 "}\n"; 24072 "}\n";
24049 chunk1[strlen(chunk1) - 1] = reference[0]; 24073 chunk1[strlen(chunk1) - 1] = reference[0];
24050 chunk2[0] = reference[1]; 24074 chunk2[0] = reference[1];
24051 chunk2[1] = reference[2]; 24075 chunk2[1] = reference[2];
24052 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 24076 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
24053 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 24077 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
24054 } 24078 }
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