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 8617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8628 v8::Handle<String> foo = v8_str("foo"); | 8628 v8::Handle<String> foo = v8_str("foo"); |
8629 v8::Handle<String> message = v8_str("message"); | 8629 v8::Handle<String> message = v8_str("message"); |
8630 v8::Handle<Value> error = v8::Exception::Error(foo); | 8630 v8::Handle<Value> error = v8::Exception::Error(foo); |
8631 CHECK(error->IsObject()); | 8631 CHECK(error->IsObject()); |
8632 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); | 8632 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); |
8633 info.GetIsolate()->ThrowException(error); | 8633 info.GetIsolate()->ThrowException(error); |
8634 info.GetReturnValue().SetUndefined(); | 8634 info.GetReturnValue().SetUndefined(); |
8635 } | 8635 } |
8636 | 8636 |
8637 | 8637 |
8638 THREADED_TEST(ExceptionGetMessage) { | 8638 THREADED_TEST(ExceptionCreateMessage) { |
8639 LocalContext context; | 8639 LocalContext context; |
8640 v8::HandleScope scope(context->GetIsolate()); | 8640 v8::HandleScope scope(context->GetIsolate()); |
8641 v8::Handle<String> foo_str = v8_str("foo"); | 8641 v8::Handle<String> foo_str = v8_str("foo"); |
8642 v8::Handle<String> message_str = v8_str("message"); | 8642 v8::Handle<String> message_str = v8_str("message"); |
8643 | 8643 |
8644 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 8644 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
8645 | 8645 |
8646 Local<v8::FunctionTemplate> fun = | 8646 Local<v8::FunctionTemplate> fun = |
8647 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); | 8647 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); |
8648 v8::Local<v8::Object> global = context->Global(); | 8648 v8::Local<v8::Object> global = context->Global(); |
8649 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); | 8649 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); |
8650 | 8650 |
8651 TryCatch try_catch; | 8651 TryCatch try_catch; |
8652 CompileRun( | 8652 CompileRun( |
8653 "function f1() {\n" | 8653 "function f1() {\n" |
8654 " throwV8Exception();\n" | 8654 " throwV8Exception();\n" |
8655 "};\n" | 8655 "};\n" |
8656 "f1();"); | 8656 "f1();"); |
8657 CHECK(try_catch.HasCaught()); | 8657 CHECK(try_catch.HasCaught()); |
8658 | 8658 |
8659 v8::Handle<v8::Value> error = try_catch.Exception(); | 8659 v8::Handle<v8::Value> error = try_catch.Exception(); |
8660 CHECK(error->IsObject()); | 8660 CHECK(error->IsObject()); |
8661 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); | 8661 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); |
8662 | 8662 |
8663 v8::Handle<v8::Message> message = v8::Exception::GetMessage(error); | 8663 v8::Handle<v8::Message> message = v8::Exception::CreateMessage(error); |
8664 CHECK(!message.IsEmpty()); | 8664 CHECK(!message.IsEmpty()); |
8665 CHECK_EQ(2, message->GetLineNumber()); | 8665 CHECK_EQ(2, message->GetLineNumber()); |
8666 CHECK_EQ(2, message->GetStartColumn()); | 8666 CHECK_EQ(2, message->GetStartColumn()); |
8667 | 8667 |
8668 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); | 8668 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); |
8669 CHECK(!stackTrace.IsEmpty()); | 8669 CHECK(!stackTrace.IsEmpty()); |
8670 CHECK_EQ(2, stackTrace->GetFrameCount()); | 8670 CHECK_EQ(2, stackTrace->GetFrameCount()); |
8671 | 8671 |
| 8672 stackTrace = v8::Exception::GetStackTrace(error); |
| 8673 CHECK(!stackTrace.IsEmpty()); |
| 8674 CHECK_EQ(2, stackTrace->GetFrameCount()); |
| 8675 |
8672 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 8676 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
8673 | 8677 |
8674 // Now check message location when SetCaptureStackTraceForUncaughtExceptions | 8678 // Now check message location when SetCaptureStackTraceForUncaughtExceptions |
8675 // is false. | 8679 // is false. |
8676 try_catch.Reset(); | 8680 try_catch.Reset(); |
8677 | 8681 |
8678 CompileRun( | 8682 CompileRun( |
8679 "function f2() {\n" | 8683 "function f2() {\n" |
8680 " return throwV8Exception();\n" | 8684 " return throwV8Exception();\n" |
8681 "};\n" | 8685 "};\n" |
8682 "f2();"); | 8686 "f2();"); |
8683 CHECK(try_catch.HasCaught()); | 8687 CHECK(try_catch.HasCaught()); |
8684 | 8688 |
8685 error = try_catch.Exception(); | 8689 error = try_catch.Exception(); |
8686 CHECK(error->IsObject()); | 8690 CHECK(error->IsObject()); |
8687 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); | 8691 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); |
8688 | 8692 |
8689 message = v8::Exception::GetMessage(error); | 8693 message = v8::Exception::CreateMessage(error); |
8690 CHECK(!message.IsEmpty()); | 8694 CHECK(!message.IsEmpty()); |
8691 CHECK_EQ(2, message->GetLineNumber()); | 8695 CHECK_EQ(2, message->GetLineNumber()); |
8692 CHECK_EQ(9, message->GetStartColumn()); | 8696 CHECK_EQ(9, message->GetStartColumn()); |
8693 | 8697 |
8694 // Should be empty stack trace. | 8698 // Should be empty stack trace. |
8695 stackTrace = message->GetStackTrace(); | 8699 stackTrace = message->GetStackTrace(); |
8696 CHECK(stackTrace.IsEmpty()); | 8700 CHECK(stackTrace.IsEmpty()); |
| 8701 CHECK(v8::Exception::GetStackTrace(error).IsEmpty()); |
8697 } | 8702 } |
8698 | 8703 |
8699 | 8704 |
8700 static void YGetter(Local<String> name, | 8705 static void YGetter(Local<String> name, |
8701 const v8::PropertyCallbackInfo<v8::Value>& info) { | 8706 const v8::PropertyCallbackInfo<v8::Value>& info) { |
8702 ApiTestFuzzer::Fuzz(); | 8707 ApiTestFuzzer::Fuzz(); |
8703 info.GetReturnValue().Set(v8_num(10)); | 8708 info.GetReturnValue().Set(v8_num(10)); |
8704 } | 8709 } |
8705 | 8710 |
8706 | 8711 |
(...skipping 9308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18015 int promise_revoke_counter = 0; | 18020 int promise_revoke_counter = 0; |
18016 int promise_reject_line_number = -1; | 18021 int promise_reject_line_number = -1; |
18017 int promise_reject_frame_count = -1; | 18022 int promise_reject_frame_count = -1; |
18018 | 18023 |
18019 void PromiseRejectCallback(v8::PromiseRejectMessage message) { | 18024 void PromiseRejectCallback(v8::PromiseRejectMessage message) { |
18020 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) { | 18025 if (message.GetEvent() == v8::kPromiseRejectWithNoHandler) { |
18021 promise_reject_counter++; | 18026 promise_reject_counter++; |
18022 CcTest::global()->Set(v8_str("rejected"), message.GetPromise()); | 18027 CcTest::global()->Set(v8_str("rejected"), message.GetPromise()); |
18023 CcTest::global()->Set(v8_str("value"), message.GetValue()); | 18028 CcTest::global()->Set(v8_str("value"), message.GetValue()); |
18024 v8::Handle<v8::StackTrace> stack_trace = | 18029 v8::Handle<v8::StackTrace> stack_trace = |
18025 v8::Exception::GetMessage(message.GetValue())->GetStackTrace(); | 18030 v8::Exception::CreateMessage(message.GetValue())->GetStackTrace(); |
18026 if (!stack_trace.IsEmpty()) { | 18031 if (!stack_trace.IsEmpty()) { |
18027 promise_reject_frame_count = stack_trace->GetFrameCount(); | 18032 promise_reject_frame_count = stack_trace->GetFrameCount(); |
18028 if (promise_reject_frame_count > 0) { | 18033 if (promise_reject_frame_count > 0) { |
18029 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); | 18034 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); |
18030 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); | 18035 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); |
18031 } else { | 18036 } else { |
18032 promise_reject_line_number = -1; | 18037 promise_reject_line_number = -1; |
18033 } | 18038 } |
18034 } | 18039 } |
18035 } else { | 18040 } else { |
(...skipping 6159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24195 char chunk2[] = | 24200 char chunk2[] = |
24196 "XX\xec\x92\x81r = 13;\n" | 24201 "XX\xec\x92\x81r = 13;\n" |
24197 " return foob\xec\x92\x81\xec\x92\x81r;\n" | 24202 " return foob\xec\x92\x81\xec\x92\x81r;\n" |
24198 "}\n"; | 24203 "}\n"; |
24199 chunk1[strlen(chunk1) - 1] = reference[0]; | 24204 chunk1[strlen(chunk1) - 1] = reference[0]; |
24200 chunk2[0] = reference[1]; | 24205 chunk2[0] = reference[1]; |
24201 chunk2[1] = reference[2]; | 24206 chunk2[1] = reference[2]; |
24202 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; | 24207 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; |
24203 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); | 24208 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); |
24204 } | 24209 } |
OLD | NEW |