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

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

Issue 608013: Enable passing of script data via script creation methods. (Closed)
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
« no previous file with comments | « src/number-info.h ('k') | no next file » | 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 4565 matching lines...) Expand 10 before | Expand all | Expand 10 after
5225 env.ExposeDebug(); 5247 env.ExposeDebug();
5226 5248
5227 // 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
5228 // the top frame when hitting a break point. 5250 // the top frame when hitting a break point.
5229 frame_script_name = CompileFunction(&env, 5251 frame_script_name = CompileFunction(&env,
5230 frame_script_name_source, 5252 frame_script_name_source,
5231 "frame_script_name"); 5253 "frame_script_name");
5232 frame_script_data = CompileFunction(&env, 5254 frame_script_data = CompileFunction(&env,
5233 frame_script_data_source, 5255 frame_script_data_source,
5234 "frame_script_data"); 5256 "frame_script_data");
5257 compiled_script_data = CompileFunction(&env,
5258 compiled_script_data_source,
5259 "compiled_script_data");
5235 5260
5236 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 5261 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
5237 v8::Undefined()); 5262 v8::Undefined());
5238 5263
5239 // Test function source. 5264 // Test function source.
5240 v8::Local<v8::String> script = v8::String::New( 5265 v8::Local<v8::String> script = v8::String::New(
5241 "function f() {\n" 5266 "function f() {\n"
5242 " debugger;\n" 5267 " debugger;\n"
5243 "}\n"); 5268 "}\n");
5244 5269
(...skipping 26 matching lines...) Expand all
5271 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();
5272 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 5297 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
5273 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 5298 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
5274 script2->Run(); 5299 script2->Run();
5275 script2->SetData(data_obj->ToString()); 5300 script2->SetData(data_obj->ToString());
5276 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")));
5277 f->Call(env->Global(), 0, NULL); 5302 f->Call(env->Global(), 0, NULL);
5278 CHECK_EQ(3, break_point_hit_count); 5303 CHECK_EQ(3, break_point_hit_count);
5279 CHECK_EQ("new name", last_script_name_hit); 5304 CHECK_EQ("new name", last_script_name_hit);
5280 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);
5281 } 5316 }
5282 5317
5283 5318
5284 static v8::Persistent<v8::Context> expected_context; 5319 static v8::Persistent<v8::Context> expected_context;
5285 static v8::Handle<v8::Value> expected_context_data; 5320 static v8::Handle<v8::Value> expected_context_data;
5286 5321
5287 5322
5288 // 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.
5289 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { 5324 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
5290 CHECK(message.GetEventContext() == expected_context); 5325 CHECK(message.GetEventContext() == expected_context);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
6099 6134
6100 break_point_hit_count = 0; 6135 break_point_hit_count = 0;
6101 foo->Call(env->Global(), 0, NULL); 6136 foo->Call(env->Global(), 0, NULL);
6102 CHECK_EQ(1, break_point_hit_count); 6137 CHECK_EQ(1, break_point_hit_count);
6103 6138
6104 v8::Debug::SetDebugEventListener(NULL); 6139 v8::Debug::SetDebugEventListener(NULL);
6105 debugee_context = v8::Handle<v8::Context>(); 6140 debugee_context = v8::Handle<v8::Context>();
6106 debugger_context = v8::Handle<v8::Context>(); 6141 debugger_context = v8::Handle<v8::Context>();
6107 CheckDebuggerUnloaded(); 6142 CheckDebuggerUnloaded();
6108 } 6143 }
OLDNEW
« no previous file with comments | « src/number-info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698