OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --ignition --side-effect-free-debug-evaluate |
| 6 |
| 7 Debug = debug.Debug |
| 8 |
| 9 var exception = null; |
| 10 |
| 11 var o = { p : 1 }; |
| 12 |
| 13 var successes = [ |
| 14 [45, |
| 15 `(function() { |
| 16 var sum = 0; |
| 17 for (var i = 0; i < 10; i++) sum += i; |
| 18 return sum; |
| 19 })()` |
| 20 ], |
| 21 ["0012", |
| 22 `(function() { |
| 23 var sum = 0; |
| 24 for (var i in [1, 2, 3]) sum += i; |
| 25 return sum; |
| 26 })()` |
| 27 ], |
| 28 [15, |
| 29 `(function() { |
| 30 var sum = 1; |
| 31 while (sum < 12) sum += sum + 1; |
| 32 return sum; |
| 33 })()` |
| 34 ], |
| 35 [15, |
| 36 `(function() { |
| 37 var sum = 1; |
| 38 do { sum += sum + 1; } while (sum < 12); |
| 39 return sum; |
| 40 })()` |
| 41 ], |
| 42 ["023", |
| 43 `(function() { |
| 44 var sum = ""; |
| 45 for (var i = 0; i < 4; i++) { |
| 46 switch (i) { |
| 47 case 0: |
| 48 case 1: |
| 49 if (i == 0) sum += i; |
| 50 break; |
| 51 default: |
| 52 case 3: |
| 53 sum += i; |
| 54 break; |
| 55 } |
| 56 } |
| 57 return sum; |
| 58 })()` |
| 59 ], |
| 60 ["oups", |
| 61 `(function() { |
| 62 try { |
| 63 if (Math.sin(1) < 1) throw new Error("oups"); |
| 64 } catch (e) { |
| 65 return e.message; |
| 66 } |
| 67 })()` |
| 68 ], |
| 69 ]; |
| 70 |
| 71 var fails = [ |
| 72 `(function() { // Iterator.prototype.next performs stores. |
| 73 var sum = 0; |
| 74 for (let i of [1, 2, 3]) sum += i; |
| 75 return sum; |
| 76 })()`, |
| 77 `(function() { // Store to scope object. |
| 78 with (o) { |
| 79 p = 2; |
| 80 } |
| 81 })()`, |
| 82 ]; |
| 83 |
| 84 function listener(event, exec_state, event_data, data) { |
| 85 if (event != Debug.DebugEvent.Break) return; |
| 86 try { |
| 87 successes.forEach(function ([expectation, source]) { |
| 88 assertEquals(expectation, exec_state.frame(0).evaluate(source).value()); |
| 89 }); |
| 90 fails.forEach(function (test) { |
| 91 assertThrows(() => exec_state.frame(0).evaluate(test), EvalError); |
| 92 }); |
| 93 } catch (e) { |
| 94 exception = e; |
| 95 print(e, e.stack); |
| 96 }; |
| 97 }; |
| 98 |
| 99 // Add the debug event listener. |
| 100 Debug.setListener(listener); |
| 101 |
| 102 function f() { |
| 103 debugger; |
| 104 }; |
| 105 |
| 106 f(); |
| 107 |
| 108 assertNull(exception); |
OLD | NEW |