15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2011 the V8 project authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Redistribution and use in source and binary forms, with or without
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// modification, are permitted provided that the following conditions are
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// met:
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Redistributions of source code must retain the above copyright
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       notice, this list of conditions and the following disclaimer.
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Redistributions in binary form must reproduce the above
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       copyright notice, this list of conditions and the following
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       disclaimer in the documentation and/or other materials provided
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       with the distribution.
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     * Neither the name of Google Inc. nor the names of its
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       contributors may be used to endorse or promote products derived
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       from this software without specific prior written permission.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flags: --expose-debug-as debug --allow-natives-syntax --turbo-deoptimization
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test tests that deoptimization due to debug breaks works for
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// inlined functions where the full-code is generated before the
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// debugger is attached.
33//
34//See http://code.google.com/p/chromium/issues/detail?id=105375
35
36// Get the Debug object exposed from the debug context global object.
37Debug = debug.Debug;
38
39var count = 0;
40var break_count = 0;
41
42// Debug event listener which sets a breakpoint first time it is hit
43// and otherwise counts break points hit and checks that the expected
44// state is reached.
45function listener(event, exec_state, event_data, data) {
46  if (event == Debug.DebugEvent.Break) {
47    break_count++;
48    if (break_count == 1) {
49      Debug.setBreakPoint(g, 3);
50
51      for (var i = 0; i < exec_state.frameCount(); i++) {
52        var frame = exec_state.frame(i);
53        // When function f is optimized (1 means YES, see runtime.cc) we
54        // expect an optimized frame for f and g.
55        if (%GetOptimizationStatus(f) == 1) {
56          if (i == 1) {
57            assertTrue(frame.isOptimizedFrame());
58            assertTrue(frame.isInlinedFrame());
59            assertEquals(4 - i, frame.inlinedFrameIndex());
60          } else if (i == 2) {
61            assertTrue(frame.isOptimizedFrame());
62            assertFalse(frame.isInlinedFrame());
63          } else {
64            assertFalse(frame.isOptimizedFrame());
65            assertFalse(frame.isInlinedFrame());
66          }
67        }
68      }
69    }
70  }
71}
72
73function f() {
74  g();
75}
76
77function g() {
78  count++;
79  h();
80  var b = 1;  // Break point is set here.
81}
82
83function h() {
84  debugger;
85}
86
87f();f();f();
88%OptimizeFunctionOnNextCall(f);
89f();
90
91// Add the debug event listener.
92Debug.setListener(listener);
93
94f();
95
96assertEquals(5, count);
97assertEquals(2, break_count);
98
99// Get rid of the debug event listener.
100Debug.setListener(null);
101