OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 9566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9577 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 9577 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
9578 v8::Handle<v8::String> src = v8::String::New(source); | 9578 v8::Handle<v8::String> src = v8::String::New(source); |
9579 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); | 9579 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); |
9580 v8::Script::New(src, origin)->Run(); | 9580 v8::Script::New(src, origin)->Run(); |
9581 CHECK(try_catch.HasCaught()); | 9581 CHECK(try_catch.HasCaught()); |
9582 v8::String::Utf8Value stack(try_catch.StackTrace()); | 9582 v8::String::Utf8Value stack(try_catch.StackTrace()); |
9583 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 9583 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
9584 } | 9584 } |
9585 | 9585 |
9586 | 9586 |
| 9587 // Checks that a StackFrame has certain expected values. |
| 9588 void checkStackFrame(const char* expected_script_name, |
| 9589 const char* expected_func_name, int expected_line_number, |
| 9590 int expected_column, bool is_eval, bool is_constructor, |
| 9591 v8::Handle<v8::StackFrame> frame) { |
| 9592 v8::HandleScope scope; |
| 9593 v8::String::Utf8Value func_name(frame->GetFunctionName()); |
| 9594 v8::String::Utf8Value script_name(frame->GetScriptName()); |
| 9595 if (*script_name == NULL) { |
| 9596 // The situation where there is no associated script, like for evals. |
| 9597 CHECK(expected_script_name == NULL); |
| 9598 } else { |
| 9599 CHECK(strstr(*script_name, expected_script_name) != NULL); |
| 9600 } |
| 9601 CHECK(strstr(*func_name, expected_func_name) != NULL); |
| 9602 CHECK_EQ(expected_line_number, frame->GetLineNumber()); |
| 9603 CHECK_EQ(expected_column, frame->GetColumn()); |
| 9604 CHECK_EQ(is_eval, frame->IsEval()); |
| 9605 CHECK_EQ(is_constructor, frame->IsConstructor()); |
| 9606 } |
| 9607 |
| 9608 |
| 9609 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) { |
| 9610 v8::HandleScope scope; |
| 9611 const char* origin = "capture-stack-trace-test"; |
| 9612 const int kOverviewTest = 1; |
| 9613 const int kDetailedTest = 2; |
| 9614 |
| 9615 ASSERT(args.Length() == 1); |
| 9616 |
| 9617 int testGroup = args[0]->ToNumber()->Value(); |
| 9618 if (testGroup == kOverviewTest) { |
| 9619 v8::Handle<v8::StackTrace> stackTrace = |
| 9620 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview); |
| 9621 CHECK_EQ(4, stackTrace->GetFrameCount()); |
| 9622 checkStackFrame(origin, "bar", 2, 10, false, false, |
| 9623 stackTrace->GetFrame(0)); |
| 9624 checkStackFrame(origin, "foo", 6, 3, false, false, |
| 9625 stackTrace->GetFrame(1)); |
| 9626 checkStackFrame(NULL, "", 1, 1, false, false, |
| 9627 stackTrace->GetFrame(2)); |
| 9628 // The last frame is an anonymous function that has the initial call. |
| 9629 checkStackFrame(origin, "", 8, 7, false, false, |
| 9630 stackTrace->GetFrame(3)); |
| 9631 |
| 9632 CHECK(stackTrace->AsArray()->IsArray()); |
| 9633 } else if (testGroup == kDetailedTest) { |
| 9634 v8::Handle<v8::StackTrace> stackTrace = |
| 9635 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); |
| 9636 CHECK_EQ(4, stackTrace->GetFrameCount()); |
| 9637 checkStackFrame(origin, "bat", 2, 1, false, false, |
| 9638 stackTrace->GetFrame(0)); |
| 9639 checkStackFrame(origin, "baz", 5, 3, false, true, |
| 9640 stackTrace->GetFrame(1)); |
| 9641 checkStackFrame(NULL, "", 1, 1, true, false, |
| 9642 stackTrace->GetFrame(2)); |
| 9643 // The last frame is an anonymous function that has the initial call to foo. |
| 9644 checkStackFrame(origin, "", 7, 1, false, false, |
| 9645 stackTrace->GetFrame(3)); |
| 9646 |
| 9647 CHECK(stackTrace->AsArray()->IsArray()); |
| 9648 } |
| 9649 return v8::Undefined(); |
| 9650 } |
| 9651 |
| 9652 |
| 9653 // Tests the C++ StackTrace API. |
| 9654 THREADED_TEST(CaptureStackTrace) { |
| 9655 v8::HandleScope scope; |
| 9656 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); |
| 9657 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 9658 templ->Set(v8_str("AnalyzeStackInNativeCode"), |
| 9659 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); |
| 9660 LocalContext context(0, templ); |
| 9661 |
| 9662 // Test getting OVERVIEW information. Should ignore information that is not |
| 9663 // script name, function name, line number, and column offset. |
| 9664 const char *overview_source = |
| 9665 "function bar() {\n" |
| 9666 " var y; AnalyzeStackInNativeCode(1);\n" |
| 9667 "}\n" |
| 9668 "function foo() {\n" |
| 9669 "\n" |
| 9670 " bar();\n" |
| 9671 "}\n" |
| 9672 "var x;eval('new foo();');"; |
| 9673 v8::Handle<v8::String> overview_src = v8::String::New(overview_source); |
| 9674 v8::Handle<Value> overview_result = |
| 9675 v8::Script::New(overview_src, origin)->Run(); |
| 9676 ASSERT(!overview_result.IsEmpty()); |
| 9677 ASSERT(overview_result->IsObject()); |
| 9678 |
| 9679 // Test getting DETAILED information. |
| 9680 const char *detailed_source = |
| 9681 "function bat() {\n" |
| 9682 "AnalyzeStackInNativeCode(2);\n" |
| 9683 "}\n" |
| 9684 "function baz() {\n" |
| 9685 " bat();\n" |
| 9686 "}\n" |
| 9687 "eval('new baz();');"; |
| 9688 v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source); |
| 9689 v8::Handle<Value> detailed_result = |
| 9690 v8::Script::New(detailed_src, origin)->Run(); |
| 9691 ASSERT(!detailed_result.IsEmpty()); |
| 9692 ASSERT(detailed_result->IsObject()); |
| 9693 } |
| 9694 |
| 9695 |
9587 // Test that idle notification can be handled and eventually returns true. | 9696 // Test that idle notification can be handled and eventually returns true. |
9588 THREADED_TEST(IdleNotification) { | 9697 THREADED_TEST(IdleNotification) { |
9589 bool rv = false; | 9698 bool rv = false; |
9590 for (int i = 0; i < 100; i++) { | 9699 for (int i = 0; i < 100; i++) { |
9591 rv = v8::V8::IdleNotification(); | 9700 rv = v8::V8::IdleNotification(); |
9592 if (rv) | 9701 if (rv) |
9593 break; | 9702 break; |
9594 } | 9703 } |
9595 CHECK(rv == true); | 9704 CHECK(rv == true); |
9596 } | 9705 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10148 CHECK_EQ(2, prologue_call_count_second); | 10257 CHECK_EQ(2, prologue_call_count_second); |
10149 CHECK_EQ(2, epilogue_call_count_second); | 10258 CHECK_EQ(2, epilogue_call_count_second); |
10150 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); | 10259 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); |
10151 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); | 10260 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); |
10152 i::Heap::CollectAllGarbage(false); | 10261 i::Heap::CollectAllGarbage(false); |
10153 CHECK_EQ(2, prologue_call_count); | 10262 CHECK_EQ(2, prologue_call_count); |
10154 CHECK_EQ(2, epilogue_call_count); | 10263 CHECK_EQ(2, epilogue_call_count); |
10155 CHECK_EQ(2, prologue_call_count_second); | 10264 CHECK_EQ(2, prologue_call_count_second); |
10156 CHECK_EQ(2, epilogue_call_count_second); | 10265 CHECK_EQ(2, epilogue_call_count_second); |
10157 } | 10266 } |
OLD | NEW |