| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 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 | |
| 30 // Test stepping into callbacks passed to builtin functions. | |
| 31 | |
| 32 Debug = debug.Debug | |
| 33 | |
| 34 var exception = null; | |
| 35 | |
| 36 function array_listener(event, exec_state, event_data, data) { | |
| 37 try { | |
| 38 if (event == Debug.DebugEvent.Break) { | |
| 39 print(event_data.sourceLineText(), breaks); | |
| 40 assertTrue(event_data.sourceLineText().indexOf(`B${breaks++}`) > 0); | |
| 41 exec_state.prepareStep(Debug.StepAction.StepIn); | |
| 42 } | |
| 43 } catch (e) { | |
| 44 print(e); | |
| 45 quit(); | |
| 46 exception = e; | |
| 47 } | |
| 48 }; | |
| 49 | |
| 50 function cb_false(num) { | |
| 51 print("element " + num); // B2 B5 B8 | |
| 52 return false; // B3 B6 B9 | |
| 53 } // B4 B7 B10 | |
| 54 | |
| 55 function cb_true(num) { | |
| 56 print("element " + num); // B2 B5 B8 | |
| 57 return true; // B3 B6 B9 | |
| 58 } // B4 B7 B10 | |
| 59 | |
| 60 function cb_reduce(a, b) { | |
| 61 print("elements " + a + " and " + b); // B2 B5 | |
| 62 return a + b; // B3 B6 | |
| 63 } // B4 B7 | |
| 64 | |
| 65 var a = [1, 2, 3]; | |
| 66 | |
| 67 var breaks = 0; | |
| 68 Debug.setListener(array_listener); | |
| 69 debugger; // B0 | |
| 70 a.forEach(cb_true); // B1 | |
| 71 Debug.setListener(null); // B11 | |
| 72 assertNull(exception); | |
| 73 assertEquals(12, breaks); | |
| 74 | |
| 75 breaks = 0; | |
| 76 Debug.setListener(array_listener); | |
| 77 debugger; // B0 | |
| 78 a.some(cb_false); // B1 | |
| 79 Debug.setListener(null); // B11 | |
| 80 assertNull(exception); | |
| 81 assertEquals(12, breaks); | |
| 82 | |
| 83 breaks = 0; | |
| 84 Debug.setListener(array_listener); | |
| 85 debugger; // B0 | |
| 86 a.every(cb_true); // B1 | |
| 87 Debug.setListener(null); // B11 | |
| 88 assertNull(exception); | |
| 89 assertEquals(12, breaks); | |
| 90 | |
| 91 breaks = 0; | |
| 92 Debug.setListener(array_listener); | |
| 93 debugger; // B0 | |
| 94 a.map(cb_true); // B1 | |
| 95 Debug.setListener(null); // B11 | |
| 96 assertNull(exception); | |
| 97 assertEquals(12, breaks); | |
| 98 | |
| 99 breaks = 0; | |
| 100 Debug.setListener(array_listener); | |
| 101 debugger; // B0 | |
| 102 a.filter(cb_true); // B1 | |
| 103 Debug.setListener(null); // B11 | |
| 104 assertNull(exception); | |
| 105 assertEquals(12, breaks); | |
| 106 | |
| 107 breaks = 0; | |
| 108 Debug.setListener(array_listener); | |
| 109 debugger; // B0 | |
| 110 a.reduce(cb_reduce); // B1 | |
| 111 Debug.setListener(null); // B8 | |
| 112 assertNull(exception); | |
| 113 assertEquals(9, breaks); | |
| 114 | |
| 115 breaks = 0; | |
| 116 Debug.setListener(array_listener); | |
| 117 debugger; // B0 | |
| 118 a.reduceRight(cb_reduce); // B1 | |
| 119 Debug.setListener(null); // B8 | |
| 120 assertNull(exception); | |
| 121 assertEquals(9, breaks); | |
| 122 | |
| 123 | |
| 124 // Test two levels of builtin callbacks: | |
| 125 // Array.forEach calls a callback function, which by itself uses | |
| 126 // Array.forEach with another callback function. | |
| 127 | |
| 128 function cb_true_2(num) { | |
| 129 print("element " + num); // B3 B6 B9 B15 B18 B21 B27 B30 B33 | |
| 130 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34 | |
| 131 } // B5 B8 B11 B17 B20 B23 B29 B32 B35 | |
| 132 | |
| 133 function cb_foreach(num) { | |
| 134 a.forEach(cb_true_2); // B2 B14 B20 B26 | |
| 135 print("back."); // B12 B18 B24 B36 | |
| 136 } // B13 B19 B25 B37 | |
| 137 | |
| 138 breaks = 0; | |
| 139 Debug.setListener(array_listener); | |
| 140 debugger; // B0 | |
| 141 a.forEach(cb_foreach); // B1 | |
| 142 Debug.setListener(null); // B38 | |
| 143 assertNull(exception); | |
| 144 assertEquals(39, breaks); | |
| OLD | NEW |