Revision: 5862
Author: [email protected]
Date: Fri Nov 19 04:08:52 2010
Log: Add more tests of breaks in infinite loops
Move stack check in do while loops to before the continue target to enable
breaks even if continue was always used in the loop.
Review URL: http://codereview.chromium.org/5184007
http://code.google.com/p/v8/source/detail?r=5862
Modified:
/branches/bleeding_edge/src/full-codegen.cc
/branches/bleeding_edge/test/cctest/test-debug.cc
=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Wed Nov 10 09:00:20 2010
+++ /branches/bleeding_edge/src/full-codegen.cc Fri Nov 19 04:08:52 2010
@@ -882,12 +882,12 @@
Visit(stmt->body());
// Check stack before looping.
+ __ bind(loop_statement.continue_target());
__ StackLimitCheck(&stack_limit_hit);
__ bind(&stack_check_success);
// Record the position of the do while condition and make sure it is
// possible to break on the condition.
- __ bind(loop_statement.continue_target());
SetExpressionPosition(stmt->cond(), stmt->condition_position());
VisitForControl(stmt->cond(),
&body,
=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Thu Nov 4 08:43:12
2010
+++ /branches/bleeding_edge/test/cctest/test-debug.cc Fri Nov 19 04:08:52
2010
@@ -6900,26 +6900,71 @@
// Test that setting the terminate execution flag during debug break
processing.
+static void TestDebugBreakInLoop(const char* loop_head,
+ const char** loop_bodies,
+ const char* loop_tail) {
+ // Receive 100 breaks for each test and then terminate JavaScript
execution.
+ static int count = 0;
+
+ for (int i = 0; loop_bodies[i] != NULL; i++) {
+ count++;
+ max_break_point_hit_count = count * 100;
+ terminate_after_max_break_point_hit = true;
+
+ EmbeddedVector<char, 1024> buffer;
+ OS::SNPrintF(buffer,
+ "function f() {%s%s%s}",
+ loop_head, loop_bodies[i], loop_tail);
+
+ // Function with infinite loop.
+ CompileRun(buffer.start());
+
+ // Set the debug break to enter the debugger as soon as possible.
+ v8::Debug::DebugBreak();
+
+ // Call function with infinite loop.
+ CompileRun("f();");
+ CHECK_EQ(count * 100, break_point_hit_count);
+
+ CHECK(!v8::V8::IsExecutionTerminating());
+ }
+}
+
+
TEST(DebugBreakLoop) {
v8::HandleScope scope;
DebugLocalContext env;
- // Receive 100 breaks and terminate.
- max_break_point_hit_count = 100;
- terminate_after_max_break_point_hit = true;
-
// Register a debug event listener which sets the break flag and counts.
v8::Debug::SetDebugEventListener(DebugEventBreakMax);
- // Function with infinite loop.
- CompileRun("function f() { while (true) { } }");
-
- // Set the debug break to enter the debugger as soon as possible.
- v8::Debug::DebugBreak();
-
- // Call function with infinite loop.
- CompileRun("f();");
- CHECK_EQ(100, break_point_hit_count);
+ CompileRun("var a = 1;");
+ CompileRun("function g() { }");
+ CompileRun("function h() { }");
+
+ const char* loop_bodies[] = {
+ "",
+ "g()",
+ "if (a == 0) { g() }",
+ "if (a == 1) { g() }",
+ "if (a == 0) { g() } else { h() }",
+ "if (a == 0) { continue }",
+ "if (a == 1) { continue }",
+ "switch (a) { case 1: g(); }",
+ "switch (a) { case 1: continue; }",
+ "switch (a) { case 1: g(); break; default: h() }",
+ "switch (a) { case 1: continue; break; default: h() }",
+ NULL
+ };
+
+ TestDebugBreakInLoop("while (true) {", loop_bodies, "}");
+ TestDebugBreakInLoop("while (a == 1) {", loop_bodies, "}");
+
+ TestDebugBreakInLoop("do {", loop_bodies, "} while (true)");
+ TestDebugBreakInLoop("do {", loop_bodies, "} while (a == 1)");
+
+ TestDebugBreakInLoop("for (;;) {", loop_bodies, "}");
+ TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}");
// Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev