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

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

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

Powered by Google App Engine
This is Rietveld 408576698