| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
| 30 Debug = debug.Debug | 30 Debug = debug.Debug |
| 31 Debug.setListener(function(){}); | 31 Debug.setListener(function(){}); |
| 32 | 32 |
| 33 var script_id; |
| 34 var script_name; |
| 35 |
| 36 // Get current script id and name. |
| 37 var scripts = Debug.scripts(); |
| 38 for (var i = 0; i < scripts.length; i++) { |
| 39 var name = scripts[i].name; |
| 40 var id = scripts[i].id; |
| 41 if (name !== undefined && name.includes("debug-script-breakpoints.js")) { |
| 42 script_id = id; |
| 43 script_name = name; |
| 44 break; |
| 45 } |
| 46 } |
| 47 assertTrue(script_id !== undefined); |
| 48 assertTrue(script_name !== undefined); |
| 49 print("#" + script_id + ": " + script_name); |
| 50 |
| 51 |
| 52 // Checks script name, line and column. |
| 53 var checkBreakPoint = function(id, line, column) { |
| 54 var breakpoint = Debug.scriptBreakPoints()[id]; |
| 55 assertEquals(script_name, breakpoint.script_name()); |
| 56 assertEquals(line, breakpoint.line()); |
| 57 assertEquals(column, breakpoint.column()); |
| 58 } |
| 59 |
| 60 |
| 33 // Set and remove a script break point for a named script. | 61 // Set and remove a script break point for a named script. |
| 34 var sbp = Debug.setScriptBreakPointByName("1", 2, 3); | 62 var sbp = Debug.setScriptBreakPointByName(script_name, 35, 5); |
| 35 assertEquals(1, Debug.scriptBreakPoints().length); | 63 assertEquals(1, Debug.scriptBreakPoints().length); |
| 36 assertEquals("1", Debug.scriptBreakPoints()[0].script_name()); | 64 checkBreakPoint(0, 35, 5); |
| 37 assertEquals(2, Debug.scriptBreakPoints()[0].line()); | |
| 38 assertEquals(3, Debug.scriptBreakPoints()[0].column()); | |
| 39 Debug.clearBreakPoint(sbp); | 65 Debug.clearBreakPoint(sbp); |
| 40 assertEquals(0, Debug.scriptBreakPoints().length); | 66 assertEquals(0, Debug.scriptBreakPoints().length); |
| 41 | 67 |
| 42 // Set three script break points for named scripts. | 68 // Set three script break points for named scripts. |
| 43 var sbp1 = Debug.setScriptBreakPointByName("1", 2, 3); | 69 var sbp1 = Debug.setScriptBreakPointByName(script_name, 36, 3); |
| 44 var sbp2 = Debug.setScriptBreakPointByName("2", 3, 4); | 70 var sbp2 = Debug.setScriptBreakPointByName(script_name, 37, 4); |
| 45 var sbp3 = Debug.setScriptBreakPointByName("3", 4, 5); | 71 var sbp3 = Debug.setScriptBreakPointByName(script_name, 38, 5); |
| 46 | 72 |
| 47 // Check the content of the script break points. | 73 // Check the content of the script break points. |
| 48 assertEquals(3, Debug.scriptBreakPoints().length); | 74 assertEquals(3, Debug.scriptBreakPoints().length); |
| 49 for (var i = 0; i < Debug.scriptBreakPoints().length; i++) { | 75 checkBreakPoint(0, 36, 3); |
| 50 var x = Debug.scriptBreakPoints()[i]; | 76 checkBreakPoint(1, 37, 4); |
| 51 if ("1" == x.script_name()) { | 77 checkBreakPoint(2, 38, 5); |
| 52 assertEquals(2, x.line()); | |
| 53 assertEquals(3, x.column()); | |
| 54 } else if ("2" == x.script_name()) { | |
| 55 assertEquals(3, x.line()); | |
| 56 assertEquals(4, x.column()); | |
| 57 } else if ("3" == x.script_name()) { | |
| 58 assertEquals(4, x.line()); | |
| 59 assertEquals(5, x.column()); | |
| 60 } else { | |
| 61 assertUnreachable("unecpected script_name " + x.script_name()); | |
| 62 } | |
| 63 } | |
| 64 | 78 |
| 65 // Remove script break points (in another order than they where added). | 79 // Remove script break points (in another order than they where added). |
| 66 assertEquals(3, Debug.scriptBreakPoints().length); | 80 assertEquals(3, Debug.scriptBreakPoints().length); |
| 67 Debug.clearBreakPoint(sbp1); | 81 Debug.clearBreakPoint(sbp1); |
| 68 assertEquals(2, Debug.scriptBreakPoints().length); | 82 assertEquals(2, Debug.scriptBreakPoints().length); |
| 69 Debug.clearBreakPoint(sbp3); | 83 Debug.clearBreakPoint(sbp3); |
| 70 assertEquals(1, Debug.scriptBreakPoints().length); | 84 assertEquals(1, Debug.scriptBreakPoints().length); |
| 71 Debug.clearBreakPoint(sbp2); | 85 Debug.clearBreakPoint(sbp2); |
| 72 assertEquals(0, Debug.scriptBreakPoints().length); | 86 assertEquals(0, Debug.scriptBreakPoints().length); |
| 73 | 87 |
| 88 |
| 89 // Checks script id, line and column. |
| 90 var checkBreakPoint = function(id, line, column) { |
| 91 var breakpoint = Debug.scriptBreakPoints()[id]; |
| 92 assertEquals(script_id, breakpoint.script_id()); |
| 93 assertEquals(line, breakpoint.line()); |
| 94 assertEquals(column, breakpoint.column()); |
| 95 } |
| 96 |
| 97 |
| 74 // Set and remove a script break point for a script id. | 98 // Set and remove a script break point for a script id. |
| 75 var sbp = Debug.setScriptBreakPointById(1, 2, 3); | 99 var sbp = Debug.setScriptBreakPointById(script_id, 40, 6); |
| 76 assertEquals(1, Debug.scriptBreakPoints().length); | 100 assertEquals(1, Debug.scriptBreakPoints().length); |
| 77 assertEquals(1, Debug.scriptBreakPoints()[0].script_id()); | 101 checkBreakPoint(0, 40, 6); |
| 78 assertEquals(2, Debug.scriptBreakPoints()[0].line()); | |
| 79 assertEquals(3, Debug.scriptBreakPoints()[0].column()); | |
| 80 Debug.clearBreakPoint(sbp); | 102 Debug.clearBreakPoint(sbp); |
| 81 assertEquals(0, Debug.scriptBreakPoints().length); | 103 assertEquals(0, Debug.scriptBreakPoints().length); |
| 82 | 104 |
| 83 // Set three script break points for script ids. | 105 // Set three script break points for script ids. |
| 84 var sbp1 = Debug.setScriptBreakPointById(1, 2, 3); | 106 var sbp1 = Debug.setScriptBreakPointById(script_id, 42, 3); |
| 85 var sbp2 = Debug.setScriptBreakPointById(2, 3, 4); | 107 var sbp2 = Debug.setScriptBreakPointById(script_id, 43, 4); |
| 86 var sbp3 = Debug.setScriptBreakPointById(3, 4, 5); | 108 var sbp3 = Debug.setScriptBreakPointById(script_id, 44, 5); |
| 87 | 109 |
| 88 // Check the content of the script break points. | 110 // Check the content of the script break points. |
| 89 assertEquals(3, Debug.scriptBreakPoints().length); | 111 assertEquals(3, Debug.scriptBreakPoints().length); |
| 90 for (var i = 0; i < Debug.scriptBreakPoints().length; i++) { | 112 checkBreakPoint(0, 42, 3); |
| 91 var x = Debug.scriptBreakPoints()[i]; | 113 checkBreakPoint(1, 43, 4); |
| 92 if (1 == x.script_id()) { | 114 checkBreakPoint(2, 44, 5); |
| 93 assertEquals(2, x.line()); | |
| 94 assertEquals(3, x.column()); | |
| 95 } else if (2 == x.script_id()) { | |
| 96 assertEquals(3, x.line()); | |
| 97 assertEquals(4, x.column()); | |
| 98 } else if (3 == x.script_id()) { | |
| 99 assertEquals(4, x.line()); | |
| 100 assertEquals(5, x.column()); | |
| 101 } else { | |
| 102 assertUnreachable("unecpected script_id " + x.script_id()); | |
| 103 } | |
| 104 } | |
| 105 | 115 |
| 106 // Remove script break points (in another order than they where added). | 116 // Remove script break points (in another order than they where added). |
| 107 assertEquals(3, Debug.scriptBreakPoints().length); | 117 assertEquals(3, Debug.scriptBreakPoints().length); |
| 108 Debug.clearBreakPoint(sbp1); | 118 Debug.clearBreakPoint(sbp1); |
| 109 assertEquals(2, Debug.scriptBreakPoints().length); | 119 assertEquals(2, Debug.scriptBreakPoints().length); |
| 110 Debug.clearBreakPoint(sbp3); | 120 Debug.clearBreakPoint(sbp3); |
| 111 assertEquals(1, Debug.scriptBreakPoints().length); | 121 assertEquals(1, Debug.scriptBreakPoints().length); |
| 112 Debug.clearBreakPoint(sbp2); | 122 Debug.clearBreakPoint(sbp2); |
| 113 assertEquals(0, Debug.scriptBreakPoints().length); | 123 assertEquals(0, Debug.scriptBreakPoints().length); |
| 114 | 124 |
| 115 Debug.setListener(null); | 125 Debug.setListener(null); |
| OLD | NEW |