| 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 3284 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3295       {"'use strict'; let x; eval('');", true, true}, |  3295       {"'use strict'; let x; eval('');", true, true}, | 
|  3296       {"'use strict'; eval(''); let x;", true, true}, |  3296       {"'use strict'; eval(''); let x;", true, true}, | 
|  3297       // Non-assignments not recognized, because the analysis is approximative. |  3297       // Non-assignments not recognized, because the analysis is approximative. | 
|  3298       {"var x; var x;", true, false}, |  3298       {"var x; var x;", true, false}, | 
|  3299       {"var x = 5; var x;", true, false}, |  3299       {"var x = 5; var x;", true, false}, | 
|  3300       {"var x; { var x; }", true, false}, |  3300       {"var x; { var x; }", true, false}, | 
|  3301       {"var x; function x() {}", true, false}, |  3301       {"var x; function x() {}", true, false}, | 
|  3302       {"function x() {}; var x;", true, false}, |  3302       {"function x() {}; var x;", true, false}, | 
|  3303       {"var x; try {} catch (x) { var x = 5; }", true, false}, |  3303       {"var x; try {} catch (x) { var x = 5; }", true, false}, | 
|  3304   }; |  3304   }; | 
 |  3305  | 
 |  3306   // We set allow_error_in_inner_function to true in cases where our handling of | 
 |  3307   // assigned variables in lazy inner functions is currently overly pessimistic. | 
 |  3308   // FIXME(marja): remove it when no longer needed. | 
