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 3255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3266 bool assigned; | 3266 bool assigned; |
3267 bool strict; | 3267 bool strict; |
3268 } outers[] = { | 3268 } outers[] = { |
3269 // Actual assignments. | 3269 // Actual assignments. |
3270 {"var x; var x = 5;", true, false}, | 3270 {"var x; var x = 5;", true, false}, |
3271 {"var x; { var x = 5; }", true, false}, | 3271 {"var x; { var x = 5; }", true, false}, |
3272 {"'use strict'; let x; x = 6;", true, true}, | 3272 {"'use strict'; let x; x = 6;", true, true}, |
3273 {"var x = 5; function x() {}", true, false}, | 3273 {"var x = 5; function x() {}", true, false}, |
3274 {"var x = 4; var x = 5;", true, false}, | 3274 {"var x = 4; var x = 5;", true, false}, |
3275 {"var [x, x] = [4, 5];", true, false}, | 3275 {"var [x, x] = [4, 5];", true, false}, |
| 3276 {"var x; [x, x] = [4, 5];", true, false}, |
3276 {"var {a: x, b: x} = {a: 4, b: 5};", true, false}, | 3277 {"var {a: x, b: x} = {a: 4, b: 5};", true, false}, |
3277 {"var x = {a: 4, b: (x = 5)};", true, false}, | 3278 {"var x = {a: 4, b: (x = 5)};", true, false}, |
3278 {"var {x=1} = {a: 4, b: (x = 5)};", true, false}, | 3279 {"var {x=1} = {a: 4, b: (x = 5)};", true, false}, |
3279 {"var {x} = {x: 4, b: (x = 5)};", true, false}, | 3280 {"var {x} = {x: 4, b: (x = 5)};", true, false}, |
3280 // Actual non-assignments. | 3281 // Actual non-assignments. |
3281 {"var x;", false, false}, | 3282 {"var x;", false, false}, |
3282 {"var x = 5;", false, false}, | 3283 {"var x = 5;", false, false}, |
3283 {"'use strict'; let x;", false, true}, | 3284 {"'use strict'; let x;", false, true}, |
3284 {"'use strict'; let x = 6;", false, true}, | 3285 {"'use strict'; let x = 6;", false, true}, |
3285 {"'use strict'; var x = 0; { let x = 6; }", false, true}, | 3286 {"'use strict'; var x = 0; { let x = 6; }", false, true}, |
3286 {"'use strict'; var x = 0; { let x; x = 6; }", false, true}, | 3287 {"'use strict'; var x = 0; { let x; x = 6; }", false, true}, |
3287 {"'use strict'; let x = 0; { let x = 6; }", false, true}, | 3288 {"'use strict'; let x = 0; { let x = 6; }", false, true}, |
3288 {"'use strict'; let x = 0; { let x; x = 6; }", false, true}, | 3289 {"'use strict'; let x = 0; { let x; x = 6; }", false, true}, |
3289 {"var x; try {} catch (x) { x = 5; }", false, false}, | 3290 {"var x; try {} catch (x) { x = 5; }", false, false}, |
3290 {"function x() {}", false, false}, | 3291 {"function x() {}", false, false}, |
3291 // Eval approximation. | 3292 // Eval approximation. |
3292 {"var x; eval('');", true, false}, | 3293 {"var x; eval('');", true, false}, |
3293 {"eval(''); var x;", true, false}, | 3294 {"eval(''); var x;", true, false}, |
3294 {"'use strict'; let x; eval('');", true, true}, | 3295 {"'use strict'; let x; eval('');", true, true}, |
3295 {"'use strict'; eval(''); let x;", true, true}, | 3296 {"'use strict'; eval(''); let x;", true, true}, |
3296 // Non-assignments not recognized, because the analysis is approximative. | 3297 // Non-assignments not recognized, because the analysis is approximative. |
3297 {"var x; var x;", true, false}, | 3298 {"var x; var x;", true, false}, |
3298 {"var x = 5; var x;", true, false}, | 3299 {"var x = 5; var x;", true, false}, |
3299 {"var x; { var x; }", true, false}, | 3300 {"var x; { var x; }", true, false}, |
3300 {"var x; function x() {}", true, false}, | 3301 {"var x; function x() {}", true, false}, |
3301 {"function x() {}; var x;", true, false}, | 3302 {"function x() {}; var x;", true, false}, |
3302 {"var x; try {} catch (x) { var x = 5; }", true, false}, | 3303 {"var x; try {} catch (x) { var x = 5; }", true, false}, |
3303 }; | 3304 }; |
3304 struct { const char* source; bool assigned; bool with; } inners[] = { | 3305 struct { |
3305 // Actual assignments. | 3306 const char* source; |
3306 { "x = 1;", true, false }, | 3307 bool assigned; |
3307 { "x++;", true, false }, | 3308 bool with; |
3308 { "++x;", true, false }, | 3309 } inners[] = { |
3309 { "x--;", true, false }, | 3310 // Actual assignments. |
3310 { "--x;", true, false }, | 3311 {"x = 1;", true, false}, |
3311 { "{ x = 1; }", true, false }, | 3312 {"x++;", true, false}, |
3312 { "'use strict'; { let x; }; x = 0;", true, false }, | 3313 {"++x;", true, false}, |
3313 { "'use strict'; { const x = 1; }; x = 0;", true, false }, | 3314 {"x--;", true, false}, |
3314 { "'use strict'; { function x() {} }; x = 0;", true, false }, | 3315 {"--x;", true, false}, |
3315 { "with ({}) { x = 1; }", true, true }, | 3316 {"{ x = 1; }", true, false}, |
3316 { "eval('');", true, false }, | 3317 {"'use strict'; { let x; }; x = 0;", true, false}, |
3317 { "'use strict'; { let y; eval('') }", true, false }, | 3318 {"'use strict'; { const x = 1; }; x = 0;", true, false}, |
3318 { "function h() { x = 0; }", true, false }, | 3319 {"'use strict'; { function x() {} }; x = 0;", true, false}, |
3319 { "(function() { x = 0; })", true, false }, | 3320 {"with ({}) { x = 1; }", true, true}, |
3320 { "(function() { x = 0; })", true, false }, | 3321 {"eval('');", true, false}, |
3321 { "with ({}) (function() { x = 0; })", true, true }, | 3322 {"'use strict'; { let y; eval('') }", true, false}, |
3322 // Actual non-assignments. | 3323 {"function h() { x = 0; }", true, false}, |
3323 { "", false, false }, | 3324 {"(function() { x = 0; })", true, false}, |
3324 { "x;", false, false }, | 3325 {"(function() { x = 0; })", true, false}, |
3325 { "var x;", false, false }, | 3326 {"with ({}) (function() { x = 0; })", true, true}, |
3326 { "var x = 8;", false, false }, | 3327 {"for (x of [1,2,3]) {}", true, false}, |
3327 { "var x; x = 8;", false, false }, | 3328 {"for (x in {a: 1}) {}", true, false}, |
3328 { "'use strict'; let x;", false, false }, | 3329 {"for ([x] of [[1],[2],[3]]) {}", true, false}, |
3329 { "'use strict'; let x = 8;", false, false }, | 3330 {"for ([x] in {ab: 1}) {}", true, false}, |
3330 { "'use strict'; let x; x = 8;", false, false }, | 3331 {"for ([...x] in {ab: 1}) {}", true, false}, |
3331 { "'use strict'; const x = 8;", false, false }, | 3332 {"[x] = [1]", true, false}, |
3332 { "function x() {}", false, false }, | 3333 // Actual non-assignments. |
3333 { "function x() { x = 0; }", false, false }, | 3334 {"", false, false}, |
3334 { "function h(x) { x = 0; }", false, false }, | 3335 {"x;", false, false}, |
3335 { "'use strict'; { let x; x = 0; }", false, false }, | 3336 {"var x;", false, false}, |
3336 { "{ var x; }; x = 0;", false, false }, | 3337 {"var x = 8;", false, false}, |
3337 { "with ({}) {}", false, true }, | 3338 {"var x; x = 8;", false, false}, |
3338 { "var x; { with ({}) { x = 1; } }", false, true }, | 3339 {"'use strict'; let x;", false, false}, |
3339 { "try {} catch(x) { x = 0; }", false, false }, | 3340 {"'use strict'; let x = 8;", false, false}, |
3340 { "try {} catch(x) { with ({}) { x = 1; } }", false, true }, | 3341 {"'use strict'; let x; x = 8;", false, false}, |
3341 // Eval approximation. | 3342 {"'use strict'; const x = 8;", false, false}, |
3342 { "eval('');", true, false }, | 3343 {"function x() {}", false, false}, |
3343 { "function h() { eval(''); }", true, false }, | 3344 {"function x() { x = 0; }", false, false}, |
3344 { "(function() { eval(''); })", true, false }, | 3345 {"function h(x) { x = 0; }", false, false}, |
3345 // Shadowing not recognized because of eval approximation. | 3346 {"'use strict'; { let x; x = 0; }", false, false}, |
3346 { "var x; eval('');", true, false }, | 3347 {"{ var x; }; x = 0;", false, false}, |
3347 { "'use strict'; let x; eval('');", true, false }, | 3348 {"with ({}) {}", false, true}, |
3348 { "try {} catch(x) { eval(''); }", true, false }, | 3349 {"var x; { with ({}) { x = 1; } }", false, true}, |
3349 { "function x() { eval(''); }", true, false }, | 3350 {"try {} catch(x) { x = 0; }", false, false}, |
3350 { "(function(x) { eval(''); })", true, false }, | 3351 {"try {} catch(x) { with ({}) { x = 1; } }", false, true}, |
| 3352 // Eval approximation. |
| 3353 {"eval('');", true, false}, |
| 3354 {"function h() { eval(''); }", true, false}, |
| 3355 {"(function() { eval(''); })", true, false}, |
| 3356 // Shadowing not recognized because of eval approximation. |
| 3357 {"var x; eval('');", true, false}, |
| 3358 {"'use strict'; let x; eval('');", true, false}, |
| 3359 {"try {} catch(x) { eval(''); }", true, false}, |
| 3360 {"function x() { eval(''); }", true, false}, |
| 3361 {"(function(x) { eval(''); })", true, false}, |
3351 }; | 3362 }; |
3352 | 3363 |
3353 int prefix_len = Utf8LengthHelper(prefix); | 3364 int prefix_len = Utf8LengthHelper(prefix); |
3354 int midfix_len = Utf8LengthHelper(midfix); | 3365 int midfix_len = Utf8LengthHelper(midfix); |
3355 int suffix_len = Utf8LengthHelper(suffix); | 3366 int suffix_len = Utf8LengthHelper(suffix); |
3356 for (unsigned i = 0; i < arraysize(outers); ++i) { | 3367 for (unsigned i = 0; i < arraysize(outers); ++i) { |
3357 const char* outer = outers[i].source; | 3368 const char* outer = outers[i].source; |
3358 int outer_len = Utf8LengthHelper(outer); | 3369 int outer_len = Utf8LengthHelper(outer); |
3359 for (unsigned j = 0; j < arraysize(inners); ++j) { | 3370 for (unsigned j = 0; j < arraysize(inners); ++j) { |
3360 for (unsigned lazy = 0; lazy < 2; ++lazy) { | 3371 for (unsigned lazy = 0; lazy < 2; ++lazy) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3403 i::Variable* var = scope->Lookup(var_name); | 3414 i::Variable* var = scope->Lookup(var_name); |
3404 bool expected = outers[i].assigned || inners[j].assigned; | 3415 bool expected = outers[i].assigned || inners[j].assigned; |
3405 CHECK(var != NULL); | 3416 CHECK(var != NULL); |
3406 CHECK(var->is_used() || !expected); | 3417 CHECK(var->is_used() || !expected); |
3407 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3418 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
3408 if (i::FLAG_lazy_inner_functions) { | 3419 if (i::FLAG_lazy_inner_functions) { |
3409 // If we parse inner functions lazily, allow being pessimistic about | 3420 // If we parse inner functions lazily, allow being pessimistic about |
3410 // maybe_assigned. | 3421 // maybe_assigned. |
3411 CHECK(is_maybe_assigned || (is_maybe_assigned == expected)); | 3422 CHECK(is_maybe_assigned || (is_maybe_assigned == expected)); |
3412 } else { | 3423 } else { |
3413 CHECK(is_maybe_assigned == expected); | 3424 CHECK_EQ(is_maybe_assigned, expected); |
3414 } | 3425 } |
3415 } | 3426 } |
3416 } | 3427 } |
3417 } | 3428 } |
3418 } | 3429 } |
3419 | 3430 |
3420 namespace { | 3431 namespace { |
3421 | 3432 |
3422 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, | 3433 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, |
3423 i::Handle<i::JSObject> m, const char* name) { | 3434 i::Handle<i::JSObject> m, const char* name) { |
(...skipping 5122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8546 DCHECK_NOT_NULL(scope); | 8557 DCHECK_NOT_NULL(scope); |
8547 DCHECK_NULL(scope->sibling()); | 8558 DCHECK_NULL(scope->sibling()); |
8548 DCHECK(scope->is_function_scope()); | 8559 DCHECK(scope->is_function_scope()); |
8549 const i::AstRawString* var_name = | 8560 const i::AstRawString* var_name = |
8550 info.ast_value_factory()->GetOneByteString("my_var"); | 8561 info.ast_value_factory()->GetOneByteString("my_var"); |
8551 i::Variable* var = scope->Lookup(var_name); | 8562 i::Variable* var = scope->Lookup(var_name); |
8552 CHECK_EQ(inners[i].ctxt_allocate, | 8563 CHECK_EQ(inners[i].ctxt_allocate, |
8553 i::ScopeTestHelper::MustAllocateInContext(var)); | 8564 i::ScopeTestHelper::MustAllocateInContext(var)); |
8554 } | 8565 } |
8555 } | 8566 } |
OLD | NEW |