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

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

Issue 687253002: Introduce v8::Exception::GetMessage to find location of an error object. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: relanding 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
« no previous file with comments | « 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 8529 matching lines...) Expand 10 before | Expand all | Expand 10 after
8540 v8::Handle<String> foo = v8_str("foo"); 8540 v8::Handle<String> foo = v8_str("foo");
8541 v8::Handle<String> message = v8_str("message"); 8541 v8::Handle<String> message = v8_str("message");
8542 v8::Handle<Value> error = v8::Exception::Error(foo); 8542 v8::Handle<Value> error = v8::Exception::Error(foo);
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(ExceptionGetStackTrace) { 8550 THREADED_TEST(ExceptionGetMessage) {
8551 LocalContext context; 8551 LocalContext context;
8552 v8::HandleScope scope(context->GetIsolate()); 8552 v8::HandleScope scope(context->GetIsolate());
8553 8553
8554 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 8554 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
8555 8555
8556 Local<v8::FunctionTemplate> fun = 8556 Local<v8::FunctionTemplate> fun =
8557 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); 8557 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception);
8558 v8::Local<v8::Object> global = context->Global(); 8558 v8::Local<v8::Object> global = context->Global();
8559 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); 8559 global->Set(v8_str("throwV8Exception"), fun->GetFunction());
8560 8560
8561 TryCatch try_catch; 8561 TryCatch try_catch;
8562 CompileRun("function f1() { throwV8Exception(); }; f1();"); 8562 CompileRun(
8563 "function f1() {\n"
8564 " throwV8Exception();\n"
8565 "};\n"
8566 "f1();");
8563 CHECK(try_catch.HasCaught()); 8567 CHECK(try_catch.HasCaught());
8564 8568
8565 v8::Handle<v8::Value> error = try_catch.Exception(); 8569 v8::Handle<v8::Value> error = try_catch.Exception();
8566 v8::Handle<String> foo = v8_str("foo"); 8570 v8::Handle<String> foo_str = v8_str("foo");
8567 v8::Handle<String> message = v8_str("message"); 8571 v8::Handle<String> message_str = v8_str("message");
8568 CHECK(error->IsObject()); 8572 CHECK(error->IsObject());
8569 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 8573 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str));
8570 8574
8571 v8::Handle<v8::StackTrace> stackTrace = v8::Exception::GetStackTrace(error); 8575 v8::Handle<v8::Message> message = v8::Exception::GetMessage(error);
8576 CHECK(!message.IsEmpty());
8577 CHECK_EQ(2, message->GetLineNumber());
8578 CHECK_EQ(2, message->GetStartColumn());
8579
8580 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace();
8572 CHECK(!stackTrace.IsEmpty()); 8581 CHECK(!stackTrace.IsEmpty());
8573 CHECK_EQ(2, stackTrace->GetFrameCount()); 8582 CHECK_EQ(2, stackTrace->GetFrameCount());
8574 8583
8575 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 8584 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
8576 } 8585 }
8577 8586
8578 8587
8579 static void YGetter(Local<String> name, 8588 static void YGetter(Local<String> name,
8580 const v8::PropertyCallbackInfo<v8::Value>& info) { 8589 const v8::PropertyCallbackInfo<v8::Value>& info) {
8581 ApiTestFuzzer::Fuzz(); 8590 ApiTestFuzzer::Fuzz();
(...skipping 9284 matching lines...) Expand 10 before | Expand all | Expand 10 after
17866 int promise_reject_counter = 0; 17875 int promise_reject_counter = 0;
17867 int promise_revoke_counter = 0; 17876 int promise_revoke_counter = 0;
17868 int promise_reject_line_number = -1; 17877 int promise_reject_line_number = -1;
17869 int promise_reject_frame_count = -1; 17878 int promise_reject_frame_count = -1;
17870 17879
17871 void PromiseRejectCallback(v8::PromiseRejectMessage message) { 17880 void PromiseRejectCallback(v8::PromiseRejectMessage message) {
17872 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) { 17881 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) {
17873 promise_reject_counter++; 17882 promise_reject_counter++;
17874 CcTest::global()->Set(v8_str("rejected"), message.GetPromise()); 17883 CcTest::global()->Set(v8_str("rejected"), message.GetPromise());
17875 CcTest::global()->Set(v8_str("value"), message.GetValue()); 17884 CcTest::global()->Set(v8_str("value"), message.GetValue());
17876 v8::Handle<v8::StackTrace> stack_trace = message.GetStackTrace(); 17885 v8::Handle<v8::StackTrace> stack_trace =
17886 v8::Exception::GetMessage(message.GetValue())->GetStackTrace();
17877 if (!stack_trace.IsEmpty()) { 17887 if (!stack_trace.IsEmpty()) {
17878 promise_reject_frame_count = stack_trace->GetFrameCount(); 17888 promise_reject_frame_count = stack_trace->GetFrameCount();
17879 if (promise_reject_frame_count > 0) { 17889 if (promise_reject_frame_count > 0) {
17880 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); 17890 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro")));
17881 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); 17891 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber();
17882 } else { 17892 } else {
17883 promise_reject_line_number = -1; 17893 promise_reject_line_number = -1;
17884 } 17894 }
17885 } 17895 }
17886 } else { 17896 } else {
17887 promise_revoke_counter++; 17897 promise_revoke_counter++;
17888 CcTest::global()->Set(v8_str("revoked"), message.GetPromise()); 17898 CcTest::global()->Set(v8_str("revoked"), message.GetPromise());
17889 CHECK(message.GetValue().IsEmpty()); 17899 CHECK(message.GetValue().IsEmpty());
17890 CHECK(message.GetStackTrace().IsEmpty());
17891 } 17900 }
17892 } 17901 }
17893 17902
17894 17903
17895 v8::Handle<v8::Promise> GetPromise(const char* name) { 17904 v8::Handle<v8::Promise> GetPromise(const char* name) {
17896 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); 17905 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name)));
17897 } 17906 }
17898 17907
17899 17908
17900 v8::Handle<v8::Value> RejectValue() { 17909 v8::Handle<v8::Value> RejectValue() {
(...skipping 6135 matching lines...) Expand 10 before | Expand all | Expand 10 after
24036 char chunk2[] = 24045 char chunk2[] =
24037 "XX\xec\x92\x81r = 13;\n" 24046 "XX\xec\x92\x81r = 13;\n"
24038 " return foob\xec\x92\x81\xec\x92\x81r;\n" 24047 " return foob\xec\x92\x81\xec\x92\x81r;\n"
24039 "}\n"; 24048 "}\n";
24040 chunk1[strlen(chunk1) - 1] = reference[0]; 24049 chunk1[strlen(chunk1) - 1] = reference[0];
24041 chunk2[0] = reference[1]; 24050 chunk2[0] = reference[1];
24042 chunk2[1] = reference[2]; 24051 chunk2[1] = reference[2];
24043 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 24052 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
24044 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 24053 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
24045 } 24054 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698