OLD | NEW |
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 7960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7971 if (event_details.GetEvent() != v8::AfterCompile) return; | 7971 if (event_details.GetEvent() != v8::AfterCompile) return; |
7972 ++after_compile_handler_depth; | 7972 ++after_compile_handler_depth; |
7973 // Do not allow nested AfterCompile events. | 7973 // Do not allow nested AfterCompile events. |
7974 CHECK(after_compile_handler_depth <= 1); | 7974 CHECK(after_compile_handler_depth <= 1); |
7975 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); | 7975 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); |
7976 isolate->RequestInterrupt(&HandleInterrupt, nullptr); | 7976 isolate->RequestInterrupt(&HandleInterrupt, nullptr); |
7977 CompileRun("function foo() {}; foo();"); | 7977 CompileRun("function foo() {}; foo();"); |
7978 --after_compile_handler_depth; | 7978 --after_compile_handler_depth; |
7979 } | 7979 } |
7980 | 7980 |
7981 | |
7982 TEST(NoInterruptsInDebugListener) { | 7981 TEST(NoInterruptsInDebugListener) { |
7983 DebugLocalContext env; | 7982 DebugLocalContext env; |
7984 v8::Debug::SetDebugEventListener(env->GetIsolate(), NoInterruptsOnDebugEvent); | 7983 v8::Debug::SetDebugEventListener(env->GetIsolate(), NoInterruptsOnDebugEvent); |
7985 CompileRun("void(0);"); | 7984 CompileRun("void(0);"); |
7986 } | 7985 } |
7987 | 7986 |
7988 class TestBreakLocation : public i::BreakLocation { | |
7989 public: | |
7990 using i::BreakLocation::GetIterator; | |
7991 using i::BreakLocation::Iterator; | |
7992 }; | |
7993 | |
7994 TEST(BreakLocationIterator) { | 7987 TEST(BreakLocationIterator) { |
7995 DebugLocalContext env; | 7988 DebugLocalContext env; |
7996 v8::Isolate* isolate = env->GetIsolate(); | 7989 v8::Isolate* isolate = env->GetIsolate(); |
7997 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7990 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7998 v8::HandleScope scope(isolate); | 7991 v8::HandleScope scope(isolate); |
7999 | 7992 |
8000 v8::Local<v8::Value> result = CompileRun( | 7993 v8::Local<v8::Value> result = CompileRun( |
8001 "function f() {\n" | 7994 "function f() {\n" |
8002 " debugger; \n" | 7995 " debugger; \n" |
8003 " f(); \n" | 7996 " f(); \n" |
8004 " debugger; \n" | 7997 " debugger; \n" |
8005 "} \n" | 7998 "} \n" |
8006 "f"); | 7999 "f"); |
8007 Handle<i::Object> function_obj = v8::Utils::OpenHandle(*result); | 8000 Handle<i::Object> function_obj = v8::Utils::OpenHandle(*result); |
8008 Handle<i::JSFunction> function = Handle<i::JSFunction>::cast(function_obj); | 8001 Handle<i::JSFunction> function = Handle<i::JSFunction>::cast(function_obj); |
8009 Handle<i::SharedFunctionInfo> shared(function->shared()); | 8002 Handle<i::SharedFunctionInfo> shared(function->shared()); |
8010 | 8003 |
8011 EnableDebugger(isolate); | 8004 EnableDebugger(isolate); |
8012 CHECK(i_isolate->debug()->EnsureDebugInfo(shared, function)); | 8005 CHECK(i_isolate->debug()->EnsureDebugInfo(shared, function)); |
8013 | 8006 |
8014 Handle<i::DebugInfo> debug_info(shared->GetDebugInfo()); | 8007 Handle<i::DebugInfo> debug_info(shared->GetDebugInfo()); |
8015 int code_size = debug_info->abstract_code()->Size(); | 8008 Handle<i::AbstractCode> abstract_code(shared->abstract_code()); |
8016 | 8009 |
8017 bool found_return = false; | 8010 { |
8018 bool found_call = false; | 8011 auto iterator = i::BreakIterator::GetIterator(debug_info, abstract_code, |
8019 bool found_debugger = false; | 8012 i::ALL_BREAK_LOCATIONS); |
| 8013 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); |
| 8014 CHECK_EQ(17, iterator->GetBreakLocation().position()); |
| 8015 iterator->Next(); |
| 8016 CHECK(iterator->GetBreakLocation().IsDebugBreakSlot()); |
| 8017 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
| 8018 iterator->Next(); |
| 8019 CHECK(iterator->GetBreakLocation().IsCall()); |
| 8020 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
| 8021 iterator->Next(); |
| 8022 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); |
| 8023 CHECK_EQ(47, iterator->GetBreakLocation().position()); |
| 8024 iterator->Next(); |
| 8025 CHECK(iterator->GetBreakLocation().IsReturn()); |
| 8026 CHECK_EQ(60, iterator->GetBreakLocation().position()); |
| 8027 iterator->Next(); |
| 8028 CHECK(iterator->Done()); |
| 8029 } |
8020 | 8030 |
8021 // Test public interface. | 8031 { |
8022 for (int i = 0; i < code_size; i++) { | 8032 auto iterator = i::BreakIterator::GetIterator(debug_info, abstract_code, |
8023 i::BreakLocation location = i::BreakLocation::FromCodeOffset(debug_info, i); | 8033 i::CALLS_AND_RETURNS); |
8024 if (location.IsCall()) found_call = true; | 8034 CHECK(iterator->GetBreakLocation().IsCall()); |
8025 if (location.IsReturn()) found_return = true; | 8035 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
8026 if (location.IsDebuggerStatement()) found_debugger = true; | 8036 iterator->Next(); |
| 8037 CHECK(iterator->GetBreakLocation().IsReturn()); |
| 8038 CHECK_EQ(60, iterator->GetBreakLocation().position()); |
| 8039 iterator->Next(); |
| 8040 CHECK(iterator->Done()); |
8027 } | 8041 } |
8028 CHECK(found_call); | |
8029 CHECK(found_return); | |
8030 CHECK(found_debugger); | |
8031 | |
8032 // Test underlying implementation. | |
8033 TestBreakLocation::Iterator* iterator = | |
8034 TestBreakLocation::GetIterator(debug_info, i::ALL_BREAK_LOCATIONS); | |
8035 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); | |
8036 CHECK_EQ(17, iterator->GetBreakLocation().position()); | |
8037 iterator->Next(); | |
8038 CHECK(iterator->GetBreakLocation().IsDebugBreakSlot()); | |
8039 CHECK_EQ(32, iterator->GetBreakLocation().position()); | |
8040 iterator->Next(); | |
8041 CHECK(iterator->GetBreakLocation().IsCall()); | |
8042 CHECK_EQ(32, iterator->GetBreakLocation().position()); | |
8043 iterator->Next(); | |
8044 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); | |
8045 CHECK_EQ(47, iterator->GetBreakLocation().position()); | |
8046 iterator->Next(); | |
8047 CHECK(iterator->GetBreakLocation().IsReturn()); | |
8048 CHECK_EQ(60, iterator->GetBreakLocation().position()); | |
8049 iterator->Next(); | |
8050 CHECK(iterator->Done()); | |
8051 delete iterator; | |
8052 | |
8053 iterator = TestBreakLocation::GetIterator(debug_info, i::CALLS_AND_RETURNS); | |
8054 CHECK(iterator->GetBreakLocation().IsCall()); | |
8055 CHECK_EQ(32, iterator->GetBreakLocation().position()); | |
8056 iterator->Next(); | |
8057 CHECK(iterator->GetBreakLocation().IsReturn()); | |
8058 CHECK_EQ(60, iterator->GetBreakLocation().position()); | |
8059 iterator->Next(); | |
8060 CHECK(iterator->Done()); | |
8061 delete iterator; | |
8062 | 8042 |
8063 DisableDebugger(isolate); | 8043 DisableDebugger(isolate); |
8064 } | 8044 } |
8065 | 8045 |
8066 TEST(DisableTailCallElimination) { | 8046 TEST(DisableTailCallElimination) { |
8067 i::FLAG_allow_natives_syntax = true; | 8047 i::FLAG_allow_natives_syntax = true; |
8068 i::FLAG_harmony_tailcalls = true; | 8048 i::FLAG_harmony_tailcalls = true; |
8069 // TODO(ishell, 4698): Investigate why TurboFan in --always-opt mode makes | 8049 // TODO(ishell, 4698): Investigate why TurboFan in --always-opt mode makes |
8070 // stack[2].getFunctionName() return null. | 8050 // stack[2].getFunctionName() return null. |
8071 i::FLAG_turbo_inlining = false; | 8051 i::FLAG_turbo_inlining = false; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8203 "function foo() {\n" | 8183 "function foo() {\n" |
8204 " try { throw new Error(); } catch (e) {}\n" | 8184 " try { throw new Error(); } catch (e) {}\n" |
8205 "}\n" | 8185 "}\n" |
8206 "debugger;\n" | 8186 "debugger;\n" |
8207 "foo();\n" | 8187 "foo();\n" |
8208 "foo();\n"); | 8188 "foo();\n"); |
8209 | 8189 |
8210 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 8190 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
8211 CHECK_EQ(break_point_hit_count, 4); | 8191 CHECK_EQ(break_point_hit_count, 4); |
8212 } | 8192 } |
OLD | NEW |