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