OLD | NEW |
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 4799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4810 } | 4810 } |
4811 } | 4811 } |
4812 | 4812 |
4813 | 4813 |
4814 // Test that scripts collected are reported through the debug event listener. | 4814 // Test that scripts collected are reported through the debug event listener. |
4815 TEST(ScriptCollectedEvent) { | 4815 TEST(ScriptCollectedEvent) { |
4816 break_point_hit_count = 0; | 4816 break_point_hit_count = 0; |
4817 v8::HandleScope scope; | 4817 v8::HandleScope scope; |
4818 DebugLocalContext env; | 4818 DebugLocalContext env; |
4819 | 4819 |
4820 // Request the loaded scripte to initialize the debugger script cache. | 4820 // Request the loaded scripts to initialize the debugger script cache. |
4821 Debug::GetLoadedScripts(); | 4821 Debug::GetLoadedScripts(); |
4822 | 4822 |
4823 // Do garbage collection to ensure that only the script in this test will be | 4823 // Do garbage collection to ensure that only the script in this test will be |
4824 // collected afterwards. | 4824 // collected afterwards. |
4825 Heap::CollectAllGarbage(); | 4825 Heap::CollectAllGarbage(); |
4826 | 4826 |
4827 script_collected_count = 0; | 4827 script_collected_count = 0; |
4828 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent, | 4828 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent, |
4829 v8::Undefined()); | 4829 v8::Undefined()); |
4830 { | 4830 { |
4831 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); | 4831 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); |
4832 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); | 4832 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); |
4833 } | 4833 } |
4834 | 4834 |
4835 // Do garbage collection to collect the script above which is no longer | 4835 // Do garbage collection to collect the script above which is no longer |
4836 // referenced. | 4836 // referenced. |
4837 Heap::CollectAllGarbage(); | 4837 Heap::CollectAllGarbage(); |
4838 | 4838 |
4839 CHECK_EQ(2, script_collected_count); | 4839 CHECK_EQ(2, script_collected_count); |
4840 | 4840 |
4841 v8::Debug::SetDebugEventListener(NULL); | 4841 v8::Debug::SetDebugEventListener(NULL); |
4842 CheckDebuggerUnloaded(); | 4842 CheckDebuggerUnloaded(); |
4843 } | 4843 } |
| 4844 |
| 4845 |
| 4846 // Debug event listener which counts the script collected events. |
| 4847 int script_collected_message_count = 0; |
| 4848 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { |
| 4849 // Count the number of scripts collected. |
| 4850 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { |
| 4851 script_collected_message_count++; |
| 4852 v8::Handle<v8::Context> context = message.GetEventContext(); |
| 4853 CHECK(context.IsEmpty()); |
| 4854 } |
| 4855 } |
| 4856 |
| 4857 |
| 4858 // Test that GetEventContext doesn't fail and return empty handle for |
| 4859 // ScriptCollected events. |
| 4860 TEST(ScriptCollectedEventContext) { |
| 4861 break_point_hit_count = 0; |
| 4862 v8::HandleScope scope; |
| 4863 |
| 4864 { // Scope for the DebugLocalContext. |
| 4865 DebugLocalContext env; |
| 4866 |
| 4867 // Request the loaded scripts to initialize the debugger script cache. |
| 4868 Debug::GetLoadedScripts(); |
| 4869 |
| 4870 // Do garbage collection to ensure that only the script in this test will be |
| 4871 // collected afterwards. |
| 4872 Heap::CollectAllGarbage(); |
| 4873 |
| 4874 script_collected_count = 0; |
| 4875 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); |
| 4876 { |
| 4877 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); |
| 4878 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); |
| 4879 } |
| 4880 } |
| 4881 |
| 4882 // Do garbage collection to collect the script above which is no longer |
| 4883 // referenced. |
| 4884 Heap::CollectAllGarbage(); |
| 4885 |
| 4886 CHECK_EQ(2, script_collected_message_count); |
| 4887 |
| 4888 v8::Debug::SetMessageHandler2(NULL); |
| 4889 } |
OLD | NEW |