blob: 61648fa4e2e6ee4e8554556db02e18acd93fe0b1 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2008 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028// Flags: --expose-debug-as debug
Steve Blocka7e24c12009-10-30 11:49:00 +000029
30// The functions used for testing backtraces.
31function Point(x, y) {
32 this.x = x;
33 this.y = y;
34};
35
36Point.prototype.distanceTo = function(p) {
37 debugger;
38 return Math.sqrt(Math.pow(Math.abs(this.x - p.x), 2) + Math.pow(Math.abs(this.y - p.y), 2))
39}
40
41p1 = new Point(1,1);
42p2 = new Point(2,2);
43
44p1.distanceTo = function(p) {
45 return p.distanceTo(this);
46}
47
48function distance(p, q) {
49 return p.distanceTo(q);
50}
51
52function createPoint(x, y) {
53 return new Point(x, y);
54}
55
56a=[1,2,distance];
57
58// Get the Debug object exposed from the debug context global object.
59Debug = debug.Debug
60
61testConstructor = false; // Flag to control which part of the test is run.
62listenerCalled = false;
63exception = false;
64
65function safeEval(code) {
66 try {
67 return eval('(' + code + ')');
68 } catch (e) {
69 return undefined;
70 }
71}
72
73function listener(event, exec_state, event_data, data) {
74 try {
75 if (event == Debug.DebugEvent.Break)
76 {
77 if (!testConstructor) {
78 // The expected backtrace is
79 // 0: Call distance on Point where distance is a property on the prototype
80 // 1: Call distance on Point where distance is a direct property
81 // 2: Call on function an array element 2
82 // 3: [anonymous]
Steve Block1e0659c2011-05-24 12:43:12 +010083 assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(0).invocationText());
84 assertEquals("#<Point>.distanceTo(p=#<Point>)", exec_state.frame(1).invocationText());
85 assertEquals("#<Array>[2](aka distance)(p=#<Point>, q=#<Point>)", exec_state.frame(2).invocationText());
Steve Blocka7e24c12009-10-30 11:49:00 +000086 assertEquals("[anonymous]()", exec_state.frame(3).invocationText());
87 listenerCalled = true;
88 } else {
89 // The expected backtrace is
90 // 0: Call Point constructor
91 // 1: Call on global function createPoint
92 // 2: [anonymous]
93 assertEquals("new Point(x=0, y=0)", exec_state.frame(0).invocationText());
94 assertEquals("createPoint(x=0, y=0)", exec_state.frame(1).invocationText());
95 assertEquals("[anonymous]()", exec_state.frame(2).invocationText());
96 listenerCalled = true;
97 }
98 }
99 } catch (e) {
100 exception = e
101 };
102};
103
104// Add the debug event listener.
105Debug.setListener(listener);
106
107// Set a break point and call to invoke the debug event listener.
108a[2](p1, p2)
109
110// Make sure that the debug event listener vas invoked.
111assertTrue(listenerCalled);
112assertFalse(exception, "exception in listener")
113
114// Set a break point and call to invoke the debug event listener.
115listenerCalled = false;
116testConstructor = true;
117Debug.setBreakPoint(Point, 0, 0);
118createPoint(0, 0);
119
120// Make sure that the debug event listener vas invoked (again).
121assertTrue(listenerCalled);
122assertFalse(exception, "exception in listener")