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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 574 |
575 // Source for the JavaScript function which picks out the script name for the | 575 // Source for the JavaScript function which picks out the script name for the |
576 // top frame. | 576 // top frame. |
577 const char* frame_script_name_source = | 577 const char* frame_script_name_source = |
578 "function frame_script_name(exec_state) {" | 578 "function frame_script_name(exec_state) {" |
579 " return exec_state.frame(0).func().script().name();" | 579 " return exec_state.frame(0).func().script().name();" |
580 "}"; | 580 "}"; |
581 v8::Local<v8::Function> frame_script_name; | 581 v8::Local<v8::Function> frame_script_name; |
582 | 582 |
583 | 583 |
584 // Source for the JavaScript function which picks out the script data for the | |
585 // top frame. | |
586 const char* frame_script_data_source = | |
587 "function frame_script_data(exec_state) {" | |
588 " return exec_state.frame(0).func().script().data();" | |
589 "}"; | |
590 v8::Local<v8::Function> frame_script_data; | |
591 | |
592 | |
593 // Source for the JavaScript function which picks out the script data from | |
594 // AfterCompile event | |
595 const char* compiled_script_data_source = | |
596 "function compiled_script_data(event_data) {" | |
597 " return event_data.script().data();" | |
598 "}"; | |
599 v8::Local<v8::Function> compiled_script_data; | |
600 | |
601 | |
602 // Source for the JavaScript function which returns the number of frames. | 584 // Source for the JavaScript function which returns the number of frames. |
603 static const char* frame_count_source = | 585 static const char* frame_count_source = |
604 "function frame_count(exec_state) {" | 586 "function frame_count(exec_state) {" |
605 " return exec_state.frameCount();" | 587 " return exec_state.frameCount();" |
606 "}"; | 588 "}"; |
607 v8::Handle<v8::Function> frame_count; | 589 v8::Handle<v8::Function> frame_count; |
608 | 590 |
609 | 591 |
610 // Global variable to store the last function hit - used by some tests. | 592 // Global variable to store the last function hit - used by some tests. |
611 char last_function_hit[80]; | 593 char last_function_hit[80]; |
612 | 594 |
613 // Global variable to store the name and data for last script hit - used by some | 595 // Global variable to store the name for last script hit - used by some tests. |
614 // tests. | |
615 char last_script_name_hit[80]; | 596 char last_script_name_hit[80]; |
616 char last_script_data_hit[80]; | |
617 | 597 |
618 // Global variables to store the last source position - used by some tests. | 598 // Global variables to store the last source position - used by some tests. |
619 int last_source_line = -1; | 599 int last_source_line = -1; |
620 int last_source_column = -1; | 600 int last_source_column = -1; |
621 | 601 |
622 // Debug event handler which counts the break points which have been hit. | 602 // Debug event handler which counts the break points which have been hit. |
623 int break_point_hit_count = 0; | 603 int break_point_hit_count = 0; |
624 int break_point_hit_count_deoptimize = 0; | 604 int break_point_hit_count_deoptimize = 0; |
625 static void DebugEventBreakPointHitCount( | 605 static void DebugEventBreakPointHitCount( |
626 const v8::Debug::EventDetails& event_details) { | 606 const v8::Debug::EventDetails& event_details) { |
627 v8::DebugEvent event = event_details.GetEvent(); | 607 v8::DebugEvent event = event_details.GetEvent(); |
628 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); | 608 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
629 v8::Handle<v8::Object> event_data = event_details.GetEventData(); | |
630 v8::internal::Isolate* isolate = CcTest::i_isolate(); | 609 v8::internal::Isolate* isolate = CcTest::i_isolate(); |
631 Debug* debug = isolate->debug(); | 610 Debug* debug = isolate->debug(); |
632 // When hitting a debug event listener there must be a break set. | 611 // When hitting a debug event listener there must be a break set. |
633 CHECK_NE(debug->break_id(), 0); | 612 CHECK_NE(debug->break_id(), 0); |
634 | 613 |
635 // Count the number of breaks. | 614 // Count the number of breaks. |
636 if (event == v8::Break) { | 615 if (event == v8::Break) { |
637 break_point_hit_count++; | 616 break_point_hit_count++; |
638 if (!frame_function_name.IsEmpty()) { | 617 if (!frame_function_name.IsEmpty()) { |
639 // Get the name of the function. | 618 // Get the name of the function. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 argc, argv); | 659 argc, argv); |
681 if (result->IsUndefined()) { | 660 if (result->IsUndefined()) { |
682 last_script_name_hit[0] = '\0'; | 661 last_script_name_hit[0] = '\0'; |
683 } else { | 662 } else { |
684 CHECK(result->IsString()); | 663 CHECK(result->IsString()); |
685 v8::Handle<v8::String> script_name(result->ToString()); | 664 v8::Handle<v8::String> script_name(result->ToString()); |
686 script_name->WriteUtf8(last_script_name_hit); | 665 script_name->WriteUtf8(last_script_name_hit); |
687 } | 666 } |
688 } | 667 } |
689 | 668 |
690 if (!frame_script_data.IsEmpty()) { | |
691 // Get the script data of the function script. | |
692 const int argc = 1; | |
693 v8::Handle<v8::Value> argv[argc] = { exec_state }; | |
694 v8::Handle<v8::Value> result = frame_script_data->Call(exec_state, | |
695 argc, argv); | |
696 if (result->IsUndefined()) { | |
697 last_script_data_hit[0] = '\0'; | |
698 } else { | |
699 result = result->ToString(); | |
700 CHECK(result->IsString()); | |
701 v8::Handle<v8::String> script_data(result->ToString()); | |
702 script_data->WriteUtf8(last_script_data_hit); | |
703 } | |
704 } | |
705 | |
706 // Perform a full deoptimization when the specified number of | 669 // Perform a full deoptimization when the specified number of |
707 // breaks have been hit. | 670 // breaks have been hit. |
708 if (break_point_hit_count == break_point_hit_count_deoptimize) { | 671 if (break_point_hit_count == break_point_hit_count_deoptimize) { |
709 i::Deoptimizer::DeoptimizeAll(isolate); | 672 i::Deoptimizer::DeoptimizeAll(isolate); |
710 } | 673 } |
711 } else if (event == v8::AfterCompile && !compiled_script_data.IsEmpty()) { | |
712 const int argc = 1; | |
713 v8::Handle<v8::Value> argv[argc] = { event_data }; | |
714 v8::Handle<v8::Value> result = compiled_script_data->Call(exec_state, | |
715 argc, argv); | |
716 if (result->IsUndefined()) { | |
717 last_script_data_hit[0] = '\0'; | |
718 } else { | |
719 result = result->ToString(); | |
720 CHECK(result->IsString()); | |
721 v8::Handle<v8::String> script_data(result->ToString()); | |
722 script_data->WriteUtf8(last_script_data_hit); | |
723 } | |
724 } | 674 } |
725 } | 675 } |
726 | 676 |
727 | 677 |
728 // Debug event handler which counts a number of events and collects the stack | 678 // Debug event handler which counts a number of events and collects the stack |
729 // height if there is a function compiled for that. | 679 // height if there is a function compiled for that. |
730 int exception_hit_count = 0; | 680 int exception_hit_count = 0; |
731 int uncaught_exception_hit_count = 0; | 681 int uncaught_exception_hit_count = 0; |
732 int last_js_stack_height = -1; | 682 int last_js_stack_height = -1; |
733 | 683 |
(...skipping 5508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6242 TEST(ScriptNameAndData) { | 6192 TEST(ScriptNameAndData) { |
6243 DebugLocalContext env; | 6193 DebugLocalContext env; |
6244 v8::HandleScope scope(env->GetIsolate()); | 6194 v8::HandleScope scope(env->GetIsolate()); |
6245 env.ExposeDebug(); | 6195 env.ExposeDebug(); |
6246 | 6196 |
6247 // Create functions for retrieving script name and data for the function on | 6197 // Create functions for retrieving script name and data for the function on |
6248 // the top frame when hitting a break point. | 6198 // the top frame when hitting a break point. |
6249 frame_script_name = CompileFunction(&env, | 6199 frame_script_name = CompileFunction(&env, |
6250 frame_script_name_source, | 6200 frame_script_name_source, |
6251 "frame_script_name"); | 6201 "frame_script_name"); |
6252 frame_script_data = CompileFunction(&env, | |
6253 frame_script_data_source, | |
6254 "frame_script_data"); | |
6255 compiled_script_data = CompileFunction(&env, | |
6256 compiled_script_data_source, | |
6257 "compiled_script_data"); | |
6258 | 6202 |
6259 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 6203 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
6260 | 6204 |
6261 // Test function source. | 6205 // Test function source. |
6262 v8::Local<v8::String> script = v8::String::NewFromUtf8(env->GetIsolate(), | 6206 v8::Local<v8::String> script = v8::String::NewFromUtf8(env->GetIsolate(), |
6263 "function f() {\n" | 6207 "function f() {\n" |
6264 " debugger;\n" | 6208 " debugger;\n" |
6265 "}\n"); | 6209 "}\n"); |
6266 | 6210 |
6267 v8::ScriptOrigin origin1 = | 6211 v8::ScriptOrigin origin1 = |
6268 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); | 6212 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); |
6269 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); | 6213 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); |
6270 script1->SetData(v8::String::NewFromUtf8(env->GetIsolate(), "data")); | |
6271 script1->Run(); | 6214 script1->Run(); |
6272 v8::Local<v8::Function> f; | 6215 v8::Local<v8::Function> f; |
6273 f = v8::Local<v8::Function>::Cast( | 6216 f = v8::Local<v8::Function>::Cast( |
6274 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6217 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6275 | 6218 |
6276 f->Call(env->Global(), 0, NULL); | 6219 f->Call(env->Global(), 0, NULL); |
6277 CHECK_EQ(1, break_point_hit_count); | 6220 CHECK_EQ(1, break_point_hit_count); |
6278 CHECK_EQ("name", last_script_name_hit); | 6221 CHECK_EQ("name", last_script_name_hit); |
6279 CHECK_EQ("data", last_script_data_hit); | |
6280 | 6222 |
6281 // Compile the same script again without setting data. As the compilation | 6223 // Compile the same script again without setting data. As the compilation |
6282 // cache is disabled when debugging expect the data to be missing. | 6224 // cache is disabled when debugging expect the data to be missing. |
6283 v8::Script::Compile(script, &origin1)->Run(); | 6225 v8::Script::Compile(script, &origin1)->Run(); |
6284 f = v8::Local<v8::Function>::Cast( | 6226 f = v8::Local<v8::Function>::Cast( |
6285 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6227 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6286 f->Call(env->Global(), 0, NULL); | 6228 f->Call(env->Global(), 0, NULL); |
6287 CHECK_EQ(2, break_point_hit_count); | 6229 CHECK_EQ(2, break_point_hit_count); |
6288 CHECK_EQ("name", last_script_name_hit); | 6230 CHECK_EQ("name", last_script_name_hit); |
6289 CHECK_EQ("", last_script_data_hit); // Undefined results in empty string. | |
6290 | 6231 |
6291 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( | 6232 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( |
6292 env->GetIsolate(), | 6233 env->GetIsolate(), |
6293 "({ a: 'abc',\n" | 6234 "({ a: 'abc',\n" |
6294 " b: 123,\n" | 6235 " b: 123,\n" |
6295 " toString: function() { return this.a + ' ' + this.b; }\n" | 6236 " toString: function() { return this.a + ' ' + this.b; }\n" |
6296 "})\n"); | 6237 "})\n"); |
6297 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run(); | 6238 v8::Script::Compile(data_obj_source)->Run(); |
6298 v8::ScriptOrigin origin2 = | 6239 v8::ScriptOrigin origin2 = |
6299 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); | 6240 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); |
6300 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 6241 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
6301 script2->Run(); | 6242 script2->Run(); |
6302 script2->SetData(data_obj->ToString()); | |
6303 f = v8::Local<v8::Function>::Cast( | 6243 f = v8::Local<v8::Function>::Cast( |
6304 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6244 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6305 f->Call(env->Global(), 0, NULL); | 6245 f->Call(env->Global(), 0, NULL); |
6306 CHECK_EQ(3, break_point_hit_count); | 6246 CHECK_EQ(3, break_point_hit_count); |
6307 CHECK_EQ("new name", last_script_name_hit); | 6247 CHECK_EQ("new name", last_script_name_hit); |
6308 CHECK_EQ("abc 123", last_script_data_hit); | |
6309 | 6248 |
6310 v8::Handle<v8::Script> script3 = v8::Script::Compile( | 6249 v8::Handle<v8::Script> script3 = v8::Script::Compile( |
6311 script, &origin2, NULL, | 6250 script, &origin2, NULL); |
6312 v8::String::NewFromUtf8(env->GetIsolate(), "in compile")); | |
6313 CHECK_EQ("in compile", last_script_data_hit); | |
6314 script3->Run(); | 6251 script3->Run(); |
6315 f = v8::Local<v8::Function>::Cast( | 6252 f = v8::Local<v8::Function>::Cast( |
6316 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6253 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6317 f->Call(env->Global(), 0, NULL); | 6254 f->Call(env->Global(), 0, NULL); |
6318 CHECK_EQ(4, break_point_hit_count); | 6255 CHECK_EQ(4, break_point_hit_count); |
6319 CHECK_EQ("in compile", last_script_data_hit); | |
6320 } | 6256 } |
6321 | 6257 |
6322 | 6258 |
6323 static v8::Handle<v8::Context> expected_context; | 6259 static v8::Handle<v8::Context> expected_context; |
6324 static v8::Handle<v8::Value> expected_context_data; | 6260 static v8::Handle<v8::Value> expected_context_data; |
6325 | 6261 |
6326 | 6262 |
6327 // Check that the expected context is the one generating the debug event. | 6263 // Check that the expected context is the one generating the debug event. |
6328 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { | 6264 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { |
6329 CHECK(message.GetEventContext() == expected_context); | 6265 CHECK(message.GetEventContext() == expected_context); |
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7729 CHECK(result->IsString()); | 7665 CHECK(result->IsString()); |
7730 v8::String::Utf8Value utf8(result); | 7666 v8::String::Utf8Value utf8(result); |
7731 CHECK_EQ("bar", *utf8); | 7667 CHECK_EQ("bar", *utf8); |
7732 | 7668 |
7733 v8::Debug::SetDebugEventListener2(NULL); | 7669 v8::Debug::SetDebugEventListener2(NULL); |
7734 CheckDebuggerUnloaded(); | 7670 CheckDebuggerUnloaded(); |
7735 } | 7671 } |
7736 | 7672 |
7737 | 7673 |
7738 #endif // ENABLE_DEBUGGER_SUPPORT | 7674 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |