| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --ignition --turbo | 5 // Flags: --ignition --turbo |
| 6 // The functions used for testing backtraces. They are at the top to make the | 6 // The functions used for testing backtraces. They are at the top to make the |
| 7 // testing of source line/column easier. | 7 // testing of source line/column easier. |
| 8 | 8 |
| 9 var Debug = debug.Debug; | 9 var Debug = debug.Debug; |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Simple empty closure scope. | 102 // Simple empty closure scope. |
| 103 | 103 |
| 104 function *gen1() { | 104 function *gen1() { |
| 105 yield 1; | 105 yield 1; |
| 106 return 2; | 106 return 2; |
| 107 } | 107 } |
| 108 | 108 |
| 109 var g = gen1(); | 109 var g = gen1(); |
| 110 CheckScopeChain([debug.ScopeType.Local, | 110 CheckScopeChain([debug.ScopeType.Closure, |
| 111 debug.ScopeType.Script, | 111 debug.ScopeType.Script, |
| 112 debug.ScopeType.Global], g); | 112 debug.ScopeType.Global], g); |
| 113 CheckScopeContent({}, 0, g); | 113 CheckScopeContent({}, 0, g); |
| 114 | 114 |
| 115 // Closure scope with a parameter. | 115 // Closure scope with a parameter. |
| 116 | 116 |
| 117 function *gen2(a) { | 117 function *gen2(a) { |
| 118 yield a; | 118 yield a; |
| 119 return 2; | 119 return 2; |
| 120 } | 120 } |
| 121 | 121 |
| 122 g = gen2(42); | 122 g = gen2(42); |
| 123 CheckScopeChain([debug.ScopeType.Local, | 123 CheckScopeChain([debug.ScopeType.Closure, |
| 124 debug.ScopeType.Script, | 124 debug.ScopeType.Script, |
| 125 debug.ScopeType.Global], g); | 125 debug.ScopeType.Global], g); |
| 126 CheckScopeContent({a: 42}, 0, g); | 126 CheckScopeContent({a: 42}, 0, g); |
| 127 | 127 |
| 128 // Closure scope with a parameter. | 128 // Closure scope with a parameter. |
| 129 | 129 |
| 130 function *gen3(a) { | 130 function *gen3(a) { |
| 131 var b = 1 | 131 var b = 1 |
| 132 yield a; | 132 yield a; |
| 133 return b; | 133 return b; |
| 134 } | 134 } |
| 135 | 135 |
| 136 g = gen3(0); | 136 g = gen3(0); |
| 137 CheckScopeChain([debug.ScopeType.Local, | 137 CheckScopeChain([debug.ScopeType.Closure, |
| 138 debug.ScopeType.Script, | 138 debug.ScopeType.Script, |
| 139 debug.ScopeType.Global], g); | 139 debug.ScopeType.Global], g); |
| 140 CheckScopeContent({a: 0, b: undefined}, 0, g); | 140 CheckScopeContent({a: 0, b: undefined}, 0, g); |
| 141 | 141 |
| 142 g.next(); // Create b. | 142 g.next(); // Create b. |
| 143 CheckScopeContent({a: 0, b: 1}, 0, g); | 143 CheckScopeContent({a: 0, b: 1}, 0, g); |
| 144 | 144 |
| 145 // Closure scope with a parameter. | 145 // Closure scope with a parameter. |
| 146 | 146 |
| 147 function *gen4(a, b) { | 147 function *gen4(a, b) { |
| 148 var x = 2; | 148 var x = 2; |
| 149 yield a; | 149 yield a; |
| 150 var y = 3; | 150 var y = 3; |
| 151 yield a; | |
| 152 return b; | 151 return b; |
| 153 } | 152 } |
| 154 | 153 |
| 155 g = gen4(0, 1); | 154 g = gen4(0, 1); |
| 156 CheckScopeChain([debug.ScopeType.Local, | 155 CheckScopeChain([debug.ScopeType.Closure, |
| 157 debug.ScopeType.Script, | 156 debug.ScopeType.Script, |
| 158 debug.ScopeType.Global], g); | 157 debug.ScopeType.Global], g); |
| 159 CheckScopeContent({a: 0, b: 1, x: undefined, y: undefined}, 0, g); | 158 CheckScopeContent({a: 0, b: 1, x: undefined, y: undefined}, 0, g); |
| 160 | 159 |
| 161 g.next(); // Create x. | 160 g.next(); // Create x. |
| 162 CheckScopeContent({a: 0, b: 1, x: 2, y: undefined}, 0, g); | 161 CheckScopeContent({a: 0, b: 1, x: 2, y: undefined}, 0, g); |
| 163 | 162 |
| 164 g.next(); // Create y. | 163 g.next(); // Create y. |
| 165 CheckScopeContent({a: 0, b: 1, x: 2, y: 3}, 0, g); | 164 CheckScopeContent({a: 0, b: 1, x: 2, y: 3}, 0, g); |
| 166 | 165 |
| 167 // Closure introducing local variable using eval. | 166 // Closure introducing local variable using eval. |
| 168 | 167 |
| 169 function *gen5(a) { | 168 function *gen5(a) { |
| 170 eval('var b = 2'); | 169 eval('var b = 2'); |
| 171 yield a; | |
| 172 return b; | 170 return b; |
| 173 } | 171 } |
| 174 | 172 |
| 175 g = gen5(1); | 173 g = gen5(1); |
| 176 g.next(); | 174 g.next(); |
| 177 CheckScopeChain([debug.ScopeType.Local, | 175 CheckScopeChain([debug.ScopeType.Closure, |
| 178 debug.ScopeType.Script, | 176 debug.ScopeType.Script, |
| 179 debug.ScopeType.Global], g); | 177 debug.ScopeType.Global], g); |
| 180 CheckScopeContent({a: 1, b: 2}, 0, g); | 178 CheckScopeContent({a: 1, b: 2}, 0, g); |
| 181 | 179 |
| 182 // Single empty with block. | 180 // Single empty with block. |
| 183 | 181 |
| 184 function *gen6() { | 182 function *gen6() { |
| 185 with({}) { | 183 with({}) { |
| 186 yield 1; | 184 yield 1; |
| 187 } | 185 } |
| 188 yield 2; | 186 yield 2; |
| 189 return 3; | 187 return 3; |
| 190 } | 188 } |
| 191 | 189 |
| 192 g = gen6(); | 190 g = gen6(); |
| 193 g.next(); | 191 g.next(); |
| 194 CheckScopeChain([debug.ScopeType.With, | 192 CheckScopeChain([debug.ScopeType.With, |
| 195 debug.ScopeType.Local, | 193 debug.ScopeType.Closure, |
| 196 debug.ScopeType.Script, | 194 debug.ScopeType.Script, |
| 197 debug.ScopeType.Global], g); | 195 debug.ScopeType.Global], g); |
| 198 CheckScopeContent({}, 0, g); | 196 CheckScopeContent({}, 0, g); |
| 199 | 197 |
| 200 g.next(); | 198 g.next(); |
| 201 CheckScopeChain([debug.ScopeType.Local, | 199 CheckScopeChain([debug.ScopeType.Closure, |
| 202 debug.ScopeType.Script, | 200 debug.ScopeType.Script, |
| 203 debug.ScopeType.Global], g); | 201 debug.ScopeType.Global], g); |
| 204 | 202 |
| 205 // Nested empty with blocks. | 203 // Nested empty with blocks. |
| 206 | 204 |
| 207 function *gen7() { | 205 function *gen7() { |
| 208 with({}) { | 206 with({}) { |
| 209 with({}) { | 207 with({}) { |
| 210 yield 1; | 208 yield 1; |
| 211 } | 209 } |
| 212 yield 2; | 210 yield 2; |
| 213 } | 211 } |
| 214 return 3; | 212 return 3; |
| 215 } | 213 } |
| 216 | 214 |
| 217 g = gen7(); | 215 g = gen7(); |
| 218 g.next(); | 216 g.next(); |
| 219 CheckScopeChain([debug.ScopeType.With, | 217 CheckScopeChain([debug.ScopeType.With, |
| 220 debug.ScopeType.With, | 218 debug.ScopeType.With, |
| 221 debug.ScopeType.Local, | 219 debug.ScopeType.Closure, |
| 222 debug.ScopeType.Script, | 220 debug.ScopeType.Script, |
| 223 debug.ScopeType.Global], g); | 221 debug.ScopeType.Global], g); |
| 224 CheckScopeContent({}, 0, g); | 222 CheckScopeContent({}, 0, g); |
| 225 | 223 |
| 226 // Nested with blocks using in-place object literals. | 224 // Nested with blocks using in-place object literals. |
| 227 | 225 |
| 228 function *gen8() { | 226 function *gen8() { |
| 229 with({a: 1,b: 2}) { | 227 with({a: 1,b: 2}) { |
| 230 with({a: 2,b: 1}) { | 228 with({a: 2,b: 1}) { |
| 231 yield a; | 229 yield a; |
| 232 } | 230 } |
| 233 yield a; | 231 yield a; |
| 234 } | 232 } |
| 235 return 3; | 233 return 3; |
| 236 } | 234 } |
| 237 | 235 |
| 238 g = gen8(); | 236 g = gen8(); |
| 239 g.next(); | 237 g.next(); |
| 240 CheckScopeChain([debug.ScopeType.With, | 238 CheckScopeChain([debug.ScopeType.With, |
| 241 debug.ScopeType.With, | 239 debug.ScopeType.With, |
| 242 debug.ScopeType.Local, | 240 debug.ScopeType.Closure, |
| 243 debug.ScopeType.Script, | 241 debug.ScopeType.Script, |
| 244 debug.ScopeType.Global], g); | 242 debug.ScopeType.Global], g); |
| 245 CheckScopeContent({a: 2, b: 1}, 0, g); | 243 CheckScopeContent({a: 2, b: 1}, 0, g); |
| 246 | 244 |
| 247 g.next(); | 245 g.next(); |
| 248 CheckScopeContent({a: 1, b: 2}, 0, g); | 246 CheckScopeContent({a: 1, b: 2}, 0, g); |
| 249 | 247 |
| 250 // Catch block. | 248 // Catch block. |
| 251 | 249 |
| 252 function *gen9() { | 250 function *gen9() { |
| 253 try { | 251 try { |
| 254 throw 42; | 252 throw 42; |
| 255 } catch (e) { | 253 } catch (e) { |
| 256 yield e; | 254 yield e; |
| 257 } | 255 } |
| 258 return 3; | 256 return 3; |
| 259 } | 257 } |
| 260 | 258 |
| 261 g = gen9(); | 259 g = gen9(); |
| 262 g.next(); | 260 g.next(); |
| 263 CheckScopeChain([debug.ScopeType.Catch, | 261 CheckScopeChain([debug.ScopeType.Catch, |
| 264 debug.ScopeType.Local, | 262 debug.ScopeType.Closure, |
| 265 debug.ScopeType.Script, | 263 debug.ScopeType.Script, |
| 266 debug.ScopeType.Global], g); | 264 debug.ScopeType.Global], g); |
| 267 CheckScopeContent({e: 42}, 0, g); | 265 CheckScopeContent({e: 42}, 0, g); |
| 268 | 266 |
| 269 // For statement with block scope. | 267 // For statement with block scope. |
| 270 | 268 |
| 271 function *gen10() { | 269 function *gen10() { |
| 272 for (let i = 0; i < 42; i++) yield i; | 270 for (let i = 0; i < 42; i++) yield i; |
| 273 return 3; | 271 return 3; |
| 274 } | 272 } |
| 275 | 273 |
| 276 g = gen10(); | 274 g = gen10(); |
| 277 g.next(); | 275 g.next(); |
| 278 CheckScopeChain([debug.ScopeType.Block, | 276 CheckScopeChain([debug.ScopeType.Block, |
| 279 debug.ScopeType.Local, | 277 debug.ScopeType.Block, |
| 278 debug.ScopeType.Closure, |
| 280 debug.ScopeType.Script, | 279 debug.ScopeType.Script, |
| 281 debug.ScopeType.Global], g); | 280 debug.ScopeType.Global], g); |
| 282 CheckScopeContent({i: 0}, 0, g); | 281 CheckScopeContent({i: 0}, 0, g); |
| 283 | 282 |
| 284 g.next(); | 283 g.next(); |
| 285 CheckScopeContent({i: 1}, 0, g); | 284 CheckScopeContent({i: 1}, 0, g); |
| 285 CheckScopeContent({i: 0}, 1, g); // Additional block scope with i = 0; |
| 286 | 286 |
| 287 // Nested generators. | 287 // Nested generators. |
| 288 | 288 |
| 289 var gen12; | 289 var gen12; |
| 290 function *gen11() { | 290 function *gen11() { |
| 291 var b = 2; | |
| 292 gen12 = function*() { | 291 gen12 = function*() { |
| 293 var a = 1; | 292 var a = 1; |
| 294 yield 1; | 293 yield 1; |
| 295 return b; | 294 return 2; |
| 296 }(); | 295 }(); |
| 297 | 296 |
| 298 var a = 0; | 297 var a = 0; |
| 299 yield* gen12; | 298 yield* gen12; |
| 300 } | 299 } |
| 301 | 300 |
| 302 gen11().next(); | 301 gen11().next(); |
| 303 g = gen12; | 302 g = gen12; |
| 304 | 303 |
| 305 CheckScopeChain([debug.ScopeType.Local, | 304 CheckScopeChain([debug.ScopeType.Closure, |
| 306 debug.ScopeType.Closure, | 305 debug.ScopeType.Closure, |
| 307 debug.ScopeType.Script, | 306 debug.ScopeType.Script, |
| 308 debug.ScopeType.Global], g); | 307 debug.ScopeType.Global], g); |
| 309 CheckScopeContent({a: 1}, 0, g); | 308 CheckScopeContent({a: 1}, 0, g); |
| 310 CheckScopeContent({b: 2}, 1, g); | 309 CheckScopeContent({a: 0}, 1, g); |
| 311 | 310 |
| 312 // Set a variable in an empty scope. | 311 // Set a variable in an empty scope. |
| 313 | 312 |
| 314 function *gen13() { | 313 function *gen13() { |
| 315 yield 1; | 314 yield 1; |
| 316 return 2; | 315 return 2; |
| 317 } | 316 } |
| 318 | 317 |
| 319 var g = gen13(); | 318 var g = gen13(); |
| 320 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42)); | 319 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 349 var e = 5; | 348 var e = 5; |
| 350 } | 349 } |
| 351 yield e; | 350 yield e; |
| 352 return e; | 351 return e; |
| 353 } | 352 } |
| 354 | 353 |
| 355 var g = gen15(); | 354 var g = gen15(); |
| 356 assertEquals(1, g.next().value); | 355 assertEquals(1, g.next().value); |
| 357 | 356 |
| 358 CheckScopeChain([debug.ScopeType.With, | 357 CheckScopeChain([debug.ScopeType.With, |
| 359 debug.ScopeType.Local, | 358 debug.ScopeType.Closure, |
| 360 debug.ScopeType.Script, | 359 debug.ScopeType.Script, |
| 361 debug.ScopeType.Global], g); | 360 debug.ScopeType.Global], g); |
| 362 CheckScopeContent({a: 1, b: 2}, 0, g); | 361 CheckScopeContent({a: 1, b: 2}, 0, g); |
| 363 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g); | 362 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g); |
| 364 | 363 |
| 365 // Variables don't exist in given scope. | 364 // Variables don't exist in given scope. |
| 366 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42)); | 365 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42)); |
| 367 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42)); | 366 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42)); |
| 368 | 367 |
| 369 // Variables in with scope are immutable. | 368 // Variables in with scope are immutable. |
| 370 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3)); | 369 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3)); |
| 371 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3)); | 370 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3)); |
| 372 | 371 |
| 373 Debug.generatorScope(g, 1).setVariableValue("c", 1); | 372 Debug.generatorScope(g, 1).setVariableValue("c", 1); |
| 374 Debug.generatorScope(g, 1).setVariableValue("e", 42); | 373 Debug.generatorScope(g, 1).setVariableValue("e", 42); |
| 375 | 374 |
| 376 CheckScopeContent({a: 1, b: 2}, 0, g); | 375 CheckScopeContent({a: 1, b: 2}, 0, g); |
| 377 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g); | 376 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g); |
| 378 assertEquals(5, g.next().value); // Initialized after set. | 377 assertEquals(5, g.next().value); // Initialized after set. |
| 379 | 378 |
| 380 CheckScopeChain([debug.ScopeType.Local, | 379 CheckScopeChain([debug.ScopeType.Closure, |
| 381 debug.ScopeType.Script, | 380 debug.ScopeType.Script, |
| 382 debug.ScopeType.Global], g); | 381 debug.ScopeType.Global], g); |
| 383 | 382 |
| 384 Debug.generatorScope(g, 0).setVariableValue("e", 42); | 383 Debug.generatorScope(g, 0).setVariableValue("e", 42); |
| 385 | 384 |
| 386 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g); | 385 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g); |
| 387 assertEquals(42, g.next().value); | 386 assertEquals(42, g.next().value); |
| 388 | 387 |
| 389 // Set a variable in nested with blocks using in-place object literals plus a | 388 // Set a variable in nested with blocks using in-place object literals plus a |
| 390 // nested block scope. | 389 // nested block scope. |
| 391 | 390 |
| 392 function *gen16() { | 391 function *gen16() { |
| 393 var c = 3; | 392 var c = 3; |
| 394 with({a: 1,b: 2}) { | 393 with({a: 1,b: 2}) { |
| 395 let d = 4; | 394 let d = 4; |
| 396 yield a; | 395 yield a; |
| 397 let e = 5; | 396 let e = 5; |
| 398 yield d; | 397 yield d; |
| 399 } | 398 } |
| 400 return 3; | 399 return 3; |
| 401 } | 400 } |
| 402 | 401 |
| 403 var g = gen16(); | 402 var g = gen16(); |
| 404 g.next(); | 403 g.next(); |
| 405 | 404 |
| 406 CheckScopeChain([debug.ScopeType.Block, | 405 CheckScopeChain([debug.ScopeType.Block, |
| 407 debug.ScopeType.With, | 406 debug.ScopeType.With, |
| 408 debug.ScopeType.Local, | 407 debug.ScopeType.Closure, |
| 409 debug.ScopeType.Script, | 408 debug.ScopeType.Script, |
| 410 debug.ScopeType.Global], g); | 409 debug.ScopeType.Global], g); |
| 411 CheckScopeContent({d: 4, e: undefined}, 0, g); | 410 CheckScopeContent({d: 4}, 0, g); |
| 412 CheckScopeContent({a: 1, b: 2}, 1, g); | 411 CheckScopeContent({a: 1, b: 2}, 1, g); |
| 413 CheckScopeContent({c: 3}, 2, g); | 412 CheckScopeContent({c: 3}, 2, g); |
| 414 | 413 |
| 415 Debug.generatorScope(g, 0).setVariableValue("d", 1); | 414 Debug.generatorScope(g, 0).setVariableValue("d", 1); |
| 416 CheckScopeContent({d: 1, e: undefined}, 0, g); | 415 CheckScopeContent({d: 1}, 0, g); |
| 417 | 416 |
| 418 assertEquals(1, g.next().value); | 417 assertEquals(1, g.next().value); |
| 419 | 418 |
| 420 // Set variable in catch block. | 419 // Set variable in catch block. |
| 421 | 420 |
| 422 var yyzyzzyz = 4829; | 421 var yyzyzzyz = 4829; |
| 423 let xxxyyxxyx = 42284; | 422 let xxxyyxxyx = 42284; |
| 424 function *gen17() { | 423 function *gen17() { |
| 425 try { | 424 try { |
| 426 throw 42; | 425 throw 42; |
| 427 } catch (e) { | 426 } catch (e) { |
| 428 yield e; | 427 yield e; |
| 429 yield e; | 428 yield e; |
| 430 } | 429 } |
| 431 return 3; | 430 return 3; |
| 432 } | 431 } |
| 433 | 432 |
| 434 g = gen17(); | 433 g = gen17(); |
| 435 g.next(); | 434 g.next(); |
| 436 | 435 |
| 437 CheckScopeChain([debug.ScopeType.Catch, | 436 CheckScopeChain([debug.ScopeType.Catch, |
| 438 debug.ScopeType.Local, | 437 debug.ScopeType.Closure, |
| 439 debug.ScopeType.Script, | 438 debug.ScopeType.Script, |
| 440 debug.ScopeType.Global], g); | 439 debug.ScopeType.Global], g); |
| 441 CheckScopeContent({e: 42}, 0, g); | 440 CheckScopeContent({e: 42}, 0, g); |
| 442 CheckScopeContent({xxxyyxxyx: 42284, | 441 CheckScopeContent({xxxyyxxyx: 42284, |
| 443 printProtocolMessages : printProtocolMessages, | 442 printProtocolMessages : printProtocolMessages, |
| 444 activeWrapper : activeWrapper, | 443 activeWrapper : activeWrapper, |
| 445 DebugWrapper : DebugWrapper | 444 DebugWrapper : DebugWrapper |
| 446 }, 2, g); | 445 }, 2, g); |
| 447 | 446 |
| 448 Debug.generatorScope(g, 0).setVariableValue("e", 1); | 447 Debug.generatorScope(g, 0).setVariableValue("e", 1); |
| 449 CheckScopeContent({e: 1}, 0, g); | 448 CheckScopeContent({e: 1}, 0, g); |
| 450 | 449 |
| 451 assertEquals(1, g.next().value); | 450 assertEquals(1, g.next().value); |
| 452 | 451 |
| 453 // Script scope. | 452 // Script scope. |
| 454 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42); | 453 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42); |
| 455 assertEquals(42, xxxyyxxyx); | 454 assertEquals(42, xxxyyxxyx); |
| 456 | 455 |
| 457 // Global scope. | 456 // Global scope. |
| 458 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42)); | 457 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42)); |
| 459 assertEquals(4829, yyzyzzyz); | 458 assertEquals(4829, yyzyzzyz); |
| OLD | NEW |