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

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

Issue 90003: Make it possible to add a user data object to each script compiled (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 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-api.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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 518
519 // Source for The JavaScript function which picks out the source column for the 519 // Source for The JavaScript function which picks out the source column for the
520 // top frame. 520 // top frame.
521 const char* frame_source_column_source = 521 const char* frame_source_column_source =
522 "function frame_source_column(exec_state) {" 522 "function frame_source_column(exec_state) {"
523 " return exec_state.frame(0).sourceColumn();" 523 " return exec_state.frame(0).sourceColumn();"
524 "}"; 524 "}";
525 v8::Local<v8::Function> frame_source_column; 525 v8::Local<v8::Function> frame_source_column;
526 526
527 527
528 // Source for The JavaScript function which picks out the script name for the
529 // top frame.
530 const char* frame_script_name_source =
531 "function frame_script_name(exec_state) {"
532 " return exec_state.frame(0).func().script().name();"
533 "}";
534 v8::Local<v8::Function> frame_script_name;
535
536
537 // Source for The JavaScript function which picks out the script data for the
538 // top frame.
539 const char* frame_script_data_source =
540 "function frame_script_data(exec_state) {"
541 " return exec_state.frame(0).func().script().data();"
542 "}";
543 v8::Local<v8::Function> frame_script_data;
544
545
528 // Source for The JavaScript function which returns the number of frames. 546 // Source for The JavaScript function which returns the number of frames.
529 static const char* frame_count_source = 547 static const char* frame_count_source =
530 "function frame_count(exec_state) {" 548 "function frame_count(exec_state) {"
531 " return exec_state.frameCount();" 549 " return exec_state.frameCount();"
532 "}"; 550 "}";
533 v8::Handle<v8::Function> frame_count; 551 v8::Handle<v8::Function> frame_count;
534 552
535 553
536 // Global variable to store the last function hit - used by some tests. 554 // Global variable to store the last function hit - used by some tests.
537 char last_function_hit[80]; 555 char last_function_hit[80];
538 556
557 // Global variable to store the name and data for last script hit - used by some
558 // tests.
559 char last_script_name_hit[80];
560 char last_script_data_hit[80];
561
539 // Global variables to store the last source position - used by some tests. 562 // Global variables to store the last source position - used by some tests.
540 int last_source_line = -1; 563 int last_source_line = -1;
541 int last_source_column = -1; 564 int last_source_column = -1;
542 565
543 // Debug event handler which counts the break points which have been hit. 566 // Debug event handler which counts the break points which have been hit.
544 int break_point_hit_count = 0; 567 int break_point_hit_count = 0;
545 static void DebugEventBreakPointHitCount(v8::DebugEvent event, 568 static void DebugEventBreakPointHitCount(v8::DebugEvent event,
546 v8::Handle<v8::Object> exec_state, 569 v8::Handle<v8::Object> exec_state,
547 v8::Handle<v8::Object> event_data, 570 v8::Handle<v8::Object> event_data,
548 v8::Handle<v8::Value> data) { 571 v8::Handle<v8::Value> data) {
(...skipping 30 matching lines...) Expand all
579 602
580 if (!frame_source_column.IsEmpty()) { 603 if (!frame_source_column.IsEmpty()) {
581 // Get the source column. 604 // Get the source column.
582 const int argc = 1; 605 const int argc = 1;
583 v8::Handle<v8::Value> argv[argc] = { exec_state }; 606 v8::Handle<v8::Value> argv[argc] = { exec_state };
584 v8::Handle<v8::Value> result = frame_source_column->Call(exec_state, 607 v8::Handle<v8::Value> result = frame_source_column->Call(exec_state,
585 argc, argv); 608 argc, argv);
586 CHECK(result->IsNumber()); 609 CHECK(result->IsNumber());
587 last_source_column = result->Int32Value(); 610 last_source_column = result->Int32Value();
588 } 611 }
612
613 if (!frame_script_name.IsEmpty()) {
614 // Get the script name of the function script.
615 const int argc = 1;
616 v8::Handle<v8::Value> argv[argc] = { exec_state };
617 v8::Handle<v8::Value> result = frame_script_name->Call(exec_state,
618 argc, argv);
619 if (result->IsUndefined()) {
620 last_script_name_hit[0] = '\0';
621 } else {
622 CHECK(result->IsString());
623 v8::Handle<v8::String> script_name(result->ToString());
624 script_name->WriteAscii(last_script_name_hit);
625 }
626 }
627
628 if (!frame_script_data.IsEmpty()) {
629 // Get the script data of the function script.
630 const int argc = 1;
631 v8::Handle<v8::Value> argv[argc] = { exec_state };
632 v8::Handle<v8::Value> result = frame_script_data->Call(exec_state,
633 argc, argv);
634 if (result->IsUndefined()) {
635 last_script_data_hit[0] = '\0';
636 } else {
637 result = result->ToString();
638 CHECK(result->IsString());
639 v8::Handle<v8::String> script_data(result->ToString());
640 script_data->WriteAscii(last_script_data_hit);
641 }
642 }
589 } 643 }
590 } 644 }
591 645
592 646
593 // Debug event handler which counts a number of events and collects the stack 647 // Debug event handler which counts a number of events and collects the stack
594 // height if there is a function compiled for that. 648 // height if there is a function compiled for that.
595 int exception_hit_count = 0; 649 int exception_hit_count = 0;
596 int uncaught_exception_hit_count = 0; 650 int uncaught_exception_hit_count = 0;
597 int last_js_stack_height = -1; 651 int last_js_stack_height = -1;
598 652
(...skipping 3643 matching lines...) Expand 10 before | Expand all | Expand 10 after
4242 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; 4296 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
4243 i::FLAG_allow_natives_syntax = true; 4297 i::FLAG_allow_natives_syntax = true;
4244 CompileRun( 4298 CompileRun(
4245 "var scripts = %DebugGetLoadedScripts();" 4299 "var scripts = %DebugGetLoadedScripts();"
4246 "for (var i = 0; i < scripts.length; ++i) {" 4300 "for (var i = 0; i < scripts.length; ++i) {"
4247 " scripts[i].line_ends;" 4301 " scripts[i].line_ends;"
4248 "}"); 4302 "}");
4249 // Must not crash while accessing line_ends. 4303 // Must not crash while accessing line_ends.
4250 i::FLAG_allow_natives_syntax = allow_natives_syntax; 4304 i::FLAG_allow_natives_syntax = allow_natives_syntax;
4251 } 4305 }
4306
4307
4308 // Test script break points set on lines.
4309 TEST(ScriptNameAndData) {
4310 v8::HandleScope scope;
4311 DebugLocalContext env;
4312 env.ExposeDebug();
4313
4314 // Create functions for retrieving script name and data for the function on
4315 // the top frame when hitting a break point.
4316 frame_script_name = CompileFunction(&env,
4317 frame_script_name_source,
4318 "frame_script_name");
4319 frame_script_data = CompileFunction(&env,
4320 frame_script_data_source,
4321 "frame_script_data");
4322
4323 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
4324 v8::Undefined());
4325
4326 // Test function source.
4327 v8::Local<v8::String> script = v8::String::New(
4328 "function f() {\n"
4329 " debugger;\n"
4330 "}\n");
4331
4332 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name"));
4333 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1);
4334 script1->SetData(v8::String::New("data"));
4335 script1->Run();
4336 v8::Script::Compile(script, &origin1)->Run();
4337 v8::Local<v8::Function> f;
4338 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
4339
4340 f->Call(env->Global(), 0, NULL);
4341 CHECK_EQ(1, break_point_hit_count);
4342 CHECK_EQ("name", last_script_name_hit);
4343 CHECK_EQ("data", last_script_data_hit);
4344
4345 v8::Local<v8::String> data_obj_source = v8::String::New(
4346 "({ a: 'abc',\n"
4347 " b: 123,\n"
4348 " toString: function() { return this.a + ' ' + this.b; }\n"
4349 "})\n");
4350 v8::Local<v8::Value> data_obj = v8::Script::Compile(data_obj_source)->Run();
4351 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
4352 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
4353 script2->Run();
4354 script2->SetData(data_obj);
4355 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
4356 f->Call(env->Global(), 0, NULL);
4357 CHECK_EQ(2, break_point_hit_count);
4358 CHECK_EQ("new name", last_script_name_hit);
4359 CHECK_EQ("abc 123", last_script_data_hit);
4360 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698