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 3269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3280 { "'use strict'; let x; eval('');", true, true }, | 3280 { "'use strict'; let x; eval('');", true, true }, |
3281 { "'use strict'; eval(''); let x;", true, true }, | 3281 { "'use strict'; eval(''); let x;", true, true }, |
3282 // Non-assignments not recognized, because the analysis is approximative. | 3282 // Non-assignments not recognized, because the analysis is approximative. |
3283 { "var x; var x;", true, false }, | 3283 { "var x; var x;", true, false }, |
3284 { "var x = 5; var x;", true, false }, | 3284 { "var x = 5; var x;", true, false }, |
3285 { "var x; { var x; }", true, false }, | 3285 { "var x; { var x; }", true, false }, |
3286 { "var x; function x() {}", true, false }, | 3286 { "var x; function x() {}", true, false }, |
3287 { "function x() {}; var x;", true, false }, | 3287 { "function x() {}; var x;", true, false }, |
3288 { "var x; try {} catch (x) { var x = 5; }", true, false }, | 3288 { "var x; try {} catch (x) { var x = 5; }", true, false }, |
3289 }; | 3289 }; |
3290 struct { const char* source; bool assigned; bool with; } inners[] = { | 3290 |
3291 // Actual assignments. | 3291 // If allow_error_in_inner_function is true, we allow a lazy inner function to |
3292 { "x = 1;", true, false }, | 3292 // pessimistically set maybe_assigned to true even if there's no assignment. |
3293 { "x++;", true, false }, | 3293 // FIXME(marja): remove it when no longer needed. |
3294 { "++x;", true, false }, | 3294 struct { |
3295 { "x--;", true, false }, | 3295 const char* source; |
3296 { "--x;", true, false }, | 3296 bool assigned; |
3297 { "{ x = 1; }", true, false }, | 3297 bool with; |
3298 { "'use strict'; { let x; }; x = 0;", true, false }, | 3298 bool allow_error_in_inner_function; |
3299 { "'use strict'; { const x = 1; }; x = 0;", true, false }, | 3299 } inners[] = { |
3300 { "'use strict'; { function x() {} }; x = 0;", true, false }, | 3300 // Actual assignments. |
3301 { "with ({}) { x = 1; }", true, true }, | 3301 {"x = 1;", true, false, false}, |
3302 { "eval('');", true, false }, | 3302 {"x++;", true, false, false}, |
3303 { "'use strict'; { let y; eval('') }", true, false }, | 3303 {"++x;", true, false, false}, |
3304 { "function h() { x = 0; }", true, false }, | 3304 {"x--;", true, false, false}, |
3305 { "(function() { x = 0; })", true, false }, | 3305 {"--x;", true, false, false}, |
3306 { "(function() { x = 0; })", true, false }, | 3306 {"{ x = 1; }", true, false, false}, |
3307 { "with ({}) (function() { x = 0; })", true, true }, | 3307 {"'use strict'; { let x; }; x = 0;", true, false, false}, |
3308 // Actual non-assignments. | 3308 {"'use strict'; { const x = 1; }; x = 0;", true, false, false}, |
3309 { "", false, false }, | 3309 {"'use strict'; { function x() {} }; x = 0;", true, false, false}, |
3310 { "x;", false, false }, | 3310 {"with ({}) { x = 1; }", true, true, false}, |
3311 { "var x;", false, false }, | 3311 {"eval('');", true, false, false}, |
3312 { "var x = 8;", false, false }, | 3312 {"'use strict'; { let y; eval('') }", true, false, false}, |
3313 { "var x; x = 8;", false, false }, | 3313 {"function h() { x = 0; }", true, false, false}, |
3314 { "'use strict'; let x;", false, false }, | 3314 {"(function() { x = 0; })", true, false, false}, |
3315 { "'use strict'; let x = 8;", false, false }, | 3315 {"(function() { x = 0; })", true, false, false}, |
3316 { "'use strict'; let x; x = 8;", false, false }, | 3316 {"with ({}) (function() { x = 0; })", true, true, false}, |
3317 { "'use strict'; const x = 8;", false, false }, | 3317 // Actual non-assignments. |
3318 { "function x() {}", false, false }, | 3318 {"", false, false, false}, |
3319 { "function x() { x = 0; }", false, false }, | 3319 {"x;", false, false, false}, |
3320 { "function h(x) { x = 0; }", false, false }, | 3320 {"var x;", false, false, false}, |
3321 { "'use strict'; { let x; x = 0; }", false, false }, | 3321 {"var x = 8;", false, false, false}, |
3322 { "{ var x; }; x = 0;", false, false }, | 3322 {"var x; x = 8;", false, false, false}, |
3323 { "with ({}) {}", false, true }, | 3323 {"'use strict'; let x;", false, false, false}, |
3324 { "var x; { with ({}) { x = 1; } }", false, true }, | 3324 {"'use strict'; let x = 8;", false, false, false}, |
3325 { "try {} catch(x) { x = 0; }", false, false }, | 3325 {"'use strict'; let x; x = 8;", false, false, false}, |
3326 { "try {} catch(x) { with ({}) { x = 1; } }", false, true }, | 3326 {"'use strict'; const x = 8;", false, false, false}, |
3327 // Eval approximation. | 3327 {"function x() {}", false, false, false}, |
3328 { "eval('');", true, false }, | 3328 {"function x() { x = 0; }", false, false, true}, |
3329 { "function h() { eval(''); }", true, false }, | 3329 {"function h(x) { x = 0; }", false, false, false}, |
3330 { "(function() { eval(''); })", true, false }, | 3330 {"'use strict'; { let x; x = 0; }", false, false, false}, |
3331 // Shadowing not recognized because of eval approximation. | 3331 {"{ var x; }; x = 0;", false, false, false}, |
3332 { "var x; eval('');", true, false }, | 3332 {"with ({}) {}", false, true, false}, |
3333 { "'use strict'; let x; eval('');", true, false }, | 3333 {"var x; { with ({}) { x = 1; } }", false, true, false}, |
3334 { "try {} catch(x) { eval(''); }", true, false }, | 3334 {"try {} catch(x) { x = 0; }", false, false, true}, |
3335 { "function x() { eval(''); }", true, false }, | 3335 {"try {} catch(x) { with ({}) { x = 1; } }", false, true, true}, |
3336 { "(function(x) { eval(''); })", true, false }, | 3336 // Eval approximation. |
| 3337 {"eval('');", true, false, false}, |
| 3338 {"function h() { eval(''); }", true, false, false}, |
| 3339 {"(function() { eval(''); })", true, false, false}, |
| 3340 // Shadowing not recognized because of eval approximation. |
| 3341 {"var x; eval('');", true, false, false}, |
| 3342 {"'use strict'; let x; eval('');", true, false, false}, |
| 3343 {"try {} catch(x) { eval(''); }", true, false, false}, |
| 3344 {"function x() { eval(''); }", true, false, false}, |
| 3345 {"(function(x) { eval(''); })", true, false, false}, |
3337 }; | 3346 }; |
3338 | 3347 |
3339 int prefix_len = Utf8LengthHelper(prefix); | 3348 int prefix_len = Utf8LengthHelper(prefix); |
3340 int midfix_len = Utf8LengthHelper(midfix); | 3349 int midfix_len = Utf8LengthHelper(midfix); |
3341 int suffix_len = Utf8LengthHelper(suffix); | 3350 int suffix_len = Utf8LengthHelper(suffix); |
3342 for (unsigned i = 0; i < arraysize(outers); ++i) { | 3351 for (unsigned i = 0; i < arraysize(outers); ++i) { |
3343 const char* outer = outers[i].source; | 3352 const char* outer = outers[i].source; |
3344 int outer_len = Utf8LengthHelper(outer); | 3353 int outer_len = Utf8LengthHelper(outer); |
3345 for (unsigned j = 0; j < arraysize(inners); ++j) { | 3354 for (unsigned j = 0; j < arraysize(inners); ++j) { |
3346 for (unsigned lazy = 0; lazy < 2; ++lazy) { | 3355 for (unsigned lazy = 0; lazy < 2; ++lazy) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 DCHECK_NULL(scope->sibling()); | 3394 DCHECK_NULL(scope->sibling()); |
3386 DCHECK(scope->is_function_scope()); | 3395 DCHECK(scope->is_function_scope()); |
3387 const i::AstRawString* var_name = | 3396 const i::AstRawString* var_name = |
3388 info->ast_value_factory()->GetOneByteString("x"); | 3397 info->ast_value_factory()->GetOneByteString("x"); |
3389 i::Variable* var = scope->Lookup(var_name); | 3398 i::Variable* var = scope->Lookup(var_name); |
3390 bool expected = outers[i].assigned || inners[j].assigned; | 3399 bool expected = outers[i].assigned || inners[j].assigned; |
3391 CHECK(var != NULL); | 3400 CHECK(var != NULL); |
3392 CHECK(var->is_used() || !expected); | 3401 CHECK(var->is_used() || !expected); |
3393 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3402 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
3394 if (i::FLAG_lazy_inner_functions) { | 3403 if (i::FLAG_lazy_inner_functions) { |
3395 // If we parse inner functions lazily, allow being pessimistic about | 3404 CHECK(is_maybe_assigned == expected || |
3396 // maybe_assigned. | 3405 (is_maybe_assigned && inners[j].allow_error_in_inner_function)); |
3397 CHECK(is_maybe_assigned || (is_maybe_assigned == expected)); | |
3398 } else { | 3406 } else { |
3399 CHECK(is_maybe_assigned == expected); | 3407 CHECK(is_maybe_assigned == expected); |
3400 } | 3408 } |
3401 } | 3409 } |
3402 } | 3410 } |
3403 } | 3411 } |
3404 } | 3412 } |
3405 | 3413 |
3406 namespace { | 3414 namespace { |
3407 | 3415 |
(...skipping 5096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8504 DCHECK_NOT_NULL(scope); | 8512 DCHECK_NOT_NULL(scope); |
8505 DCHECK_NULL(scope->sibling()); | 8513 DCHECK_NULL(scope->sibling()); |
8506 DCHECK(scope->is_function_scope()); | 8514 DCHECK(scope->is_function_scope()); |
8507 const i::AstRawString* var_name = | 8515 const i::AstRawString* var_name = |
8508 info.ast_value_factory()->GetOneByteString("my_var"); | 8516 info.ast_value_factory()->GetOneByteString("my_var"); |
8509 i::Variable* var = scope->Lookup(var_name); | 8517 i::Variable* var = scope->Lookup(var_name); |
8510 CHECK_EQ(inners[i].ctxt_allocate, | 8518 CHECK_EQ(inners[i].ctxt_allocate, |
8511 i::ScopeTestHelper::MustAllocateInContext(var)); | 8519 i::ScopeTestHelper::MustAllocateInContext(var)); |
8512 } | 8520 } |
8513 } | 8521 } |
OLD | NEW |