Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 28 | // Flags: --expose-debug-as debug --allow-natives-syntax |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | // The functions used for testing backtraces. They are at the top to make the |
| 30 | // testing of source line/column easier. |
| 31 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | // Get the Debug object exposed from the debug context global object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 33 | var Debug = debug.Debug; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 35 | var test_name; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | var listener_delegate; |
| 37 | var listener_called; |
| 38 | var exception; |
| 39 | var begin_test_count = 0; |
| 40 | var end_test_count = 0; |
| 41 | var break_count = 0; |
| 42 | |
| 43 | |
| 44 | // Debug event listener which delegates. |
| 45 | function listener(event, exec_state, event_data, data) { |
| 46 | try { |
| 47 | if (event == Debug.DebugEvent.Break) { |
| 48 | break_count++; |
| 49 | listener_called = true; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 50 | listener_delegate(exec_state); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 51 | } |
| 52 | } catch (e) { |
| 53 | exception = e; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Add the debug event listener. |
| 58 | Debug.setListener(listener); |
| 59 | |
| 60 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 61 | // Initialize for a new test. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 62 | function BeginTest(name) { |
| 63 | test_name = name; |
| 64 | listener_delegate = null; |
| 65 | listener_called = false; |
| 66 | exception = null; |
| 67 | begin_test_count++; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | // Check result of a test. |
| 72 | function EndTest() { |
| 73 | assertTrue(listener_called, "listerner not called for " + test_name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | assertNull(exception, test_name + " / " + exception); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 75 | end_test_count++; |
| 76 | } |
| 77 | |
| 78 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | // Check that two scope are the same. |
| 80 | function assertScopeMirrorEquals(scope1, scope2) { |
| 81 | assertEquals(scope1.scopeType(), scope2.scopeType()); |
| 82 | assertEquals(scope1.frameIndex(), scope2.frameIndex()); |
| 83 | assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); |
| 84 | assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value()); |
| 85 | } |
| 86 | |
| 87 | function CheckFastAllScopes(scopes, exec_state) |
| 88 | { |
| 89 | var fast_all_scopes = exec_state.frame().allScopes(true); |
| 90 | var length = fast_all_scopes.length; |
| 91 | assertTrue(scopes.length >= length); |
| 92 | for (var i = 0; i < scopes.length && i < length; i++) { |
| 93 | var scope = fast_all_scopes[length - i - 1]; |
| 94 | assertTrue(scope.isScope()); |
| 95 | assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 100 | // Check that the scope chain contains the expected types of scopes. |
| 101 | function CheckScopeChain(scopes, exec_state) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 102 | var all_scopes = exec_state.frame().allScopes(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 103 | assertEquals(scopes.length, exec_state.frame().scopeCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 104 | assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | for (var i = 0; i < scopes.length; i++) { |
| 106 | var scope = exec_state.frame().scope(i); |
| 107 | assertTrue(scope.isScope()); |
| 108 | assertEquals(scopes[i], scope.scopeType()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | assertScopeMirrorEquals(all_scopes[i], scope); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 110 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | // Check the global object when hitting the global scope. |
| 112 | if (scopes[i] == debug.ScopeType.Global) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 113 | // Objects don't have same class (one is "global", other is "Object", |
| 114 | // so just check the properties directly. |
| 115 | assertPropertiesEqual(this, scope.scopeObject().value()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | CheckFastAllScopes(scopes, exec_state); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 119 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 120 | // Get the debug command processor. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 121 | var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 122 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | // Send a scopes request and check the result. |
| 124 | var json; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 125 | var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 126 | var response_json = dcp.processDebugJSONRequest(request_json); |
| 127 | var response = JSON.parse(response_json); |
| 128 | assertEquals(scopes.length, response.body.scopes.length); |
| 129 | for (var i = 0; i < scopes.length; i++) { |
| 130 | assertEquals(i, response.body.scopes[i].index); |
| 131 | assertEquals(scopes[i], response.body.scopes[i].type); |
| 132 | if (scopes[i] == debug.ScopeType.Local || |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 133 | scopes[i] == debug.ScopeType.Script || |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 134 | scopes[i] == debug.ScopeType.Closure) { |
| 135 | assertTrue(response.body.scopes[i].object.ref < 0); |
| 136 | } else { |
| 137 | assertTrue(response.body.scopes[i].object.ref >= 0); |
| 138 | } |
| 139 | var found = false; |
| 140 | for (var j = 0; j < response.refs.length && !found; j++) { |
| 141 | found = response.refs[j].handle == response.body.scopes[i].object.ref; |
| 142 | } |
| 143 | assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " not found"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 148 | // Check that the scope chain contains the expected names of scopes. |
| 149 | function CheckScopeChainNames(names, exec_state) { |
| 150 | var all_scopes = exec_state.frame().allScopes(); |
| 151 | assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); |
| 152 | for (var i = 0; i < names.length; i++) { |
| 153 | var scope = exec_state.frame().scope(i); |
| 154 | assertTrue(scope.isScope()); |
| 155 | assertEquals(scope.details().name(), names[i]) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 160 | // Check that the content of the scope is as expected. For functions just check |
| 161 | // that there is a function. |
| 162 | function CheckScopeContent(content, number, exec_state) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 163 | var scope = exec_state.frame().scope(number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | var count = 0; |
| 165 | for (var p in content) { |
| 166 | var property_mirror = scope.scopeObject().property(p); |
| 167 | assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in scope'); |
| 168 | if (typeof(content[p]) === 'function') { |
| 169 | assertTrue(property_mirror.value().isFunction()); |
| 170 | } else { |
| 171 | assertEquals(content[p], property_mirror.value().value(), 'property ' + p + ' has unexpected value'); |
| 172 | } |
| 173 | count++; |
| 174 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 175 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | // 'arguments' and might be exposed in the local and closure scope. Just |
| 177 | // ignore this. |
| 178 | var scope_size = scope.scopeObject().properties().length; |
| 179 | if (!scope.scopeObject().property('arguments').isUndefined()) { |
| 180 | scope_size--; |
| 181 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 182 | // Ditto for 'this'. |
| 183 | if (!scope.scopeObject().property('this').isUndefined()) { |
| 184 | scope_size--; |
| 185 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 186 | // Skip property with empty name. |
| 187 | if (!scope.scopeObject().property('').isUndefined()) { |
| 188 | scope_size--; |
| 189 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 190 | |
| 191 | if (count != scope_size) { |
| 192 | print('Names found in scope:'); |
| 193 | var names = scope.scopeObject().propertyNames(); |
| 194 | for (var i = 0; i < names.length; i++) { |
| 195 | print(names[i]); |
| 196 | } |
| 197 | } |
| 198 | assertEquals(count, scope_size); |
| 199 | |
| 200 | // Get the debug command processor. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 201 | var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 202 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 203 | // Send a scope request for information on a single scope and check the |
| 204 | // result. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 205 | var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"number":'; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 206 | request_json += scope.scopeIndex(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 207 | request_json += '}}'; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 208 | var response_json = dcp.processDebugJSONRequest(request_json); |
| 209 | var response = JSON.parse(response_json); |
| 210 | assertEquals(scope.scopeType(), response.body.type); |
| 211 | assertEquals(number, response.body.index); |
| 212 | if (scope.scopeType() == debug.ScopeType.Local || |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 213 | scope.scopeType() == debug.ScopeType.Script || |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | scope.scopeType() == debug.ScopeType.Closure) { |
| 215 | assertTrue(response.body.object.ref < 0); |
| 216 | } else { |
| 217 | assertTrue(response.body.object.ref >= 0); |
| 218 | } |
| 219 | var found = false; |
| 220 | for (var i = 0; i < response.refs.length && !found; i++) { |
| 221 | found = response.refs[i].handle == response.body.object.ref; |
| 222 | } |
| 223 | assertTrue(found, "Scope object " + response.body.object.ref + " not found"); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | // Simple empty local scope. |
| 228 | BeginTest("Local 1"); |
| 229 | |
| 230 | function local_1() { |
| 231 | debugger; |
| 232 | } |
| 233 | |
| 234 | listener_delegate = function(exec_state) { |
| 235 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 236 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 237 | debug.ScopeType.Global], exec_state); |
| 238 | CheckScopeContent({}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 239 | }; |
| 240 | local_1(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | EndTest(); |
| 242 | |
| 243 | |
| 244 | // Local scope with a parameter. |
| 245 | BeginTest("Local 2"); |
| 246 | |
| 247 | function local_2(a) { |
| 248 | debugger; |
| 249 | } |
| 250 | |
| 251 | listener_delegate = function(exec_state) { |
| 252 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 253 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 254 | debug.ScopeType.Global], exec_state); |
| 255 | CheckScopeContent({a:1}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 256 | }; |
| 257 | local_2(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | EndTest(); |
| 259 | |
| 260 | |
| 261 | // Local scope with a parameter and a local variable. |
| 262 | BeginTest("Local 3"); |
| 263 | |
| 264 | function local_3(a) { |
| 265 | var x = 3; |
| 266 | debugger; |
| 267 | } |
| 268 | |
| 269 | listener_delegate = function(exec_state) { |
| 270 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 271 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 272 | debug.ScopeType.Global], exec_state); |
| 273 | CheckScopeContent({a:1,x:3}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 274 | }; |
| 275 | local_3(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 276 | EndTest(); |
| 277 | |
| 278 | |
| 279 | // Local scope with parameters and local variables. |
| 280 | BeginTest("Local 4"); |
| 281 | |
| 282 | function local_4(a, b) { |
| 283 | var x = 3; |
| 284 | var y = 4; |
| 285 | debugger; |
| 286 | } |
| 287 | |
| 288 | listener_delegate = function(exec_state) { |
| 289 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 290 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 291 | debug.ScopeType.Global], exec_state); |
| 292 | CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 293 | }; |
| 294 | local_4(1, 2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | EndTest(); |
| 296 | |
| 297 | |
| 298 | // Empty local scope with use of eval. |
| 299 | BeginTest("Local 5"); |
| 300 | |
| 301 | function local_5() { |
| 302 | eval(''); |
| 303 | debugger; |
| 304 | } |
| 305 | |
| 306 | listener_delegate = function(exec_state) { |
| 307 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 308 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 309 | debug.ScopeType.Global], exec_state); |
| 310 | CheckScopeContent({}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 311 | }; |
| 312 | local_5(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | EndTest(); |
| 314 | |
| 315 | |
| 316 | // Local introducing local variable using eval. |
| 317 | BeginTest("Local 6"); |
| 318 | |
| 319 | function local_6() { |
| 320 | eval('var i = 5'); |
| 321 | debugger; |
| 322 | } |
| 323 | |
| 324 | listener_delegate = function(exec_state) { |
| 325 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 326 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | debug.ScopeType.Global], exec_state); |
| 328 | CheckScopeContent({i:5}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 329 | }; |
| 330 | local_6(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 331 | EndTest(); |
| 332 | |
| 333 | |
| 334 | // Local scope with parameters, local variables and local variable introduced |
| 335 | // using eval. |
| 336 | BeginTest("Local 7"); |
| 337 | |
| 338 | function local_7(a, b) { |
| 339 | var x = 3; |
| 340 | var y = 4; |
| 341 | eval('var i = 5'); |
| 342 | eval('var j = 6'); |
| 343 | debugger; |
| 344 | } |
| 345 | |
| 346 | listener_delegate = function(exec_state) { |
| 347 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 348 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 349 | debug.ScopeType.Global], exec_state); |
| 350 | CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 351 | }; |
| 352 | local_7(1, 2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | EndTest(); |
| 354 | |
| 355 | |
| 356 | // Single empty with block. |
| 357 | BeginTest("With 1"); |
| 358 | |
| 359 | function with_1() { |
| 360 | with({}) { |
| 361 | debugger; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | listener_delegate = function(exec_state) { |
| 366 | CheckScopeChain([debug.ScopeType.With, |
| 367 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 368 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | debug.ScopeType.Global], exec_state); |
| 370 | CheckScopeContent({}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 371 | }; |
| 372 | with_1(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 373 | EndTest(); |
| 374 | |
| 375 | |
| 376 | // Nested empty with blocks. |
| 377 | BeginTest("With 2"); |
| 378 | |
| 379 | function with_2() { |
| 380 | with({}) { |
| 381 | with({}) { |
| 382 | debugger; |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | listener_delegate = function(exec_state) { |
| 388 | CheckScopeChain([debug.ScopeType.With, |
| 389 | debug.ScopeType.With, |
| 390 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 391 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 392 | debug.ScopeType.Global], exec_state); |
| 393 | CheckScopeContent({}, 0, exec_state); |
| 394 | CheckScopeContent({}, 1, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 395 | }; |
| 396 | with_2(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 397 | EndTest(); |
| 398 | |
| 399 | |
| 400 | // With block using an in-place object literal. |
| 401 | BeginTest("With 3"); |
| 402 | |
| 403 | function with_3() { |
| 404 | with({a:1,b:2}) { |
| 405 | debugger; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | listener_delegate = function(exec_state) { |
| 410 | CheckScopeChain([debug.ScopeType.With, |
| 411 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 412 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | debug.ScopeType.Global], exec_state); |
| 414 | CheckScopeContent({a:1,b:2}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 415 | }; |
| 416 | with_3(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | EndTest(); |
| 418 | |
| 419 | |
| 420 | // Nested with blocks using in-place object literals. |
| 421 | BeginTest("With 4"); |
| 422 | |
| 423 | function with_4() { |
| 424 | with({a:1,b:2}) { |
| 425 | with({a:2,b:1}) { |
| 426 | debugger; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | listener_delegate = function(exec_state) { |
| 432 | CheckScopeChain([debug.ScopeType.With, |
| 433 | debug.ScopeType.With, |
| 434 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 435 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 436 | debug.ScopeType.Global], exec_state); |
| 437 | CheckScopeContent({a:2,b:1}, 0, exec_state); |
| 438 | CheckScopeContent({a:1,b:2}, 1, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 439 | }; |
| 440 | with_4(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | EndTest(); |
| 442 | |
| 443 | |
| 444 | // Nested with blocks using existing object. |
| 445 | BeginTest("With 5"); |
| 446 | |
| 447 | var with_object = {c:3,d:4}; |
| 448 | function with_5() { |
| 449 | with(with_object) { |
| 450 | with(with_object) { |
| 451 | debugger; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | listener_delegate = function(exec_state) { |
| 457 | CheckScopeChain([debug.ScopeType.With, |
| 458 | debug.ScopeType.With, |
| 459 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 460 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 461 | debug.ScopeType.Global], exec_state); |
| 462 | CheckScopeContent(with_object, 0, exec_state); |
| 463 | CheckScopeContent(with_object, 1, exec_state); |
| 464 | assertEquals(exec_state.frame().scope(0).scopeObject(), exec_state.frame().scope(1).scopeObject()); |
| 465 | assertEquals(with_object, exec_state.frame().scope(1).scopeObject().value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 466 | }; |
| 467 | with_5(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | EndTest(); |
| 469 | |
| 470 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 471 | // Nested with blocks using existing object in global code. |
| 472 | BeginTest("With 6"); |
| 473 | listener_delegate = function(exec_state) { |
| 474 | CheckScopeChain([debug.ScopeType.With, |
| 475 | debug.ScopeType.With, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 476 | debug.ScopeType.Script, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 477 | debug.ScopeType.Global], exec_state); |
| 478 | CheckScopeContent(with_object, 0, exec_state); |
| 479 | CheckScopeContent(with_object, 1, exec_state); |
| 480 | assertEquals(exec_state.frame().scope(0).scopeObject(), exec_state.frame().scope(1).scopeObject()); |
| 481 | assertEquals(with_object, exec_state.frame().scope(1).scopeObject().value()); |
| 482 | }; |
| 483 | |
| 484 | var with_object = {c:3,d:4}; |
| 485 | with(with_object) { |
| 486 | with(with_object) { |
| 487 | debugger; |
| 488 | } |
| 489 | } |
| 490 | EndTest(); |
| 491 | |
| 492 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 493 | // With block in function that is marked for optimization while being executed. |
| 494 | BeginTest("With 7"); |
| 495 | |
| 496 | function with_7() { |
| 497 | with({}) { |
| 498 | %OptimizeFunctionOnNextCall(with_7); |
| 499 | debugger; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | listener_delegate = function(exec_state) { |
| 504 | CheckScopeChain([debug.ScopeType.With, |
| 505 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 506 | debug.ScopeType.Script, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 507 | debug.ScopeType.Global], exec_state); |
| 508 | CheckScopeContent({}, 0, exec_state); |
| 509 | }; |
| 510 | with_7(); |
| 511 | EndTest(); |
| 512 | |
| 513 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | // Simple closure formed by returning an inner function referering the outer |
| 515 | // functions arguments. |
| 516 | BeginTest("Closure 1"); |
| 517 | |
| 518 | function closure_1(a) { |
| 519 | function f() { |
| 520 | debugger; |
| 521 | return a; |
| 522 | }; |
| 523 | return f; |
| 524 | } |
| 525 | |
| 526 | listener_delegate = function(exec_state) { |
| 527 | CheckScopeChain([debug.ScopeType.Local, |
| 528 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 529 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | debug.ScopeType.Global], exec_state); |
| 531 | CheckScopeContent({a:1}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 532 | CheckScopeChainNames([undefined, "closure_1", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 533 | }; |
| 534 | closure_1(1)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 535 | EndTest(); |
| 536 | |
| 537 | |
| 538 | // Simple closure formed by returning an inner function referering the outer |
| 539 | // functions arguments. Due to VM optimizations parts of the actual closure is |
| 540 | // missing from the debugger information. |
| 541 | BeginTest("Closure 2"); |
| 542 | |
| 543 | function closure_2(a, b) { |
| 544 | var x = a + 2; |
| 545 | var y = b + 2; |
| 546 | function f() { |
| 547 | debugger; |
| 548 | return a + x; |
| 549 | }; |
| 550 | return f; |
| 551 | } |
| 552 | |
| 553 | listener_delegate = function(exec_state) { |
| 554 | CheckScopeChain([debug.ScopeType.Local, |
| 555 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 556 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | debug.ScopeType.Global], exec_state); |
| 558 | CheckScopeContent({a:1,x:3}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 559 | CheckScopeChainNames([undefined, "closure_2", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 560 | }; |
| 561 | closure_2(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 562 | EndTest(); |
| 563 | |
| 564 | |
| 565 | // Simple closure formed by returning an inner function referering the outer |
| 566 | // functions arguments. Using all arguments and locals from the outer function |
| 567 | // in the inner function makes these part of the debugger information on the |
| 568 | // closure. |
| 569 | BeginTest("Closure 3"); |
| 570 | |
| 571 | function closure_3(a, b) { |
| 572 | var x = a + 2; |
| 573 | var y = b + 2; |
| 574 | function f() { |
| 575 | debugger; |
| 576 | return a + b + x + y; |
| 577 | }; |
| 578 | return f; |
| 579 | } |
| 580 | |
| 581 | listener_delegate = function(exec_state) { |
| 582 | CheckScopeChain([debug.ScopeType.Local, |
| 583 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 584 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | debug.ScopeType.Global], exec_state); |
| 586 | CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 587 | CheckScopeChainNames([undefined, "closure_3", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 588 | }; |
| 589 | closure_3(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | EndTest(); |
| 591 | |
| 592 | |
| 593 | |
| 594 | // Simple closure formed by returning an inner function referering the outer |
| 595 | // functions arguments. Using all arguments and locals from the outer function |
| 596 | // in the inner function makes these part of the debugger information on the |
| 597 | // closure. Use the inner function as well... |
| 598 | BeginTest("Closure 4"); |
| 599 | |
| 600 | function closure_4(a, b) { |
| 601 | var x = a + 2; |
| 602 | var y = b + 2; |
| 603 | function f() { |
| 604 | debugger; |
| 605 | if (f) { |
| 606 | return a + b + x + y; |
| 607 | } |
| 608 | }; |
| 609 | return f; |
| 610 | } |
| 611 | |
| 612 | listener_delegate = function(exec_state) { |
| 613 | CheckScopeChain([debug.ScopeType.Local, |
| 614 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 615 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 616 | debug.ScopeType.Global], exec_state); |
| 617 | CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 618 | CheckScopeChainNames([undefined, "closure_4", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 619 | }; |
| 620 | closure_4(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 621 | EndTest(); |
| 622 | |
| 623 | |
| 624 | |
| 625 | // Simple closure formed by returning an inner function referering the outer |
| 626 | // functions arguments. In the presence of eval all arguments and locals |
| 627 | // (including the inner function itself) from the outer function becomes part of |
| 628 | // the debugger infformation on the closure. |
| 629 | BeginTest("Closure 5"); |
| 630 | |
| 631 | function closure_5(a, b) { |
| 632 | var x = 3; |
| 633 | var y = 4; |
| 634 | function f() { |
| 635 | eval(''); |
| 636 | debugger; |
| 637 | return 1; |
| 638 | }; |
| 639 | return f; |
| 640 | } |
| 641 | |
| 642 | listener_delegate = function(exec_state) { |
| 643 | CheckScopeChain([debug.ScopeType.Local, |
| 644 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 645 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | debug.ScopeType.Global], exec_state); |
| 647 | CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 648 | CheckScopeChainNames(["f", "closure_5", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 649 | }; |
| 650 | closure_5(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | EndTest(); |
| 652 | |
| 653 | |
| 654 | // Two closures. Due to optimizations only the parts actually used are provided |
| 655 | // through the debugger information. |
| 656 | BeginTest("Closure 6"); |
| 657 | function closure_6(a, b) { |
| 658 | function f(a, b) { |
| 659 | var x = 3; |
| 660 | var y = 4; |
| 661 | return function() { |
| 662 | var x = 3; |
| 663 | var y = 4; |
| 664 | debugger; |
| 665 | some_global = a; |
| 666 | return f; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 667 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | } |
| 669 | return f(a, b); |
| 670 | } |
| 671 | |
| 672 | listener_delegate = function(exec_state) { |
| 673 | CheckScopeChain([debug.ScopeType.Local, |
| 674 | debug.ScopeType.Closure, |
| 675 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 676 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 677 | debug.ScopeType.Global], exec_state); |
| 678 | CheckScopeContent({a:1}, 1, exec_state); |
| 679 | CheckScopeContent({f:function(){}}, 2, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 680 | CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 681 | }; |
| 682 | closure_6(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 683 | EndTest(); |
| 684 | |
| 685 | |
| 686 | // Two closures. In the presence of eval all information is provided as the |
| 687 | // compiler cannot determine which parts are used. |
| 688 | BeginTest("Closure 7"); |
| 689 | function closure_7(a, b) { |
| 690 | var x = 3; |
| 691 | var y = 4; |
| 692 | eval('var i = 5'); |
| 693 | eval('var j = 6'); |
| 694 | function f(a, b) { |
| 695 | var x = 3; |
| 696 | var y = 4; |
| 697 | eval('var i = 5'); |
| 698 | eval('var j = 6'); |
| 699 | return function() { |
| 700 | debugger; |
| 701 | some_global = a; |
| 702 | return f; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 703 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 704 | } |
| 705 | return f(a, b); |
| 706 | } |
| 707 | |
| 708 | listener_delegate = function(exec_state) { |
| 709 | CheckScopeChain([debug.ScopeType.Local, |
| 710 | debug.ScopeType.Closure, |
| 711 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 712 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | debug.ScopeType.Global], exec_state); |
| 714 | CheckScopeContent({}, 0, exec_state); |
| 715 | CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 1, exec_state); |
| 716 | CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 2, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 717 | CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 718 | }; |
| 719 | closure_7(1, 2)(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 720 | EndTest(); |
| 721 | |
| 722 | |
| 723 | // Closure that may be optimized out. |
| 724 | BeginTest("Closure 8"); |
| 725 | function closure_8() { |
| 726 | (function inner(x) { |
| 727 | debugger; |
| 728 | })(2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 729 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 730 | |
| 731 | listener_delegate = function(exec_state) { |
| 732 | CheckScopeChain([debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 733 | debug.ScopeType.Script, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 734 | debug.ScopeType.Global], exec_state); |
| 735 | CheckScopeContent({x: 2}, 0, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 736 | CheckScopeChainNames([undefined, undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 737 | }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 738 | closure_8(); |
| 739 | EndTest(); |
| 740 | |
| 741 | |
| 742 | BeginTest("Closure 9"); |
| 743 | function closure_9() { |
| 744 | eval("var y = 1;"); |
| 745 | eval("var z = 1;"); |
| 746 | (function inner(x) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 747 | y++; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 748 | z++; |
| 749 | debugger; |
| 750 | })(2); |
| 751 | } |
| 752 | |
| 753 | listener_delegate = function(exec_state) { |
| 754 | CheckScopeChain([debug.ScopeType.Local, |
| 755 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 756 | debug.ScopeType.Script, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 757 | debug.ScopeType.Global], exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 758 | CheckScopeChainNames([undefined, "closure_9", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 759 | }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 760 | closure_9(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | EndTest(); |
| 762 | |
| 763 | |
| 764 | // Test a mixture of scopes. |
| 765 | BeginTest("The full monty"); |
| 766 | function the_full_monty(a, b) { |
| 767 | var x = 3; |
| 768 | var y = 4; |
| 769 | eval('var i = 5'); |
| 770 | eval('var j = 6'); |
| 771 | function f(a, b) { |
| 772 | var x = 9; |
| 773 | var y = 10; |
| 774 | eval('var i = 11'); |
| 775 | eval('var j = 12'); |
| 776 | with ({j:13}){ |
| 777 | return function() { |
| 778 | var x = 14; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 779 | with ({a:15}) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 780 | with ({b:16}) { |
| 781 | debugger; |
| 782 | some_global = a; |
| 783 | return f; |
| 784 | } |
| 785 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 786 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | return f(a, b); |
| 790 | } |
| 791 | |
| 792 | listener_delegate = function(exec_state) { |
| 793 | CheckScopeChain([debug.ScopeType.With, |
| 794 | debug.ScopeType.With, |
| 795 | debug.ScopeType.Local, |
| 796 | debug.ScopeType.With, |
| 797 | debug.ScopeType.Closure, |
| 798 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 799 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 800 | debug.ScopeType.Global], exec_state); |
| 801 | CheckScopeContent({b:16}, 0, exec_state); |
| 802 | CheckScopeContent({a:15}, 1, exec_state); |
| 803 | CheckScopeContent({x:14}, 2, exec_state); |
| 804 | CheckScopeContent({j:13}, 3, exec_state); |
| 805 | CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); |
| 806 | CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 807 | CheckScopeChainNames([undefined, undefined, undefined, "f", "f", "the_full_monty", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 808 | }; |
| 809 | the_full_monty(1, 2)(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 810 | EndTest(); |
| 811 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 812 | |
| 813 | BeginTest("Closure inside With 1"); |
| 814 | function closure_in_with_1() { |
| 815 | with({x:1}) { |
| 816 | (function inner(x) { |
| 817 | debugger; |
| 818 | })(2); |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | listener_delegate = function(exec_state) { |
| 823 | CheckScopeChain([debug.ScopeType.Local, |
| 824 | debug.ScopeType.With, |
| 825 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 826 | debug.ScopeType.Script, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 827 | debug.ScopeType.Global], exec_state); |
| 828 | CheckScopeContent({x: 2}, 0, exec_state); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 829 | }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 830 | closure_in_with_1(); |
| 831 | EndTest(); |
| 832 | |
| 833 | |
| 834 | BeginTest("Closure inside With 2"); |
| 835 | function closure_in_with_2() { |
| 836 | with({x:1}) { |
| 837 | (function inner(x) { |
| 838 | with({x:3}) { |
| 839 | debugger; |
| 840 | } |
| 841 | })(2); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | listener_delegate = function(exec_state) { |
| 846 | CheckScopeChain([debug.ScopeType.With, |
| 847 | debug.ScopeType.Local, |
| 848 | debug.ScopeType.With, |
| 849 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 850 | debug.ScopeType.Script, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 851 | debug.ScopeType.Global], exec_state); |
| 852 | CheckScopeContent({x: 3}, 0, exec_state); |
| 853 | CheckScopeContent({x: 2}, 1, exec_state); |
| 854 | CheckScopeContent({x: 1}, 2, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 855 | CheckScopeChainNames(["inner", "inner", "closure_in_with_2", "closure_in_with_2", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 856 | }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 857 | closure_in_with_2(); |
| 858 | EndTest(); |
| 859 | |
| 860 | |
| 861 | BeginTest("Closure inside With 3"); |
| 862 | function createClosure(a) { |
| 863 | var b = a + 1; |
| 864 | return function closure() { |
| 865 | var c = b; |
| 866 | (function inner(x) { |
| 867 | with({x:c}) { |
| 868 | debugger; |
| 869 | } |
| 870 | })(2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 871 | }; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | function closure_in_with_3() { |
| 875 | var f = createClosure(0); |
| 876 | f(); |
| 877 | } |
| 878 | |
| 879 | listener_delegate = function(exec_state) { |
| 880 | CheckScopeChain([debug.ScopeType.With, |
| 881 | debug.ScopeType.Local, |
| 882 | debug.ScopeType.Closure, |
| 883 | debug.ScopeType.Closure, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 884 | debug.ScopeType.Script, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 885 | debug.ScopeType.Global], exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 886 | CheckScopeChainNames(["inner", "inner", "closure", "createClosure", undefined, undefined], exec_state) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 887 | } |
| 888 | closure_in_with_3(); |
| 889 | EndTest(); |
| 890 | |
| 891 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 892 | BeginTest("Closure inside With 4"); |
| 893 | listener_delegate = function(exec_state) { |
| 894 | CheckScopeChain([debug.ScopeType.Local, |
| 895 | debug.ScopeType.With, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 896 | debug.ScopeType.Script, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 897 | debug.ScopeType.Global], exec_state); |
| 898 | CheckScopeContent({x: 2}, 0, exec_state); |
| 899 | CheckScopeContent({x: 1}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 900 | CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | with({x:1}) { |
| 904 | (function(x) { |
| 905 | debugger; |
| 906 | })(2); |
| 907 | } |
| 908 | EndTest(); |
| 909 | |
| 910 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | // Test global scope. |
| 912 | BeginTest("Global"); |
| 913 | listener_delegate = function(exec_state) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 914 | CheckScopeChain([debug.ScopeType.Script, debug.ScopeType.Global], exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 915 | CheckScopeChainNames([undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 916 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 917 | debugger; |
| 918 | EndTest(); |
| 919 | |
| 920 | |
| 921 | BeginTest("Catch block 1"); |
| 922 | function catch_block_1() { |
| 923 | try { |
| 924 | throw 'Exception'; |
| 925 | } catch (e) { |
| 926 | debugger; |
| 927 | } |
| 928 | }; |
| 929 | |
| 930 | |
| 931 | listener_delegate = function(exec_state) { |
| 932 | CheckScopeChain([debug.ScopeType.Catch, |
| 933 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 934 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 935 | debug.ScopeType.Global], exec_state); |
| 936 | CheckScopeContent({e:'Exception'}, 0, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 937 | CheckScopeChainNames(["catch_block_1", undefined, undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 938 | }; |
| 939 | catch_block_1(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 940 | EndTest(); |
| 941 | |
| 942 | |
| 943 | BeginTest("Catch block 2"); |
| 944 | function catch_block_2() { |
| 945 | try { |
| 946 | throw 'Exception'; |
| 947 | } catch (e) { |
| 948 | with({n:10}) { |
| 949 | debugger; |
| 950 | } |
| 951 | } |
| 952 | }; |
| 953 | |
| 954 | |
| 955 | listener_delegate = function(exec_state) { |
| 956 | CheckScopeChain([debug.ScopeType.With, |
| 957 | debug.ScopeType.Catch, |
| 958 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 959 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 960 | debug.ScopeType.Global], exec_state); |
| 961 | CheckScopeContent({n:10}, 0, exec_state); |
| 962 | CheckScopeContent({e:'Exception'}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 963 | CheckScopeChainNames(["catch_block_2", "catch_block_2", "catch_block_2", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 964 | }; |
| 965 | catch_block_2(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 966 | EndTest(); |
| 967 | |
| 968 | |
| 969 | BeginTest("Catch block 3"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 970 | function catch_block_3() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 971 | // Do eval to dynamically declare a local variable so that the context's |
| 972 | // extension slot is initialized with JSContextExtensionObject. |
| 973 | eval("var y = 78;"); |
| 974 | try { |
| 975 | throw 'Exception'; |
| 976 | } catch (e) { |
| 977 | debugger; |
| 978 | } |
| 979 | }; |
| 980 | |
| 981 | |
| 982 | listener_delegate = function(exec_state) { |
| 983 | CheckScopeChain([debug.ScopeType.Catch, |
| 984 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 985 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | debug.ScopeType.Global], exec_state); |
| 987 | CheckScopeContent({e:'Exception'}, 0, exec_state); |
| 988 | CheckScopeContent({y:78}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 989 | CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 990 | }; |
| 991 | catch_block_3(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 992 | EndTest(); |
| 993 | |
| 994 | |
| 995 | BeginTest("Catch block 4"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 996 | function catch_block_4() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 997 | // Do eval to dynamically declare a local variable so that the context's |
| 998 | // extension slot is initialized with JSContextExtensionObject. |
| 999 | eval("var y = 98;"); |
| 1000 | try { |
| 1001 | throw 'Exception'; |
| 1002 | } catch (e) { |
| 1003 | with({n:10}) { |
| 1004 | debugger; |
| 1005 | } |
| 1006 | } |
| 1007 | }; |
| 1008 | |
| 1009 | listener_delegate = function(exec_state) { |
| 1010 | CheckScopeChain([debug.ScopeType.With, |
| 1011 | debug.ScopeType.Catch, |
| 1012 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1013 | debug.ScopeType.Script, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1014 | debug.ScopeType.Global], exec_state); |
| 1015 | CheckScopeContent({n:10}, 0, exec_state); |
| 1016 | CheckScopeContent({e:'Exception'}, 1, exec_state); |
| 1017 | CheckScopeContent({y:98}, 2, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1018 | CheckScopeChainNames(["catch_block_4", "catch_block_4", "catch_block_4", undefined, undefined], exec_state) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1019 | }; |
| 1020 | catch_block_4(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1021 | EndTest(); |
| 1022 | |
| 1023 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1024 | // Test catch in global scope. |
| 1025 | BeginTest("Catch block 5"); |
| 1026 | listener_delegate = function(exec_state) { |
| 1027 | CheckScopeChain([debug.ScopeType.Catch, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1028 | debug.ScopeType.Script, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1029 | debug.ScopeType.Global], exec_state); |
| 1030 | CheckScopeContent({e:'Exception'}, 0, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1031 | CheckScopeChainNames([undefined, undefined, undefined], exec_state) |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1032 | }; |
| 1033 | |
| 1034 | try { |
| 1035 | throw 'Exception'; |
| 1036 | } catch (e) { |
| 1037 | debugger; |
| 1038 | } |
| 1039 | |
| 1040 | EndTest(); |
| 1041 | |
| 1042 | |
| 1043 | // Closure inside catch in global code. |
| 1044 | BeginTest("Catch block 6"); |
| 1045 | listener_delegate = function(exec_state) { |
| 1046 | CheckScopeChain([debug.ScopeType.Local, |
| 1047 | debug.ScopeType.Catch, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1048 | debug.ScopeType.Script, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1049 | debug.ScopeType.Global], exec_state); |
| 1050 | CheckScopeContent({x: 2}, 0, exec_state); |
| 1051 | CheckScopeContent({e:'Exception'}, 1, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1052 | CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1053 | }; |
| 1054 | |
| 1055 | try { |
| 1056 | throw 'Exception'; |
| 1057 | } catch (e) { |
| 1058 | (function(x) { |
| 1059 | debugger; |
| 1060 | })(2); |
| 1061 | } |
| 1062 | EndTest(); |
| 1063 | |
| 1064 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1065 | // Catch block in function that is marked for optimization while being executed. |
| 1066 | BeginTest("Catch block 7"); |
| 1067 | function catch_block_7() { |
| 1068 | %OptimizeFunctionOnNextCall(catch_block_7); |
| 1069 | try { |
| 1070 | throw 'Exception'; |
| 1071 | } catch (e) { |
| 1072 | debugger; |
| 1073 | } |
| 1074 | }; |
| 1075 | |
| 1076 | |
| 1077 | listener_delegate = function(exec_state) { |
| 1078 | CheckScopeChain([debug.ScopeType.Catch, |
| 1079 | debug.ScopeType.Local, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1080 | debug.ScopeType.Script, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1081 | debug.ScopeType.Global], exec_state); |
| 1082 | CheckScopeContent({e:'Exception'}, 0, exec_state); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1083 | CheckScopeChainNames(["catch_block_7", undefined, undefined, undefined], exec_state) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1084 | }; |
| 1085 | catch_block_7(); |
| 1086 | EndTest(); |
| 1087 | |
| 1088 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1089 | BeginTest("Classes and methods 1"); |
| 1090 | |
| 1091 | listener_delegate = function(exec_state) { |
| 1092 | "use strict" |
| 1093 | CheckScopeChain([debug.ScopeType.Local, |
| 1094 | debug.ScopeType.Script, |
| 1095 | debug.ScopeType.Global], exec_state); |
| 1096 | CheckScopeContent({}, 1, exec_state); |
| 1097 | CheckScopeChainNames([undefined, undefined, undefined], exec_state) |
| 1098 | }; |
| 1099 | |
| 1100 | (function() { |
| 1101 | "use strict"; |
| 1102 | class C1 { |
| 1103 | m() { |
| 1104 | debugger; |
| 1105 | } |
| 1106 | } |
| 1107 | new C1().m(); |
| 1108 | })(); |
| 1109 | |
| 1110 | EndTest(); |
| 1111 | |
| 1112 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1113 | assertEquals(begin_test_count, break_count, |
| 1114 | 'one or more tests did not enter the debugger'); |
| 1115 | assertEquals(begin_test_count, end_test_count, |
| 1116 | 'one or more tests did not have its result checked'); |