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

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

Issue 115462: Add a script cache to the debugger... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 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
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 4513 matching lines...) Expand 10 before | Expand all | Expand 10 after
4524 virtual size_t length() const { return empty_.length(); } 4524 virtual size_t length() const { return empty_.length(); }
4525 virtual const uint16_t* data() const { return empty_.start(); } 4525 virtual const uint16_t* data() const { return empty_.start(); }
4526 private: 4526 private:
4527 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_; 4527 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_;
4528 }; 4528 };
4529 4529
4530 4530
4531 TEST(DebugGetLoadedScripts) { 4531 TEST(DebugGetLoadedScripts) {
4532 v8::HandleScope scope; 4532 v8::HandleScope scope;
4533 DebugLocalContext env; 4533 DebugLocalContext env;
4534 env.ExposeDebug();
4535
4534 EmptyExternalStringResource source_ext_str; 4536 EmptyExternalStringResource source_ext_str;
4535 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); 4537 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
4536 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source); 4538 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source);
4537 Handle<i::ExternalTwoByteString> i_source( 4539 Handle<i::ExternalTwoByteString> i_source(
4538 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); 4540 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
4539 // This situation can happen if source was an external string disposed 4541 // This situation can happen if source was an external string disposed
4540 // by its owner. 4542 // by its owner.
4541 i_source->set_resource(0); 4543 i_source->set_resource(0);
4542 4544
4543 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; 4545 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
4544 i::FLAG_allow_natives_syntax = true; 4546 i::FLAG_allow_natives_syntax = true;
4545 CompileRun( 4547 CompileRun(
4546 "var scripts = %DebugGetLoadedScripts();" 4548 "var scripts = %DebugGetLoadedScripts();"
4547 "for (var i = 0; i < scripts.length; ++i) {" 4549 "var count = scripts.length;"
4548 " scripts[i].line_ends;" 4550 "for (var i = 0; i < count; ++i) {"
4551 " scripts[i].line_ends;"
4549 "}"); 4552 "}");
4550 // Must not crash while accessing line_ends. 4553 // Must not crash while accessing line_ends.
4551 i::FLAG_allow_natives_syntax = allow_natives_syntax; 4554 i::FLAG_allow_natives_syntax = allow_natives_syntax;
4555
4556 // Some scripts are retrieved - at least the number of native scripts.
4557 CHECK_GT((*env)->Global()->Get(v8::String::New("count"))->Int32Value(), 8);
4552 } 4558 }
4553 4559
4554 4560
4555 // Test script break points set on lines. 4561 // Test script break points set on lines.
4556 TEST(ScriptNameAndData) { 4562 TEST(ScriptNameAndData) {
4557 v8::HandleScope scope; 4563 v8::HandleScope scope;
4558 DebugLocalContext env; 4564 DebugLocalContext env;
4559 env.ExposeDebug(); 4565 env.ExposeDebug();
4560 4566
4561 // Create functions for retrieving script name and data for the function on 4567 // Create functions for retrieving script name and data for the function on
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4679 v8::Context::Scope context_scope(context_2); 4685 v8::Context::Scope context_scope(context_2);
4680 expected_context = context_2; 4686 expected_context = context_2;
4681 expected_context_data = data_2; 4687 expected_context_data = data_2;
4682 v8::Local<v8::Function> f = CompileFunction(source, "f"); 4688 v8::Local<v8::Function> f = CompileFunction(source, "f");
4683 f->Call(context_2->Global(), 0, NULL); 4689 f->Call(context_2->Global(), 0, NULL);
4684 } 4690 }
4685 4691
4686 // Two times compile event and two times break event. 4692 // Two times compile event and two times break event.
4687 CHECK_GT(message_handler_hit_count, 4); 4693 CHECK_GT(message_handler_hit_count, 4);
4688 } 4694 }
4695
4696
4697 // Debug event listener which counts the script collected events.
4698 int script_collected_count = 0;
4699 static void DebugEventScriptCollectedEvent(v8::DebugEvent event,
4700 v8::Handle<v8::Object> exec_state,
4701 v8::Handle<v8::Object> event_data,
4702 v8::Handle<v8::Value> data) {
4703 // Count the number of breaks.
4704 if (event == v8::ScriptCollected) {
4705 script_collected_count++;
4706 }
4707 }
4708
4709
4710 // Test that scripts collected are reported through the debug event listener.
4711 TEST(ScriptCollectedEvent) {
4712 break_point_hit_count = 0;
4713 v8::HandleScope scope;
4714 DebugLocalContext env;
4715
4716 // Request the loaded scripte to initialize the debugger script cache.
4717 Debug::GetLoadedScripts();
4718
4719 // Do garbage collection to ensure that only the script in this test will be
4720 // collected afterwards.
4721 Heap::CollectAllGarbage();
4722
4723 script_collected_count = 0;
4724 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent,
4725 v8::Undefined());
4726 {
4727 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run();
4728 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run();
4729 }
4730
4731 // Do garbage collection to collect the script above which is no longer
4732 // referenced.
4733 Heap::CollectAllGarbage();
4734
4735 CHECK_EQ(2, script_collected_count);
4736
4737 v8::Debug::SetDebugEventListener(NULL);
4738 CheckDebuggerUnloaded();
4739 }
OLDNEW
« src/debug.cc ('K') | « src/utils.cc ('k') | test/mjsunit/debug-references.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698