| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 | 494 |
| 495 // --- D e b u g E v e n t H a n d l e r s | 495 // --- D e b u g E v e n t H a n d l e r s |
| 496 // --- | 496 // --- |
| 497 // --- The different tests uses a number of debug event handlers. | 497 // --- The different tests uses a number of debug event handlers. |
| 498 // --- | 498 // --- |
| 499 | 499 |
| 500 | 500 |
| 501 // Source for The JavaScript function which picks out the function name on the | 501 // Source for The JavaScript function which picks out the function name of the |
| 502 // top frame. | 502 // top frame. |
| 503 const char* frame_function_name_source = | 503 const char* frame_function_name_source = |
| 504 "function frame_function_name(exec_state) {" | 504 "function frame_function_name(exec_state) {" |
| 505 " return exec_state.frame(0).func().name();" | 505 " return exec_state.frame(0).func().name();" |
| 506 "}"; | 506 "}"; |
| 507 v8::Local<v8::Function> frame_function_name; | 507 v8::Local<v8::Function> frame_function_name; |
| 508 | 508 |
| 509 | 509 |
| 510 // Source for The JavaScript function which picks out the source line for the |
| 511 // top frame. |
| 512 const char* frame_source_line_source = |
| 513 "function frame_source_line(exec_state) {" |
| 514 " return exec_state.frame(0).sourceLine();" |
| 515 "}"; |
| 516 v8::Local<v8::Function> frame_source_line; |
| 517 |
| 518 |
| 519 // Source for The JavaScript function which picks out the source column for the |
| 520 // top frame. |
| 521 const char* frame_source_column_source = |
| 522 "function frame_source_column(exec_state) {" |
| 523 " return exec_state.frame(0).sourceColumn();" |
| 524 "}"; |
| 525 v8::Local<v8::Function> frame_source_column; |
| 526 |
| 527 |
| 510 // Source for The JavaScript function which returns the number of frames. | 528 // Source for The JavaScript function which returns the number of frames. |
| 511 static const char* frame_count_source = | 529 static const char* frame_count_source = |
| 512 "function frame_count(exec_state) {" | 530 "function frame_count(exec_state) {" |
| 513 " return exec_state.frameCount();" | 531 " return exec_state.frameCount();" |
| 514 "}"; | 532 "}"; |
| 515 v8::Handle<v8::Function> frame_count; | 533 v8::Handle<v8::Function> frame_count; |
| 516 | 534 |
| 517 | 535 |
| 518 // Global variable to store the last function hit - used by some tests. | 536 // Global variable to store the last function hit - used by some tests. |
| 519 char last_function_hit[80]; | 537 char last_function_hit[80]; |
| 520 | 538 |
| 539 // Global variables to store the last source position - used by some tests. |
| 540 int last_source_line = -1; |
| 541 int last_source_column = -1; |
| 542 |
| 521 // Debug event handler which counts the break points which have been hit. | 543 // Debug event handler which counts the break points which have been hit. |
| 522 int break_point_hit_count = 0; | 544 int break_point_hit_count = 0; |
| 523 static void DebugEventBreakPointHitCount(v8::DebugEvent event, | 545 static void DebugEventBreakPointHitCount(v8::DebugEvent event, |
| 524 v8::Handle<v8::Object> exec_state, | 546 v8::Handle<v8::Object> exec_state, |
| 525 v8::Handle<v8::Object> event_data, | 547 v8::Handle<v8::Object> event_data, |
| 526 v8::Handle<v8::Value> data) { | 548 v8::Handle<v8::Value> data) { |
| 527 // When hitting a debug event listener there must be a break set. | 549 // When hitting a debug event listener there must be a break set. |
| 528 CHECK_NE(v8::internal::Debug::break_id(), 0); | 550 CHECK_NE(v8::internal::Debug::break_id(), 0); |
| 529 | 551 |
| 530 // Count the number of breaks. | 552 // Count the number of breaks. |
| 531 if (event == v8::Break) { | 553 if (event == v8::Break) { |
| 532 break_point_hit_count++; | 554 break_point_hit_count++; |
| 533 if (!frame_function_name.IsEmpty()) { | 555 if (!frame_function_name.IsEmpty()) { |
| 534 // Get the name of the function. | 556 // Get the name of the function. |
| 535 const int argc = 1; | 557 const int argc = 1; |
| 536 v8::Handle<v8::Value> argv[argc] = { exec_state }; | 558 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
| 537 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, | 559 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, |
| 538 argc, argv); | 560 argc, argv); |
| 539 if (result->IsUndefined()) { | 561 if (result->IsUndefined()) { |
| 540 last_function_hit[0] = '\0'; | 562 last_function_hit[0] = '\0'; |
| 541 } else { | 563 } else { |
| 542 CHECK(result->IsString()); | 564 CHECK(result->IsString()); |
| 543 v8::Handle<v8::String> function_name(result->ToString()); | 565 v8::Handle<v8::String> function_name(result->ToString()); |
| 544 function_name->WriteAscii(last_function_hit); | 566 function_name->WriteAscii(last_function_hit); |
| 545 } | 567 } |
| 546 } | 568 } |
| 569 |
| 570 if (!frame_source_line.IsEmpty()) { |
| 571 // Get the source line. |
| 572 const int argc = 1; |
| 573 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
| 574 v8::Handle<v8::Value> result = frame_source_line->Call(exec_state, |
| 575 argc, argv); |
| 576 CHECK(result->IsNumber()); |
| 577 last_source_line = result->Int32Value(); |
| 578 } |
| 579 |
| 580 if (!frame_source_column.IsEmpty()) { |
| 581 // Get the source column. |
| 582 const int argc = 1; |
| 583 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
| 584 v8::Handle<v8::Value> result = frame_source_column->Call(exec_state, |
| 585 argc, argv); |
| 586 CHECK(result->IsNumber()); |
| 587 last_source_column = result->Int32Value(); |
| 588 } |
| 547 } | 589 } |
| 548 } | 590 } |
| 549 | 591 |
| 550 | 592 |
| 551 // Debug event handler which counts a number of events and collects the stack | 593 // Debug event handler which counts a number of events and collects the stack |
| 552 // height if there is a function compiled for that. | 594 // height if there is a function compiled for that. |
| 553 int exception_hit_count = 0; | 595 int exception_hit_count = 0; |
| 554 int uncaught_exception_hit_count = 0; | 596 int uncaught_exception_hit_count = 0; |
| 555 int last_js_stack_height = -1; | 597 int last_js_stack_height = -1; |
| 556 | 598 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 v8::Debug::SetDebugEventListener(NULL); | 1029 v8::Debug::SetDebugEventListener(NULL); |
| 988 CheckDebuggerUnloaded(); | 1030 CheckDebuggerUnloaded(); |
| 989 } | 1031 } |
| 990 | 1032 |
| 991 | 1033 |
| 992 // Test that a break point can be set at a return store location. | 1034 // Test that a break point can be set at a return store location. |
| 993 TEST(BreakPointReturn) { | 1035 TEST(BreakPointReturn) { |
| 994 break_point_hit_count = 0; | 1036 break_point_hit_count = 0; |
| 995 v8::HandleScope scope; | 1037 v8::HandleScope scope; |
| 996 DebugLocalContext env; | 1038 DebugLocalContext env; |
| 1039 |
| 1040 // Create a functions for checking the source line and column when hitting |
| 1041 // a break point. |
| 1042 frame_source_line = CompileFunction(&env, |
| 1043 frame_source_line_source, |
| 1044 "frame_source_line"); |
| 1045 frame_source_column = CompileFunction(&env, |
| 1046 frame_source_column_source, |
| 1047 "frame_source_column"); |
| 1048 |
| 1049 |
| 997 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1050 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 998 v8::Undefined()); | 1051 v8::Undefined()); |
| 999 v8::Script::Compile(v8::String::New("function foo(){}"))->Run(); | 1052 v8::Script::Compile(v8::String::New("function foo(){}"))->Run(); |
| 1000 v8::Local<v8::Function> foo = | 1053 v8::Local<v8::Function> foo = |
| 1001 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1054 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
| 1002 | 1055 |
| 1003 // Run without breakpoints. | 1056 // Run without breakpoints. |
| 1004 foo->Call(env->Global(), 0, NULL); | 1057 foo->Call(env->Global(), 0, NULL); |
| 1005 CHECK_EQ(0, break_point_hit_count); | 1058 CHECK_EQ(0, break_point_hit_count); |
| 1006 | 1059 |
| 1007 // Run with breakpoint | 1060 // Run with breakpoint |
| 1008 int bp = SetBreakPoint(foo, 0); | 1061 int bp = SetBreakPoint(foo, 0); |
| 1009 foo->Call(env->Global(), 0, NULL); | 1062 foo->Call(env->Global(), 0, NULL); |
| 1010 CHECK_EQ(1, break_point_hit_count); | 1063 CHECK_EQ(1, break_point_hit_count); |
| 1064 CHECK_EQ(0, last_source_line); |
| 1065 CHECK_EQ(16, last_source_column); |
| 1011 foo->Call(env->Global(), 0, NULL); | 1066 foo->Call(env->Global(), 0, NULL); |
| 1012 CHECK_EQ(2, break_point_hit_count); | 1067 CHECK_EQ(2, break_point_hit_count); |
| 1068 CHECK_EQ(0, last_source_line); |
| 1069 CHECK_EQ(16, last_source_column); |
| 1013 | 1070 |
| 1014 // Run without breakpoints. | 1071 // Run without breakpoints. |
| 1015 ClearBreakPoint(bp); | 1072 ClearBreakPoint(bp); |
| 1016 foo->Call(env->Global(), 0, NULL); | 1073 foo->Call(env->Global(), 0, NULL); |
| 1017 CHECK_EQ(2, break_point_hit_count); | 1074 CHECK_EQ(2, break_point_hit_count); |
| 1018 | 1075 |
| 1019 v8::Debug::SetDebugEventListener(NULL); | 1076 v8::Debug::SetDebugEventListener(NULL); |
| 1020 CheckDebuggerUnloaded(); | 1077 CheckDebuggerUnloaded(); |
| 1021 } | 1078 } |
| 1022 | 1079 |
| (...skipping 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3656 | 3713 |
| 3657 | 3714 |
| 3658 TEST(SendCommandToUninitializedVM) { | 3715 TEST(SendCommandToUninitializedVM) { |
| 3659 const char* dummy_command = "{}"; | 3716 const char* dummy_command = "{}"; |
| 3660 uint16_t dummy_buffer[80]; | 3717 uint16_t dummy_buffer[80]; |
| 3661 int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer); | 3718 int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer); |
| 3662 v8::Debug::SendCommand(dummy_buffer, dummy_length); | 3719 v8::Debug::SendCommand(dummy_buffer, dummy_length); |
| 3663 } | 3720 } |
| 3664 | 3721 |
| 3665 | 3722 |
| 3666 // Source for a JavaScript function which returns the source line for the top | |
| 3667 // frame. | |
| 3668 static const char* frame_source_line_source = | |
| 3669 "function frame_source_line(exec_state) {" | |
| 3670 " return exec_state.frame(0).sourceLine();" | |
| 3671 "}"; | |
| 3672 v8::Handle<v8::Function> frame_source_line; | |
| 3673 | |
| 3674 | |
| 3675 // Source for a JavaScript function which returns the data parameter of a | 3723 // Source for a JavaScript function which returns the data parameter of a |
| 3676 // function called in the context of the debugger. If no data parameter is | 3724 // function called in the context of the debugger. If no data parameter is |
| 3677 // passed it throws an exception. | 3725 // passed it throws an exception. |
| 3678 static const char* debugger_call_with_data_source = | 3726 static const char* debugger_call_with_data_source = |
| 3679 "function debugger_call_with_data(exec_state, data) {" | 3727 "function debugger_call_with_data(exec_state, data) {" |
| 3680 " if (data) return data;" | 3728 " if (data) return data;" |
| 3681 " throw 'No data!'" | 3729 " throw 'No data!'" |
| 3682 "}"; | 3730 "}"; |
| 3683 v8::Handle<v8::Function> debugger_call_with_data; | 3731 v8::Handle<v8::Function> debugger_call_with_data; |
| 3684 | 3732 |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4180 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; | 4228 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; |
| 4181 i::FLAG_allow_natives_syntax = true; | 4229 i::FLAG_allow_natives_syntax = true; |
| 4182 CompileRun( | 4230 CompileRun( |
| 4183 "var scripts = %DebugGetLoadedScripts();" | 4231 "var scripts = %DebugGetLoadedScripts();" |
| 4184 "for (var i = 0; i < scripts.length; ++i) {" | 4232 "for (var i = 0; i < scripts.length; ++i) {" |
| 4185 " scripts[i].line_ends;" | 4233 " scripts[i].line_ends;" |
| 4186 "}"); | 4234 "}"); |
| 4187 // Must not crash while accessing line_ends. | 4235 // Must not crash while accessing line_ends. |
| 4188 i::FLAG_allow_natives_syntax = allow_natives_syntax; | 4236 i::FLAG_allow_natives_syntax = allow_natives_syntax; |
| 4189 } | 4237 } |
| OLD | NEW |