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

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

Issue 606053: Enable passing of script data via script creation methods (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
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') | 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 4564 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 env.ExposeDebug(); 5246 env.ExposeDebug();
5225 5247
5226 // Create functions for retrieving script name and data for the function on 5248 // Create functions for retrieving script name and data for the function on
5227 // the top frame when hitting a break point. 5249 // the top frame when hitting a break point.
5228 frame_script_name = CompileFunction(&env, 5250 frame_script_name = CompileFunction(&env,
5229 frame_script_name_source, 5251 frame_script_name_source,
5230 "frame_script_name"); 5252 "frame_script_name");
5231 frame_script_data = CompileFunction(&env, 5253 frame_script_data = CompileFunction(&env,
5232 frame_script_data_source, 5254 frame_script_data_source,
5233 "frame_script_data"); 5255 "frame_script_data");
5256 compiled_script_data = CompileFunction(&env,
5257 compiled_script_data_source,
5258 "compiled_script_data");
5234 5259
5235 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 5260 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
5236 v8::Undefined()); 5261 v8::Undefined());
5237 5262
5238 // Test function source. 5263 // Test function source.
5239 v8::Local<v8::String> script = v8::String::New( 5264 v8::Local<v8::String> script = v8::String::New(
5240 "function f() {\n" 5265 "function f() {\n"
5241 " debugger;\n" 5266 " debugger;\n"
5242 "}\n"); 5267 "}\n");
5243 5268
(...skipping 26 matching lines...) Expand all
5270 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run(); 5295 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
5271 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 5296 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
5272 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 5297 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
5273 script2->Run(); 5298 script2->Run();
5274 script2->SetData(data_obj->ToString()); 5299 script2->SetData(data_obj->ToString());
5275 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 5300 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
5276 f->Call(env->Global(), 0, NULL); 5301 f->Call(env->Global(), 0, NULL);
5277 CHECK_EQ(3, break_point_hit_count); 5302 CHECK_EQ(3, break_point_hit_count);
5278 CHECK_EQ("new name", last_script_name_hit); 5303 CHECK_EQ("new name", last_script_name_hit);
5279 CHECK_EQ("abc 123", last_script_data_hit); 5304 CHECK_EQ("abc 123", last_script_data_hit);
5305
5306 v8::Handle<v8::Script> script3 =
5307 v8::Script::Compile(script, &origin2, NULL,
5308 v8::String::New("in compile"));
5309 CHECK_EQ("in compile", last_script_data_hit);
5310 script3->Run();
5311 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
5312 f->Call(env->Global(), 0, NULL);
5313 CHECK_EQ(4, break_point_hit_count);
5314 CHECK_EQ("in compile", last_script_data_hit);
5280 } 5315 }
5281 5316
5282 5317
5283 static v8::Persistent<v8::Context> expected_context; 5318 static v8::Persistent<v8::Context> expected_context;
5284 static v8::Handle<v8::Value> expected_context_data; 5319 static v8::Handle<v8::Value> expected_context_data;
5285 5320
5286 5321
5287 // Check that the expected context is the one generating the debug event. 5322 // Check that the expected context is the one generating the debug event.
5288 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { 5323 static void ContextCheckMessageHandler(const v8::Debug::Message& message) {
5289 CHECK(message.GetEventContext() == expected_context); 5324 CHECK(message.GetEventContext() == expected_context);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
6098 6133
6099 break_point_hit_count = 0; 6134 break_point_hit_count = 0;
6100 foo->Call(env->Global(), 0, NULL); 6135 foo->Call(env->Global(), 0, NULL);
6101 CHECK_EQ(1, break_point_hit_count); 6136 CHECK_EQ(1, break_point_hit_count);
6102 6137
6103 v8::Debug::SetDebugEventListener(NULL); 6138 v8::Debug::SetDebugEventListener(NULL);
6104 debugee_context = v8::Handle<v8::Context>(); 6139 debugee_context = v8::Handle<v8::Context>();
6105 debugger_context = v8::Handle<v8::Context>(); 6140 debugger_context = v8::Handle<v8::Context>();
6106 CheckDebuggerUnloaded(); 6141 CheckDebuggerUnloaded();
6107 } 6142 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698