1 // Copyright 2008 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 // Flags: --expose-debug-as debug 29 // Get the Debug object exposed from the debug context global object. 30 Debug = debug.Debug 31 32 // Set and remove a script break point for a named script. 33 var sbp = Debug.setScriptBreakPointByName("1", 2, 3); 34 assertEquals(1, Debug.scriptBreakPoints().length); 35 assertEquals("1", Debug.scriptBreakPoints()[0].script_name()); 36 assertEquals(2, Debug.scriptBreakPoints()[0].line()); 37 assertEquals(3, Debug.scriptBreakPoints()[0].column()); 38 Debug.clearBreakPoint(sbp); 39 assertEquals(0, Debug.scriptBreakPoints().length); 40 41 // Set three script break points for named scripts. 42 var sbp1 = Debug.setScriptBreakPointByName("1", 2, 3); 43 var sbp2 = Debug.setScriptBreakPointByName("2", 3, 4); 44 var sbp3 = Debug.setScriptBreakPointByName("3", 4, 5); 45 46 // Check the content of the script break points. 47 assertEquals(3, Debug.scriptBreakPoints().length); 48 for (var i = 0; i < Debug.scriptBreakPoints().length; i++) { 49 var x = Debug.scriptBreakPoints()[i]; 50 if ("1" == x.script_name()) { 51 assertEquals(2, x.line()); 52 assertEquals(3, x.column()); 53 } else if ("2" == x.script_name()) { 54 assertEquals(3, x.line()); 55 assertEquals(4, x.column()); 56 } else if ("3" == x.script_name()) { 57 assertEquals(4, x.line()); 58 assertEquals(5, x.column()); 59 } else { 60 assertUnreachable("unecpected script_name " + x.script_name()); 61 } 62 } 63 64 // Remove script break points (in another order than they where added). 65 assertEquals(3, Debug.scriptBreakPoints().length); 66 Debug.clearBreakPoint(sbp1); 67 assertEquals(2, Debug.scriptBreakPoints().length); 68 Debug.clearBreakPoint(sbp3); 69 assertEquals(1, Debug.scriptBreakPoints().length); 70 Debug.clearBreakPoint(sbp2); 71 assertEquals(0, Debug.scriptBreakPoints().length); 72 73 // Set and remove a script break point for a script id. 74 var sbp = Debug.setScriptBreakPointById(1, 2, 3); 75 assertEquals(1, Debug.scriptBreakPoints().length); 76 assertEquals(1, Debug.scriptBreakPoints()[0].script_id()); 77 assertEquals(2, Debug.scriptBreakPoints()[0].line()); 78 assertEquals(3, Debug.scriptBreakPoints()[0].column()); 79 Debug.clearBreakPoint(sbp); 80 assertEquals(0, Debug.scriptBreakPoints().length); 81 82 // Set three script break points for script ids. 83 var sbp1 = Debug.setScriptBreakPointById(1, 2, 3); 84 var sbp2 = Debug.setScriptBreakPointById(2, 3, 4); 85 var sbp3 = Debug.setScriptBreakPointById(3, 4, 5); 86 87 // Check the content of the script break points. 88 assertEquals(3, Debug.scriptBreakPoints().length); 89 for (var i = 0; i < Debug.scriptBreakPoints().length; i++) { 90 var x = Debug.scriptBreakPoints()[i]; 91 if (1 == x.script_id()) { 92 assertEquals(2, x.line()); 93 assertEquals(3, x.column()); 94 } else if (2 == x.script_id()) { 95 assertEquals(3, x.line()); 96 assertEquals(4, x.column()); 97 } else if (3 == x.script_id()) { 98 assertEquals(4, x.line()); 99 assertEquals(5, x.column()); 100 } else { 101 assertUnreachable("unecpected script_id " + x.script_id()); 102 } 103 } 104 105 // Remove script break points (in another order than they where added). 106 assertEquals(3, Debug.scriptBreakPoints().length); 107 Debug.clearBreakPoint(sbp1); 108 assertEquals(2, Debug.scriptBreakPoints().length); 109 Debug.clearBreakPoint(sbp3); 110 assertEquals(1, Debug.scriptBreakPoints().length); 111 Debug.clearBreakPoint(sbp2); 112 assertEquals(0, Debug.scriptBreakPoints().length); 113