| OLD | NEW | 
|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // Flags: --allow-natives-syntax --expose-debug-as debug | 5 // Flags: --allow-natives-syntax --expose-debug-as debug | 
| 6 | 6 | 
| 7 Debug = debug.Debug | 7 Debug = debug.Debug | 
| 8 var exception = null; | 8 var exception = null; | 
| 9 var break_count = 0; | 9 var break_count = 0; | 
| 10 var expected_breaks = 7; | 10 var expected_breaks = -1; | 
| 11 | 11 | 
| 12 function listener(event, exec_state, event_data, data) { | 12 function listener(event, exec_state, event_data, data) { | 
| 13   try { | 13   try { | 
| 14     if (event == Debug.DebugEvent.Break) { | 14     if (event == Debug.DebugEvent.Break) { | 
| 15       assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); | 15       assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); | 
|  | 16       if (!break_count) { | 
|  | 17         // Count number of expected breakpoints in this source file. | 
|  | 18         var source_text = exec_state.frame(0).func().script().source(); | 
|  | 19         expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; | 
|  | 20         print("Expected breaks: " + expected_breaks); | 
|  | 21       } | 
| 16       var source = exec_state.frame(0).sourceLineText(); | 22       var source = exec_state.frame(0).sourceLineText(); | 
| 17       print("paused at: " + source); | 23       print("paused at: " + source); | 
| 18       assertTrue(source.indexOf("// Break " + break_count + ".") > 0, | 24       assertTrue(source.indexOf("// Break " + break_count + ".") > 0, | 
| 19                  "Unexpected pause at: " + source); | 25                  "Unexpected pause at: " + source + "\n" + | 
|  | 26                  "Expected: // Break " + break_count + "."); | 
| 20       if (source.indexOf("StepOver.") !== -1) { | 27       if (source.indexOf("StepOver.") !== -1) { | 
| 21         exec_state.prepareStep(Debug.StepAction.StepNext, 1); | 28         exec_state.prepareStep(Debug.StepAction.StepNext, 1); | 
| 22       } else { | 29       } else { | 
| 23         exec_state.prepareStep(Debug.StepAction.StepIn, 1); | 30         exec_state.prepareStep(Debug.StepAction.StepIn, 1); | 
| 24       } | 31       } | 
| 25       ++break_count; | 32       ++break_count; | 
| 26     } else if (event == Debug.DebugEvent.AsyncTaskEvent && |  | 
| 27                event_data.type() === "willHandle" && |  | 
| 28                event_data.name() !== "Object.observe" && |  | 
| 29                break_count > 0) { |  | 
| 30       exec_state.prepareStep(Debug.StepAction.StepIn, 1); |  | 
| 31     } | 33     } | 
| 32   } catch (e) { | 34   } catch (e) { | 
| 33     exception = e; | 35     exception = e; | 
| 34     print(e, e.stack); | 36     print(e, e.stack); | 
| 35   } | 37   } | 
| 36 }; | 38 }; | 
| 37 | 39 | 
| 38 Debug.setListener(listener); | 40 Debug.setListener(listener); | 
| 39 | 41 | 
| 40 Promise.resolve(42) | 42 Promise.resolve(42) | 
| 41   .then(promise1) | 43   .then(promise1) | 
| 42   .then(Object) // Should skip stepping into native. | 44   .then(Object) // Should skip stepping into native. | 
| 43   .then(Boolean) // Should skip stepping into native. | 45   .then(Boolean) // Should skip stepping into native. | 
| 44   .then(promise2) | 46   .then(promise2) | 
| 45   .then(undefined, promise3) | 47   .catch(promise3) | 
| 46   .catch(function(e) { | 48   .catch(function(e) { | 
| 47     %AbortJS("FAIL: uncaught exception " + e); | 49     %AbortJS("FAIL: uncaught exception " + e); | 
| 48   }); | 50   }); | 
| 49 | 51 | 
| 50 function promise1() | 52 function promise1() { | 
| 51 { |  | 
| 52   debugger; // Break 0. | 53   debugger; // Break 0. | 
| 53   return exception || 1; // Break 1. | 54   return exception || 1; // Break 1. | 
| 54 } // Break 2. | 55 } // Break 2. | 
| 55 | 56 | 
| 56 function promise2() | 57 function promise2() { | 
| 57 { |  | 
| 58   throw new Error; // Break 3. | 58   throw new Error; // Break 3. | 
| 59 } | 59 } | 
| 60 | 60 | 
| 61 function promise3() | 61 function promise3() { | 
| 62 { | 62   installObservers(); // Break 4. StepOver. | 
| 63   finalize(); // Break 4. StepOver. |  | 
| 64   return break_count; // Break 5. | 63   return break_count; // Break 5. | 
| 65 } // Break 6. | 64 } // Break 6. | 
| 66 | 65 | 
| 67 function finalize() | 66 function installObservers() { | 
| 68 { | 67   var dummy = {}; | 
|  | 68   Object.observe(dummy, observer1); | 
|  | 69   Object.observe(dummy, Object); // Should skip stepping into native. | 
|  | 70   Object.observe(dummy, Boolean); // Should skip stepping into native. | 
|  | 71   Object.observe(dummy, observer2); | 
|  | 72   dummy.foo = 1; | 
|  | 73 } | 
|  | 74 | 
|  | 75 function observer1() { | 
|  | 76   return exception || 3; // Break 7. | 
|  | 77 } // Break 8. | 
|  | 78 | 
|  | 79 function observer2() { | 
|  | 80   Promise.resolve().then(promise4); // Break 9. StepOver. | 
|  | 81   return break_count + 1; // Break 10. | 
|  | 82 } // Break 11. | 
|  | 83 | 
|  | 84 function promise4() { | 
|  | 85   finalize(); // Break 12. StepOver. | 
|  | 86   return 0; // Break 13. | 
|  | 87 } // Break 14. StepOver. | 
|  | 88 | 
|  | 89 function finalize() { | 
| 69   var dummy = {}; | 90   var dummy = {}; | 
| 70   Object.observe(dummy, function() { | 91   Object.observe(dummy, function() { | 
| 71     if (expected_breaks !== break_count) { | 92     if (expected_breaks !== break_count) { | 
| 72       %AbortJS("FAIL: expected <" + expected_breaks + "> breaks instead of <" + | 93       %AbortJS("FAIL: expected <" + expected_breaks + "> breaks instead of <" + | 
| 73                break_count + ">"); | 94                break_count + ">"); | 
| 74     } | 95     } | 
| 75     if (exception !== null) { | 96     if (exception !== null) { | 
| 76       %AbortJS("FAIL: exception: " + exception); | 97       %AbortJS("FAIL: exception: " + exception); | 
| 77     } | 98     } | 
| 78   }); | 99   }); | 
| 79   dummy.foo = 1; | 100   dummy.foo = 1; | 
| 80 } | 101 } | 
| OLD | NEW | 
|---|