OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 9193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9204 int suffix_len = Utf8LengthHelper(suffix); | 9204 int suffix_len = Utf8LengthHelper(suffix); |
9205 | 9205 |
9206 // The scope start positions must match; note the extra space in lazy_inner. | 9206 // The scope start positions must match; note the extra space in lazy_inner. |
9207 const char* lazy_inner = " function inner(%s) { %s }"; | 9207 const char* lazy_inner = " function inner(%s) { %s }"; |
9208 const char* eager_inner = "(function inner(%s) { %s })()"; | 9208 const char* eager_inner = "(function inner(%s) { %s })()"; |
9209 | 9209 |
9210 struct { | 9210 struct { |
9211 const char* params; | 9211 const char* params; |
9212 const char* source; | 9212 const char* source; |
9213 } inners[] = { | 9213 } inners[] = { |
| 9214 // Simple cases |
9214 {"", "var1;"}, | 9215 {"", "var1;"}, |
9215 {"", "var1 = 5;"}, | 9216 {"", "var1 = 5;"}, |
9216 {"", "if (true) {}"}, | 9217 {"", "if (true) {}"}, |
9217 {"", "function f1() {}"}, | 9218 {"", "function f1() {}"}, |
9218 | 9219 |
| 9220 // Var declarations and assignments. |
9219 {"", "var var1;"}, | 9221 {"", "var var1;"}, |
9220 {"", "var var1; var1 = 5;"}, | 9222 {"", "var var1; var1 = 5;"}, |
9221 {"", "if (true) { var var1; }"}, | 9223 {"", "if (true) { var var1; }"}, |
9222 {"", "if (true) { var var1; var1 = 5; }"}, | 9224 {"", "if (true) { var var1; var1 = 5; }"}, |
9223 {"", "var var1; function f() { var1; }"}, | 9225 {"", "var var1; function f() { var1; }"}, |
9224 {"", "var var1; var1 = 5; function f() { var1; }"}, | 9226 {"", "var var1; var1 = 5; function f() { var1; }"}, |
9225 {"", "var var1; function f() { var1 = 5; }"}, | 9227 {"", "var var1; function f() { var1 = 5; }"}, |
9226 | 9228 |
| 9229 // Let declarations and assignments. |
9227 {"", "let var1;"}, | 9230 {"", "let var1;"}, |
9228 {"", "let var1; var1 = 5;"}, | 9231 {"", "let var1; var1 = 5;"}, |
9229 {"", "if (true) { let var1; }"}, | 9232 {"", "if (true) { let var1; }"}, |
9230 {"", "if (true) { let var1; var1 = 5; }"}, | 9233 {"", "if (true) { let var1; var1 = 5; }"}, |
9231 {"", "let var1; function f() { var1; }"}, | 9234 {"", "let var1; function f() { var1; }"}, |
9232 {"", "let var1; var1 = 5; function f() { var1; }"}, | 9235 {"", "let var1; var1 = 5; function f() { var1; }"}, |
9233 {"", "let var1; function f() { var1 = 5; }"}, | 9236 {"", "let var1; function f() { var1 = 5; }"}, |
9234 | 9237 |
| 9238 // Const declarations. |
9235 {"", "const var1 = 5;"}, | 9239 {"", "const var1 = 5;"}, |
9236 {"", "if (true) { const var1 = 5; }"}, | 9240 {"", "if (true) { const var1 = 5; }"}, |
9237 {"", "const var1 = 5; function f() { var1; }"}, | 9241 {"", "const var1 = 5; function f() { var1; }"}, |
9238 | 9242 |
| 9243 // Redeclarations. |
9239 {"", "var var1; var var1;"}, | 9244 {"", "var var1; var var1;"}, |
9240 {"", "var var1; var var1; var1 = 5;"}, | 9245 {"", "var var1; var var1; var1 = 5;"}, |
9241 {"", "var var1; if (true) { var var1; }"}, | 9246 {"", "var var1; if (true) { var var1; }"}, |
9242 {"", "if (true) { var var1; var var1; }"}, | 9247 {"", "if (true) { var var1; var var1; }"}, |
9243 {"", "var var1; if (true) { var var1; var1 = 5; }"}, | 9248 {"", "var var1; if (true) { var var1; var1 = 5; }"}, |
9244 {"", "if (true) { var var1; var var1; var1 = 5; }"}, | 9249 {"", "if (true) { var var1; var var1; var1 = 5; }"}, |
9245 {"", "var var1; var var1; function f() { var1; }"}, | 9250 {"", "var var1; var var1; function f() { var1; }"}, |
9246 {"", "var var1; var var1; function f() { var1 = 5; }"}, | 9251 {"", "var var1; var var1; function f() { var1 = 5; }"}, |
9247 | 9252 |
| 9253 // Shadowing declarations. |
9248 {"", "var var1; if (true) { var var1; }"}, | 9254 {"", "var var1; if (true) { var var1; }"}, |
9249 {"", "var var1; if (true) { let var1; }"}, | 9255 {"", "var var1; if (true) { let var1; }"}, |
9250 {"", "let var1; if (true) { let var1; }"}, | 9256 {"", "let var1; if (true) { let var1; }"}, |
9251 | 9257 |
9252 {"", "var var1; if (true) { const var1 = 0; }"}, | 9258 {"", "var var1; if (true) { const var1 = 0; }"}, |
9253 {"", "const var1 = 0; if (true) { const var1 = 0; }"}, | 9259 {"", "const var1 = 0; if (true) { const var1 = 0; }"}, |
9254 | 9260 |
| 9261 // Variable called "arguments" |
9255 {"", "arguments;"}, | 9262 {"", "arguments;"}, |
9256 {"", "arguments = 5;"}, | 9263 {"", "arguments = 5;"}, |
9257 {"", "function f() { arguments; }"}, | 9264 {"", "function f() { arguments; }"}, |
9258 {"", "function f() { arguments = 5; }"}, | 9265 {"", "function f() { arguments = 5; }"}, |
9259 | 9266 |
9260 {"", "var arguments;"}, | 9267 {"", "var arguments;"}, |
9261 {"", "var arguments; arguments = 5;"}, | 9268 {"", "var arguments; arguments = 5;"}, |
9262 {"", "if (true) { var arguments; }"}, | 9269 {"", "if (true) { var arguments; }"}, |
9263 {"", "if (true) { var arguments; arguments = 5; }"}, | 9270 {"", "if (true) { var arguments; arguments = 5; }"}, |
9264 {"", "var arguments; function f() { arguments; }"}, | 9271 {"", "var arguments; function f() { arguments; }"}, |
9265 {"", "var arguments; arguments = 5; function f() { arguments; }"}, | 9272 {"", "var arguments; arguments = 5; function f() { arguments; }"}, |
9266 {"", "var arguments; function f() { arguments = 5; }"}, | 9273 {"", "var arguments; function f() { arguments = 5; }"}, |
9267 | 9274 |
9268 {"", "let arguments;"}, | 9275 {"", "let arguments;"}, |
9269 {"", "let arguments; arguments = 5;"}, | 9276 {"", "let arguments; arguments = 5;"}, |
9270 {"", "if (true) { let arguments; }"}, | 9277 {"", "if (true) { let arguments; }"}, |
9271 {"", "if (true) { let arguments; arguments = 5; }"}, | 9278 {"", "if (true) { let arguments; arguments = 5; }"}, |
9272 {"", "let arguments; function f() { arguments; }"}, | 9279 {"", "let arguments; function f() { arguments; }"}, |
9273 {"", "let arguments; arguments = 5; function f() { arguments; }"}, | 9280 {"", "let arguments; arguments = 5; function f() { arguments; }"}, |
9274 {"", "let arguments; function f() { arguments = 5; }"}, | 9281 {"", "let arguments; function f() { arguments = 5; }"}, |
9275 | 9282 |
9276 {"", "const arguments = 5;"}, | 9283 {"", "const arguments = 5;"}, |
9277 {"", "if (true) { const arguments = 5; }"}, | 9284 {"", "if (true) { const arguments = 5; }"}, |
9278 {"", "const arguments = 5; function f() { arguments; }"}, | 9285 {"", "const arguments = 5; function f() { arguments; }"}, |
9279 | 9286 |
| 9287 // Destructuring declarations. |
9280 {"", "var [var1, var2] = [1, 2];"}, | 9288 {"", "var [var1, var2] = [1, 2];"}, |
9281 {"", "var [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"}, | 9289 {"", "var [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"}, |
9282 {"", "var [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"}, | 9290 {"", "var [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"}, |
9283 {"", "var [var1, ...var2] = [1, 2, 3];"}, | 9291 {"", "var [var1, ...var2] = [1, 2, 3];"}, |
9284 | 9292 |
9285 {"", "var {var1: var2, var3: var4} = {var1: 1, var3: 2};"}, | 9293 {"", "var {var1: var2, var3: var4} = {var1: 1, var3: 2};"}, |
9286 {"", | 9294 {"", |
9287 "var {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"}, | 9295 "var {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"}, |
9288 {"", "var {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"}, | 9296 {"", "var {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"}, |
9289 | 9297 |
(...skipping 10 matching lines...) Expand all Loading... |
9300 {"", "const [var1, var2] = [1, 2];"}, | 9308 {"", "const [var1, var2] = [1, 2];"}, |
9301 {"", "const [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"}, | 9309 {"", "const [var1, var2, [var3, var4]] = [1, 2, [3, 4]];"}, |
9302 {"", "const [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"}, | 9310 {"", "const [{var1: var2}, {var3: var4}] = [{var1: 1}, {var3: 2}];"}, |
9303 {"", "const [var1, ...var2] = [1, 2, 3];"}, | 9311 {"", "const [var1, ...var2] = [1, 2, 3];"}, |
9304 | 9312 |
9305 {"", "const {var1: var2, var3: var4} = {var1: 1, var3: 2};"}, | 9313 {"", "const {var1: var2, var3: var4} = {var1: 1, var3: 2};"}, |
9306 {"", | 9314 {"", |
9307 "const {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"}, | 9315 "const {var1: var2, var3: {var4: var5}} = {var1: 1, var3: {var4: 2}};"}, |
9308 {"", "const {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"}, | 9316 {"", "const {var1: var2, var3: [var4, var5]} = {var1: 1, var3: [2, 3]};"}, |
9309 | 9317 |
| 9318 // Referencing the function variable. |
9310 {"", "inner;"}, | 9319 {"", "inner;"}, |
9311 {"", "function f1() { f1; }"}, | 9320 {"", "function f1() { f1; }"}, |
9312 {"", "function f1() { inner; }"}, | 9321 {"", "function f1() { inner; }"}, |
9313 {"", "function f1() { function f2() { f1; } }"}, | 9322 {"", "function f1() { function f2() { f1; } }"}, |
9314 {"", "function arguments() {}"}, | 9323 {"", "function arguments() {}"}, |
9315 {"", "function f1() {} function f1() {}"}, | 9324 {"", "function f1() {} function f1() {}"}, |
9316 {"", "var f1; function f1() {}"}, | 9325 {"", "var f1; function f1() {}"}, |
9317 | 9326 |
| 9327 // Assigning to the function variable. |
9318 {"", "inner = 3;"}, | 9328 {"", "inner = 3;"}, |
9319 {"", "function f1() { f1 = 3; }"}, | 9329 {"", "function f1() { f1 = 3; }"}, |
9320 {"", "function f1() { f1; } f1 = 3;"}, | 9330 {"", "function f1() { f1; } f1 = 3;"}, |
9321 {"", "function arguments() {} arguments = 8"}, | 9331 {"", "function arguments() {} arguments = 8"}, |
9322 {"", "function f1() {} f1 = 3; function f1() {}"}, | 9332 {"", "function f1() {} f1 = 3; function f1() {}"}, |
9323 | 9333 |
| 9334 // Evals. |
9324 {"", "var var1; eval('');"}, | 9335 {"", "var var1; eval('');"}, |
9325 {"", "var var1; function f1() { eval(''); }"}, | 9336 {"", "var var1; function f1() { eval(''); }"}, |
9326 {"", "let var1; eval('');"}, | 9337 {"", "let var1; eval('');"}, |
9327 {"", "let var1; function f1() { eval(''); }"}, | 9338 {"", "let var1; function f1() { eval(''); }"}, |
9328 {"", "const var1 = 10; eval('');"}, | 9339 {"", "const var1 = 10; eval('');"}, |
9329 {"", "const var1 = 10; function f1() { eval(''); }"}, | 9340 {"", "const var1 = 10; function f1() { eval(''); }"}, |
9330 | 9341 |
| 9342 // Standard for loops. |
9331 {"", "for (var var1 = 0; var1 < 10; ++var1) { }"}, | 9343 {"", "for (var var1 = 0; var1 < 10; ++var1) { }"}, |
9332 {"", "for (let var1 = 0; var1 < 10; ++var1) { }"}, | 9344 {"", "for (let var1 = 0; var1 < 10; ++var1) { }"}, |
9333 {"", "for (const var1 = 0; var1 < 10; ++var1) { }"}, | 9345 {"", "for (const var1 = 0; var1 < 10; ++var1) { }"}, |
9334 | 9346 |
9335 {"", | 9347 {"", |
9336 "for (var var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, | 9348 "for (var var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, |
9337 {"", | 9349 {"", |
9338 "for (let var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, | 9350 "for (let var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, |
9339 {"", | 9351 {"", |
9340 "for (const var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, | 9352 "for (const var1 = 0; var1 < 10; ++var1) { function foo() { var1; } }"}, |
9341 {"", | 9353 {"", |
9342 "'use strict'; for (var var1 = 0; var1 < 10; ++var1) { function foo() { " | 9354 "'use strict'; for (var var1 = 0; var1 < 10; ++var1) { function foo() { " |
9343 "var1; } }"}, | 9355 "var1; } }"}, |
9344 {"", | 9356 {"", |
9345 "'use strict'; for (let var1 = 0; var1 < 10; ++var1) { function foo() { " | 9357 "'use strict'; for (let var1 = 0; var1 < 10; ++var1) { function foo() { " |
9346 "var1; } }"}, | 9358 "var1; } }"}, |
9347 {"", | 9359 {"", |
9348 "'use strict'; for (const var1 = 0; var1 < 10; ++var1) { function foo() " | 9360 "'use strict'; for (const var1 = 0; var1 < 10; ++var1) { function foo() " |
9349 "{ var1; } }"}, | 9361 "{ var1; } }"}, |
9350 | 9362 |
| 9363 // For of loops |
| 9364 {"", "for (var1 of [1, 2]) { }"}, |
| 9365 {"", "for (var var1 of [1, 2]) { }"}, |
| 9366 {"", "for (let var1 of [1, 2]) { }"}, |
| 9367 {"", "for (const var1 of [1, 2]) { }"}, |
| 9368 |
| 9369 {"", "for (var1 of [1, 2]) { var1; }"}, |
| 9370 {"", "for (var var1 of [1, 2]) { var1; }"}, |
| 9371 {"", "for (let var1 of [1, 2]) { var1; }"}, |
| 9372 {"", "for (const var1 of [1, 2]) { var1; }"}, |
| 9373 |
| 9374 {"", "for (var1 of [1, 2]) { var1 = 0; }"}, |
| 9375 {"", "for (var var1 of [1, 2]) { var1 = 0; }"}, |
| 9376 {"", "for (let var1 of [1, 2]) { var1 = 0; }"}, |
| 9377 {"", "for (const var1 of [1, 2]) { var1 = 0; }"}, |
| 9378 |
| 9379 {"", "for (var1 of [1, 2]) { function foo() { var1; } }"}, |
| 9380 {"", "for (var var1 of [1, 2]) { function foo() { var1; } }"}, |
| 9381 {"", "for (let var1 of [1, 2]) { function foo() { var1; } }"}, |
| 9382 {"", "for (const var1 of [1, 2]) { function foo() { var1; } }"}, |
| 9383 |
| 9384 {"", "for (var1 of [1, 2]) { function foo() { var1 = 0; } }"}, |
| 9385 {"", "for (var var1 of [1, 2]) { function foo() { var1 = 0; } }"}, |
| 9386 {"", "for (let var1 of [1, 2]) { function foo() { var1 = 0; } }"}, |
| 9387 {"", "for (const var1 of [1, 2]) { function foo() { var1 = 0; } }"}, |
| 9388 |
| 9389 // For in loops |
| 9390 {"", "for (var1 in {a: 6}) { }"}, |
| 9391 {"", "for (var var1 in {a: 6}) { }"}, |
| 9392 {"", "for (let var1 in {a: 6}) { }"}, |
| 9393 {"", "for (const var1 in {a: 6}) { }"}, |
| 9394 |
| 9395 {"", "for (var1 in {a: 6}) { var1; }"}, |
| 9396 {"", "for (var var1 in {a: 6}) { var1; }"}, |
| 9397 {"", "for (let var1 in {a: 6}) { var1; }"}, |
| 9398 {"", "for (const var1 in {a: 6}) { var1; }"}, |
| 9399 |
| 9400 {"", "for (var1 in {a: 6}) { var1 = 0; }"}, |
| 9401 {"", "for (var var1 in {a: 6}) { var1 = 0; }"}, |
| 9402 {"", "for (let var1 in {a: 6}) { var1 = 0; }"}, |
| 9403 {"", "for (const var1 in {a: 6}) { var1 = 0; }"}, |
| 9404 |
| 9405 {"", "for (var1 in {a: 6}) { function foo() { var1; } }"}, |
| 9406 {"", "for (var var1 in {a: 6}) { function foo() { var1; } }"}, |
| 9407 {"", "for (let var1 in {a: 6}) { function foo() { var1; } }"}, |
| 9408 {"", "for (const var1 in {a: 6}) { function foo() { var1; } }"}, |
| 9409 |
| 9410 {"", "for (var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9411 {"", "for (var var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9412 {"", "for (let var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9413 {"", "for (const var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9414 |
| 9415 {"", "for (var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9416 {"", "for (var var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9417 {"", "for (let var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9418 {"", "for (const var1 in {a: 6}) { function foo() { var1 = 0; } }"}, |
| 9419 |
| 9420 // Loops without declarations |
| 9421 {"", "var var1 = 0; for ( ; var1 < 2; ++var1) { }"}, |
| 9422 {"", |
| 9423 "var var1 = 0; for ( ; var1 < 2; ++var1) { function foo() { var1; } }"}, |
| 9424 {"", "var var1 = 0; for ( ; var1 > 2; ) { }"}, |
| 9425 {"", "var var1 = 0; for ( ; var1 > 2; ) { function foo() { var1; } }"}, |
| 9426 {"", |
| 9427 "var var1 = 0; for ( ; var1 > 2; ) { function foo() { var1 = 6; } }"}, |
| 9428 |
| 9429 {"", "var var1 = 0; for(var1; var1 < 2; ++var1) { }"}, |
| 9430 {"", |
| 9431 "var var1 = 0; for (var1; var1 < 2; ++var1) { function foo() { var1; } " |
| 9432 "}"}, |
| 9433 {"", "var var1 = 0; for (var1; var1 > 2; ) { }"}, |
| 9434 {"", "var var1 = 0; for (var1; var1 > 2; ) { function foo() { var1; } }"}, |
| 9435 {"", |
| 9436 "var var1 = 0; for (var1; var1 > 2; ) { function foo() { var1 = 6; } }"}, |
| 9437 |
| 9438 // FIXME(marja): Add test cases for special variables (this, arguments |
| 9439 // etc) referred to in the for loop conditions. |
| 9440 |
| 9441 // Sloppy block functions. |
9351 {"", "if (true) { function f1() {} }"}, | 9442 {"", "if (true) { function f1() {} }"}, |
9352 {"", "if (true) { function f1() {} function f1() {} }"}, | 9443 {"", "if (true) { function f1() {} function f1() {} }"}, |
9353 {"", "if (true) { if (true) { function f1() {} } }"}, | 9444 {"", "if (true) { if (true) { function f1() {} } }"}, |
9354 {"", "if (true) { if (true) { function f1() {} function f1() {} } }"}, | 9445 {"", "if (true) { if (true) { function f1() {} function f1() {} } }"}, |
9355 {"", "if (true) { function f1() {} f1 = 3; }"}, | 9446 {"", "if (true) { function f1() {} f1 = 3; }"}, |
9356 | 9447 |
9357 {"", "if (true) { function f1() {} function foo() { f1; } }"}, | 9448 {"", "if (true) { function f1() {} function foo() { f1; } }"}, |
9358 {"", "if (true) { function f1() {} } function foo() { f1; }"}, | 9449 {"", "if (true) { function f1() {} } function foo() { f1; }"}, |
9359 {"", | 9450 {"", |
9360 "if (true) { function f1() {} function f1() {} function foo() { f1; } " | 9451 "if (true) { function f1() {} function f1() {} function foo() { f1; } " |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9437 eager_info.literal()->scope()->inner_scope()->inner_scope(); | 9528 eager_info.literal()->scope()->inner_scope()->inner_scope(); |
9438 DCHECK_NOT_NULL(scope); | 9529 DCHECK_NOT_NULL(scope); |
9439 DCHECK_NULL(scope->sibling()); | 9530 DCHECK_NULL(scope->sibling()); |
9440 DCHECK(scope->is_function_scope()); | 9531 DCHECK(scope->is_function_scope()); |
9441 | 9532 |
9442 size_t index = 0; | 9533 size_t index = 0; |
9443 i::ScopeTestHelper::CompareScopeToData( | 9534 i::ScopeTestHelper::CompareScopeToData( |
9444 scope, lazy_info.preparsed_scope_data(), index); | 9535 scope, lazy_info.preparsed_scope_data(), index); |
9445 } | 9536 } |
9446 } | 9537 } |
OLD | NEW |