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

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

Issue 660095: Merge revision 3813 to 3930 from bleeding_edge to partial snapshots branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: '' Created 10 years, 10 months 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 | « test/cctest/test-compiler.cc ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 543
544 // Source for The JavaScript function which picks out the script data for the 544 // Source for The JavaScript function which picks out the script data for the
545 // top frame. 545 // top frame.
546 const char* frame_script_data_source = 546 const char* frame_script_data_source =
547 "function frame_script_data(exec_state) {" 547 "function frame_script_data(exec_state) {"
548 " return exec_state.frame(0).func().script().data();" 548 " return exec_state.frame(0).func().script().data();"
549 "}"; 549 "}";
550 v8::Local<v8::Function> frame_script_data; 550 v8::Local<v8::Function> frame_script_data;
551 551
552 552
553 // Source for The JavaScript function which picks out the script data from
554 // AfterCompile event
555 const char* compiled_script_data_source =
556 "function compiled_script_data(event_data) {"
557 " return event_data.script().data();"
558 "}";
559 v8::Local<v8::Function> compiled_script_data;
560
561
553 // Source for The JavaScript function which returns the number of frames. 562 // Source for The JavaScript function which returns the number of frames.
554 static const char* frame_count_source = 563 static const char* frame_count_source =
555 "function frame_count(exec_state) {" 564 "function frame_count(exec_state) {"
556 " return exec_state.frameCount();" 565 " return exec_state.frameCount();"
557 "}"; 566 "}";
558 v8::Handle<v8::Function> frame_count; 567 v8::Handle<v8::Function> frame_count;
559 568
560 569
561 // Global variable to store the last function hit - used by some tests. 570 // Global variable to store the last function hit - used by some tests.
562 char last_function_hit[80]; 571 char last_function_hit[80];
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 argc, argv); 649 argc, argv);
641 if (result->IsUndefined()) { 650 if (result->IsUndefined()) {
642 last_script_data_hit[0] = '\0'; 651 last_script_data_hit[0] = '\0';
643 } else { 652 } else {
644 result = result->ToString(); 653 result = result->ToString();
645 CHECK(result->IsString()); 654 CHECK(result->IsString());
646 v8::Handle<v8::String> script_data(result->ToString()); 655 v8::Handle<v8::String> script_data(result->ToString());
647 script_data->WriteAscii(last_script_data_hit); 656 script_data->WriteAscii(last_script_data_hit);
648 } 657 }
649 } 658 }
659 } else if (event == v8::AfterCompile && !compiled_script_data.IsEmpty()) {
660 const int argc = 1;
661 v8::Handle<v8::Value> argv[argc] = { event_data };
662 v8::Handle<v8::Value> result = compiled_script_data->Call(exec_state,
663 argc, argv);
664 if (result->IsUndefined()) {
665 last_script_data_hit[0] = '\0';
666 } else {
667 result = result->ToString();
668 CHECK(result->IsString());
669 v8::Handle<v8::String> script_data(result->ToString());
670 script_data->WriteAscii(last_script_data_hit);
671 }
650 } 672 }
651 } 673 }
652 674
653 675
654 // Debug event handler which counts a number of events and collects the stack 676 // Debug event handler which counts a number of events and collects the stack
655 // height if there is a function compiled for that. 677 // height if there is a function compiled for that.
656 int exception_hit_count = 0; 678 int exception_hit_count = 0;
657 int uncaught_exception_hit_count = 0; 679 int uncaught_exception_hit_count = 0;
658 int last_js_stack_height = -1; 680 int last_js_stack_height = -1;
659 681
(...skipping 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 // We match the message wether it is an evaluate response message. 3899 // We match the message wether it is an evaluate response message.
3878 bool IsEvaluateResponseMessage(char* message) { 3900 bool IsEvaluateResponseMessage(char* message) {
3879 const char* type_response = "\"type\":\"response\""; 3901 const char* type_response = "\"type\":\"response\"";
3880 const char* command_evaluate = "\"command\":\"evaluate\""; 3902 const char* command_evaluate = "\"command\":\"evaluate\"";
3881 // Does the message contain both type:response and command:evaluate? 3903 // Does the message contain both type:response and command:evaluate?
3882 return strstr(message, type_response) != NULL && 3904 return strstr(message, type_response) != NULL &&
3883 strstr(message, command_evaluate) != NULL; 3905 strstr(message, command_evaluate) != NULL;
3884 } 3906 }
3885 3907
3886 3908
3909 static int StringToInt(const char* s) {
3910 return atoi(s); // NOLINT
3911 }
3912
3913
3887 // We match parts of the message to get evaluate result int value. 3914 // We match parts of the message to get evaluate result int value.
3888 int GetEvaluateIntResult(char *message) { 3915 int GetEvaluateIntResult(char *message) {
3889 const char* value = "\"value\":"; 3916 const char* value = "\"value\":";
3890 char* pos = strstr(message, value); 3917 char* pos = strstr(message, value);
3891 if (pos == NULL) { 3918 if (pos == NULL) {
3892 return -1; 3919 return -1;
3893 } 3920 }
3894 int res = -1; 3921 int res = -1;
3895 res = atoi(pos + strlen(value)); 3922 res = StringToInt(pos + strlen(value));
3896 return res; 3923 return res;
3897 } 3924 }
3898 3925
3899 3926
3900 // We match parts of the message to get hit breakpoint id. 3927 // We match parts of the message to get hit breakpoint id.
3901 int GetBreakpointIdFromBreakEventMessage(char *message) { 3928 int GetBreakpointIdFromBreakEventMessage(char *message) {
3902 const char* breakpoints = "\"breakpoints\":["; 3929 const char* breakpoints = "\"breakpoints\":[";
3903 char* pos = strstr(message, breakpoints); 3930 char* pos = strstr(message, breakpoints);
3904 if (pos == NULL) { 3931 if (pos == NULL) {
3905 return -1; 3932 return -1;
3906 } 3933 }
3907 int res = -1; 3934 int res = -1;
3908 res = atoi(pos + strlen(breakpoints)); 3935 res = StringToInt(pos + strlen(breakpoints));
3909 return res; 3936 return res;
3910 } 3937 }
3911 3938
3912 3939
3913 // We match parts of the message to get total frames number. 3940 // We match parts of the message to get total frames number.
3914 int GetTotalFramesInt(char *message) { 3941 int GetTotalFramesInt(char *message) {
3915 const char* prefix = "\"totalFrames\":"; 3942 const char* prefix = "\"totalFrames\":";
3916 char* pos = strstr(message, prefix); 3943 char* pos = strstr(message, prefix);
3917 if (pos == NULL) { 3944 if (pos == NULL) {
3918 return -1; 3945 return -1;
3919 } 3946 }
3920 pos += strlen(prefix); 3947 pos += strlen(prefix);
3921 char* pos_end = pos; 3948 int res = StringToInt(pos);
3922 int res = static_cast<int>(strtol(pos, &pos_end, 10));
3923 if (pos_end == pos) {
3924 return -1;
3925 }
3926 return res; 3949 return res;
3927 } 3950 }
3928 3951
3929 3952
3930 /* Test MessageQueues */ 3953 /* Test MessageQueues */
3931 /* Tests the message queues that hold debugger commands and 3954 /* Tests the message queues that hold debugger commands and
3932 * response messages to the debugger. Fills queues and makes 3955 * response messages to the debugger. Fills queues and makes
3933 * them grow. 3956 * them grow.
3934 */ 3957 */
3935 Barriers message_queue_barriers; 3958 Barriers message_queue_barriers;
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 env.ExposeDebug(); 5247 env.ExposeDebug();
5225 5248
5226 // Create functions for retrieving script name and data for the function on 5249 // Create functions for retrieving script name and data for the function on
5227 // the top frame when hitting a break point. 5250 // the top frame when hitting a break point.
5228 frame_script_name = CompileFunction(&env, 5251 frame_script_name = CompileFunction(&env,
5229 frame_script_name_source, 5252 frame_script_name_source,
5230 "frame_script_name"); 5253 "frame_script_name");
5231 frame_script_data = CompileFunction(&env, 5254 frame_script_data = CompileFunction(&env,
5232 frame_script_data_source, 5255 frame_script_data_source,
5233 "frame_script_data"); 5256 "frame_script_data");
5257 compiled_script_data = CompileFunction(&env,
5258 compiled_script_data_source,
5259 "compiled_script_data");
5234 5260
5235 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 5261 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
5236 v8::Undefined()); 5262 v8::Undefined());
5237 5263
5238 // Test function source. 5264 // Test function source.
5239 v8::Local<v8::String> script = v8::String::New( 5265 v8::Local<v8::String> script = v8::String::New(
5240 "function f() {\n" 5266 "function f() {\n"
5241 " debugger;\n" 5267 " debugger;\n"
5242 "}\n"); 5268 "}\n");
5243 5269
(...skipping 26 matching lines...) Expand all
5270 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run(); 5296 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
5271 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 5297 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
5272 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 5298 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
5273 script2->Run(); 5299 script2->Run();
5274 script2->SetData(data_obj->ToString()); 5300 script2->SetData(data_obj->ToString());
5275 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 5301 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
5276 f->Call(env->Global(), 0, NULL); 5302 f->Call(env->Global(), 0, NULL);
5277 CHECK_EQ(3, break_point_hit_count); 5303 CHECK_EQ(3, break_point_hit_count);
5278 CHECK_EQ("new name", last_script_name_hit); 5304 CHECK_EQ("new name", last_script_name_hit);
5279 CHECK_EQ("abc 123", last_script_data_hit); 5305 CHECK_EQ("abc 123", last_script_data_hit);
5306
5307 v8::Handle<v8::Script> script3 =
5308 v8::Script::Compile(script, &origin2, NULL,
5309 v8::String::New("in compile"));
5310 CHECK_EQ("in compile", last_script_data_hit);
5311 script3->Run();
5312 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
5313 f->Call(env->Global(), 0, NULL);
5314 CHECK_EQ(4, break_point_hit_count);
5315 CHECK_EQ("in compile", last_script_data_hit);
5280 } 5316 }
5281 5317
5282 5318
5283 static v8::Persistent<v8::Context> expected_context; 5319 static v8::Persistent<v8::Context> expected_context;
5284 static v8::Handle<v8::Value> expected_context_data; 5320 static v8::Handle<v8::Value> expected_context_data;
5285 5321
5286 5322
5287 // Check that the expected context is the one generating the debug event. 5323 // Check that the expected context is the one generating the debug event.
5288 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { 5324 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
5289 CHECK(message.GetEventContext() == expected_context); 5325 CHECK(message.GetEventContext() == expected_context);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
6098 6134
6099 break_point_hit_count = 0; 6135 break_point_hit_count = 0;
6100 foo->Call(env->Global(), 0, NULL); 6136 foo->Call(env->Global(), 0, NULL);
6101 CHECK_EQ(1, break_point_hit_count); 6137 CHECK_EQ(1, break_point_hit_count);
6102 6138
6103 v8::Debug::SetDebugEventListener(NULL); 6139 v8::Debug::SetDebugEventListener(NULL);
6104 debugee_context = v8::Handle<v8::Context>(); 6140 debugee_context = v8::Handle<v8::Context>();
6105 debugger_context = v8::Handle<v8::Context>(); 6141 debugger_context = v8::Handle<v8::Context>();
6106 CheckDebuggerUnloaded(); 6142 CheckDebuggerUnloaded();
6107 } 6143 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698