|  3305   struct { |  3309   struct { | 
|  3306     const char* source; |  3310     const char* source; | 
|  3307     bool assigned; |  3311     bool assigned; | 
|  3308     bool with; |  3312     bool with; | 
 |  3313     bool allow_error_in_inner_function; | 
|  3309   } inners[] = { |  3314   } inners[] = { | 
|  3310       // Actual assignments. |  3315       // Actual assignments. | 
|  3311       {"x = 1;", true, false}, |  3316       {"x = 1;", true, false, false}, | 
|  3312       {"x++;", true, false}, |  3317       {"x++;", true, false, false}, | 
|  3313       {"++x;", true, false}, |  3318       {"++x;", true, false, false}, | 
|  3314       {"x--;", true, false}, |  3319       {"x--;", true, false, false}, | 
|  3315       {"--x;", true, false}, |  3320       {"--x;", true, false, false}, | 
|  3316       {"{ x = 1; }", true, false}, |  3321       {"{ x = 1; }", true, false, false}, | 
|  3317       {"'use strict'; { let x; }; x = 0;", true, false}, |  3322       {"'use strict'; { let x; }; x = 0;", true, false, false}, | 
|  3318       {"'use strict'; { const x = 1; }; x = 0;", true, false}, |  3323       {"'use strict'; { const x = 1; }; x = 0;", true, false, false}, | 
|  3319       {"'use strict'; { function x() {} }; x = 0;", true, false}, |  3324       {"'use strict'; { function x() {} }; x = 0;", true, false, false}, | 
|  3320       {"with ({}) { x = 1; }", true, true}, |  3325       {"with ({}) { x = 1; }", true, true, false}, | 
|  3321       {"eval('');", true, false}, |  3326       {"eval('');", true, false, false}, | 
|  3322       {"'use strict'; { let y; eval('') }", true, false}, |  3327       {"'use strict'; { let y; eval('') }", true, false, false}, | 
|  3323       {"function h() { x = 0; }", true, false}, |  3328       {"function h() { x = 0; }", true, false, false}, | 
|  3324       {"(function() { x = 0; })", true, false}, |  3329       {"(function() { x = 0; })", true, false, false}, | 
|  3325       {"(function() { x = 0; })", true, false}, |  3330       {"(function() { x = 0; })", true, false, false}, | 
|  3326       {"with ({}) (function() { x = 0; })", true, true}, |  3331       {"with ({}) (function() { x = 0; })", true, true, false}, | 
|  3327       {"for (x of [1,2,3]) {}", true, false}, |  3332       {"for (x of [1,2,3]) {}", true, false, false}, | 
|  3328       {"for (x in {a: 1}) {}", true, false}, |  3333       {"for (x in {a: 1}) {}", true, false, false}, | 
|  3329       {"for ([x] of [[1],[2],[3]]) {}", true, false}, |  3334       {"for ([x] of [[1],[2],[3]]) {}", true, false, false}, | 
|  3330       {"for ([x] in {ab: 1}) {}", true, false}, |  3335       {"for ([x] in {ab: 1}) {}", true, false, false}, | 
|  3331       {"for ([...x] in {ab: 1}) {}", true, false}, |  3336       {"for ([...x] in {ab: 1}) {}", true, false, false}, | 
|  3332       {"[x] = [1]", true, false}, |  3337       {"[x] = [1]", true, false, false}, | 
|  3333       // Actual non-assignments. |  3338       // Actual non-assignments. | 
|  3334       {"", false, false}, |  3339       {"", false, false, false}, | 
|  3335       {"x;", false, false}, |  3340       {"x;", false, false, false}, | 
|  3336       {"var x;", false, false}, |  3341       {"var x;", false, false, false}, | 
|  3337       {"var x = 8;", false, false}, |  3342       {"var x = 8;", false, false, false}, | 
|  3338       {"var x; x = 8;", false, false}, |  3343       {"var x; x = 8;", false, false, false}, | 
|  3339       {"'use strict'; let x;", false, false}, |  3344       {"'use strict'; let x;", false, false, false}, | 
|  3340       {"'use strict'; let x = 8;", false, false}, |  3345       {"'use strict'; let x = 8;", false, false, false}, | 
|  3341       {"'use strict'; let x; x = 8;", false, false}, |  3346       {"'use strict'; let x; x = 8;", false, false, false}, | 
|  3342       {"'use strict'; const x = 8;", false, false}, |  3347       {"'use strict'; const x = 8;", false, false, false}, | 
|  3343       {"function x() {}", false, false}, |  3348       {"function x() {}", false, false, false}, | 
|  3344       {"function x() { x = 0; }", false, false}, |  3349       {"function x() { x = 0; }", false, false, true}, | 
|  3345       {"function h(x) { x = 0; }", false, false}, |  3350       {"function h(x) { x = 0; }", false, false, false}, | 
|  3346       {"'use strict'; { let x; x = 0; }", false, false}, |  3351       {"'use strict'; { let x; x = 0; }", false, false, false}, | 
|  3347       {"{ var x; }; x = 0;", false, false}, |  3352       {"{ var x; }; x = 0;", false, false, false}, | 
|  3348       {"with ({}) {}", false, true}, |  3353       {"with ({}) {}", false, true, false}, | 
|  3349       {"var x; { with ({}) { x = 1; } }", false, true}, |  3354       {"var x; { with ({}) { x = 1; } }", false, true, false}, | 
|  3350       {"try {} catch(x) { x = 0; }", false, false}, |  3355       {"try {} catch(x) { x = 0; }", false, false, true}, | 
|  3351       {"try {} catch(x) { with ({}) { x = 1; } }", false, true}, |  3356       {"try {} catch(x) { with ({}) { x = 1; } }", false, true, true}, | 
|  3352       // Eval approximation. |  3357       // Eval approximation. | 
|  3353       {"eval('');", true, false}, |  3358       {"eval('');", true, false, false}, | 
|  3354       {"function h() { eval(''); }", true, false}, |  3359       {"function h() { eval(''); }", true, false, false}, | 
|  3355       {"(function() { eval(''); })", true, false}, |  3360       {"(function() { eval(''); })", true, false, false}, | 
|  3356       // Shadowing not recognized because of eval approximation. |  3361       // Shadowing not recognized because of eval approximation. | 
|  3357       {"var x; eval('');", true, false}, |  3362       {"var x; eval('');", true, false, false}, | 
|  3358       {"'use strict'; let x; eval('');", true, false}, |  3363       {"'use strict'; let x; eval('');", true, false, false}, | 
|  3359       {"try {} catch(x) { eval(''); }", true, false}, |  3364       {"try {} catch(x) { eval(''); }", true, false, false}, | 
|  3360       {"function x() { eval(''); }", true, false}, |  3365       {"function x() { eval(''); }", true, false, false}, | 
|  3361       {"(function(x) { eval(''); })", true, false}, |  3366       {"(function(x) { eval(''); })", true, false, false}, | 
|  3362   }; |  3367   }; | 
|  3363  |  3368  | 
|  3364   int prefix_len = Utf8LengthHelper(prefix); |  3369   int prefix_len = Utf8LengthHelper(prefix); | 
|  3365   int midfix_len = Utf8LengthHelper(midfix); |  3370   int midfix_len = Utf8LengthHelper(midfix); | 
|  3366   int suffix_len = Utf8LengthHelper(suffix); |  3371   int suffix_len = Utf8LengthHelper(suffix); | 
|  3367   for (unsigned i = 0; i < arraysize(outers); ++i) { |  3372   for (unsigned i = 0; i < arraysize(outers); ++i) { | 
|  3368     const char* outer = outers[i].source; |  3373     const char* outer = outers[i].source; | 
|  3369     int outer_len = Utf8LengthHelper(outer); |  3374     int outer_len = Utf8LengthHelper(outer); | 
|  3370     for (unsigned j = 0; j < arraysize(inners); ++j) { |  3375     for (unsigned j = 0; j < arraysize(inners); ++j) { | 
|  3371       for (unsigned lazy = 0; lazy < 2; ++lazy) { |  3376       for (unsigned lazy = 0; lazy < 2; ++lazy) { | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3410         DCHECK_NULL(scope->sibling()); |  3415         DCHECK_NULL(scope->sibling()); | 
|  3411         DCHECK(scope->is_function_scope()); |  3416         DCHECK(scope->is_function_scope()); | 
|  3412         const i::AstRawString* var_name = |  3417         const i::AstRawString* var_name = | 
|  3413             info->ast_value_factory()->GetOneByteString("x"); |  3418             info->ast_value_factory()->GetOneByteString("x"); | 
|  3414         i::Variable* var = scope->Lookup(var_name); |  3419         i::Variable* var = scope->Lookup(var_name); | 
|  3415         bool expected = outers[i].assigned || inners[j].assigned; |  3420         bool expected = outers[i].assigned || inners[j].assigned; | 
|  3416         CHECK(var != NULL); |  3421         CHECK(var != NULL); | 
|  3417         CHECK(var->is_used() || !expected); |  3422         CHECK(var->is_used() || !expected); | 
|  3418         bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |  3423         bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 
|  3419         if (i::FLAG_lazy_inner_functions) { |  3424         if (i::FLAG_lazy_inner_functions) { | 
|  3420           // If we parse inner functions lazily, allow being pessimistic about |  3425           CHECK(is_maybe_assigned == expected || | 
|  3421           // maybe_assigned. |  3426                 (is_maybe_assigned && inners[j].allow_error_in_inner_function)); | 
|  3422           CHECK(is_maybe_assigned || (is_maybe_assigned == expected)); |  | 
|  3423         } else { |  3427         } else { | 
|  3424           CHECK_EQ(is_maybe_assigned, expected); |  3428           CHECK_EQ(is_maybe_assigned, expected); | 
|  3425         } |  3429         } | 
|  3426       } |  3430       } | 
|  3427     } |  3431     } | 
|  3428   } |  3432   } | 
|  3429 } |  3433 } | 
|  3430  |  3434  | 
|  3431 namespace { |  3435 namespace { | 
|  3432  |  3436  | 
| (...skipping 5124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  8557     DCHECK_NOT_NULL(scope); |  8561     DCHECK_NOT_NULL(scope); | 
|  8558     DCHECK_NULL(scope->sibling()); |  8562     DCHECK_NULL(scope->sibling()); | 
|  8559     DCHECK(scope->is_function_scope()); |  8563     DCHECK(scope->is_function_scope()); | 
|  8560     const i::AstRawString* var_name = |  8564     const i::AstRawString* var_name = | 
|  8561         info.ast_value_factory()->GetOneByteString("my_var"); |  8565         info.ast_value_factory()->GetOneByteString("my_var"); | 
|  8562     i::Variable* var = scope->Lookup(var_name); |  8566     i::Variable* var = scope->Lookup(var_name); | 
|  8563     CHECK_EQ(inners[i].ctxt_allocate, |  8567     CHECK_EQ(inners[i].ctxt_allocate, | 
|  8564              i::ScopeTestHelper::MustAllocateInContext(var)); |  8568              i::ScopeTestHelper::MustAllocateInContext(var)); | 
|  8565   } |  8569   } | 
|  8566 } |  8570 } | 
| OLD | NEW |