@@ -35,7 +35,8 @@ function Point(x, y) {
35
35
36
36
Point . prototype . distanceTo = function ( p ) {
37
37
debugger ;
38
- return Math . sqrt ( Math . pow ( Math . abs ( this . x - p . x ) , 2 ) + Math . pow ( Math . abs ( this . y - p . y ) , 2 ) )
38
+ return Math . sqrt ( Math . pow ( Math . abs ( this . x - p . x ) , 2 ) +
39
+ Math . pow ( Math . abs ( this . y - p . y ) , 2 ) )
39
40
}
40
41
41
42
p1 = new Point ( 1 , 1 ) ;
@@ -58,7 +59,7 @@ a=[1,2,distance];
58
59
// Get the Debug object exposed from the debug context global object.
59
60
Debug = debug . Debug
60
61
61
- testConstructor = false ; // Flag to control which part of the test is run.
62
+ what = 'constructor' ; // Flag to control which part of the test is run.
62
63
listenerCalled = false ;
63
64
exception = false ;
64
65
@@ -72,30 +73,47 @@ function safeEval(code) {
72
73
73
74
function listener ( event , exec_state , event_data , data ) {
74
75
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]
83
- 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 ( ) ) ;
86
- 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 ;
76
+ if ( event == Debug . DebugEvent . Break ) {
77
+ if ( what == 'constructor' ) {
78
+ // The expected backtrace is
79
+ // 0: Call distance on Point where distance is a prototype property
80
+ // 1: Call distance on Point where distance is a direct property
81
+ // 2: Call on function an array element 2
82
+ // 3: [anonymous]
83
+ assertEquals ( "#<Point>.distanceTo(p=#<Point>)" ,
84
+ exec_state . frame ( 0 ) . invocationText ( ) ) ;
85
+ assertEquals ( "#<Point>.distanceTo(p=#<Point>)" ,
86
+ exec_state . frame ( 1 ) . invocationText ( ) ) ;
87
+ assertEquals ( "#<Array>[2](aka distance)(p=#<Point>, q=#<Point>)" ,
88
+ exec_state . frame ( 2 ) . invocationText ( ) ) ;
89
+ assertEquals ( "[anonymous]()" , exec_state . frame ( 3 ) . invocationText ( ) ) ;
90
+ listenerCalled = true ;
91
+ } else if ( what == 'breakpoint' ) {
92
+ // The expected backtrace is
93
+ // 0: Call Point constructor
94
+ // 1: Call on global function createPoint
95
+ // 2: [anonymous]
96
+ assertEquals ( "new Point(x=0, y=0)" ,
97
+ exec_state . frame ( 0 ) . invocationText ( ) ) ;
98
+ assertEquals ( "createPoint(x=0, y=0)" ,
99
+ exec_state . frame ( 1 ) . invocationText ( ) ) ;
100
+ assertEquals ( "[anonymous]()" , exec_state . frame ( 2 ) . invocationText ( ) ) ;
101
+ listenerCalled = true ;
102
+ } else if ( what == 'symbol' ) {
103
+ // The expected backtrace is
104
+ // 0: Call Point constructor
105
+ // 1: Call on symbol method
106
+ // 2: [anonymous]
107
+ assertEquals ( "new Point(x=0, y=0)" ,
108
+ exec_state . frame ( 0 ) . invocationText ( ) ) ;
109
+ assertEquals ( "#<Object>[Symbol(Das Symbol)](x=0, y=0)" ,
110
+ exec_state . frame ( 1 ) . invocationText ( ) ) ;
111
+ assertEquals ( "[anonymous]()" , exec_state . frame ( 2 ) . invocationText ( ) ) ;
112
+ listenerCalled = true ;
113
+ } else {
114
+ assertUnreachable ( ) ;
115
+ }
97
116
}
98
- }
99
117
} catch ( e ) {
100
118
exception = e
101
119
} ;
@@ -112,11 +130,21 @@ assertTrue(listenerCalled);
112
130
assertFalse ( exception , "exception in listener" )
113
131
114
132
// Set a break point and call to invoke the debug event listener.
133
+ what = 'breakpoint' ;
115
134
listenerCalled = false ;
116
- testConstructor = true ;
117
135
Debug . setBreakPoint ( Point , 0 , 0 ) ;
118
136
createPoint ( 0 , 0 ) ;
119
137
120
138
// Make sure that the debug event listener vas invoked (again).
121
139
assertTrue ( listenerCalled ) ;
122
140
assertFalse ( exception , "exception in listener" )
141
+
142
+ what = 'symbol' ;
143
+ listenerCalled = false ;
144
+ var S = Symbol ( 'Das Symbol' ) ;
145
+ var o = { [ S ] ( x , y ) { return new Point ( x , y ) ; } } ;
146
+ Debug . setBreakPoint ( Point , 0 , 0 ) ;
147
+ o [ S ] ( 0 , 0 ) ;
148
+
149
+ assertTrue ( listenerCalled ) ;
150
+ assertFalse ( exception , "exception in listener" )
0 commit comments