13ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Copyright 2012 the V8 project authors. All rights reserved. 21e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// Redistribution and use in source and binary forms, with or without 31e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// modification, are permitted provided that the following conditions are 41e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// met: 51e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 61e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions of source code must retain the above copyright 71e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// notice, this list of conditions and the following disclaimer. 81e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions in binary form must reproduce the above 91e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// copyright notice, this list of conditions and the following 101e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// disclaimer in the documentation and/or other materials provided 111e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// with the distribution. 121e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Neither the name of Google Inc. nor the names of its 131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// contributors may be used to endorse or promote products derived 141e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// from this software without specific prior written permission. 151e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 161e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 283ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Flags: --expose-debug-as debug 291e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 303ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Test that the break point is set before initializing the loop variable 313ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// so that we break before any iteration has been run. 32e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch 333ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochDebug = debug.Debug; 343fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 353ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar break_hit = false; 363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 373ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochfunction listener(event, exec_state, event_data, data) { 383ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch if (event == Debug.DebugEvent.Break) { 393ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch break_hit = true; 403ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch } 413ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch} 423ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 433ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochDebug.setListener(listener); 443ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 453ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochfunction test() { 463ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch for (var i = 0; i < 3; i++) { // Break here. 473ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch if (i == 0) break; 483ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch } 493ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch} 503ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 513ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochDebug.setBreakPoint(test, 1, 0); 523ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 533ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertTrue(Debug.showBreakPoints(test).indexOf("// Break here.") >= 0); 543ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 553ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochtest(); 563ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 573ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertTrue(break_hit); 58