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 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3254 | 3254 |
3255 TEST(InnerAssignment) { | 3255 TEST(InnerAssignment) { |
3256 i::Isolate* isolate = CcTest::i_isolate(); | 3256 i::Isolate* isolate = CcTest::i_isolate(); |
3257 i::Factory* factory = isolate->factory(); | 3257 i::Factory* factory = isolate->factory(); |
3258 i::HandleScope scope(isolate); | 3258 i::HandleScope scope(isolate); |
3259 LocalContext env; | 3259 LocalContext env; |
3260 | 3260 |
3261 const char* prefix = "function f() {"; | 3261 const char* prefix = "function f() {"; |
3262 const char* midfix = " function g() {"; | 3262 const char* midfix = " function g() {"; |
3263 const char* suffix = "}}; f"; | 3263 const char* suffix = "}}; f"; |
3264 struct { const char* source; bool assigned; bool strict; } outers[] = { | 3264 struct { |
3265 // Actual assignments. | 3265 const char* source; |
3266 { "var x; var x = 5;", true, false }, | 3266 bool assigned; |
3267 { "var x; { var x = 5; }", true, false }, | 3267 bool strict; |
3268 { "'use strict'; let x; x = 6;", true, true }, | 3268 } outers[] = { |
3269 { "var x = 5; function x() {}", true, false }, | 3269 // Actual assignments. |
3270 // Actual non-assignments. | 3270 {"var x; var x = 5;", true, false}, |
3271 { "var x;", false, false }, | 3271 {"var x; { var x = 5; }", true, false}, |
3272 { "var x = 5;", false, false }, | 3272 {"'use strict'; let x; x = 6;", true, true}, |
3273 { "'use strict'; let x;", false, true }, | 3273 {"var x = 5; function x() {}", true, false}, |
3274 { "'use strict'; let x = 6;", false, true }, | 3274 {"var x = 4; var x = 5;", true, false}, |
3275 { "'use strict'; var x = 0; { let x = 6; }", false, true }, | 3275 {"var [x, x] = [4, 5];", true, false}, |
3276 { "'use strict'; var x = 0; { let x; x = 6; }", false, true }, | 3276 {"var {a: x, b: x} = {a: 4, b: 5};", true, false}, |
3277 { "'use strict'; let x = 0; { let x = 6; }", false, true }, | 3277 {"var x = {a: 4, b: (x = 5)};", true, false}, |
3278 { "'use strict'; let x = 0; { let x; x = 6; }", false, true }, | 3278 {"var {x=1} = {a: 4, b: (x = 5)};", true, false}, |
3279 { "var x; try {} catch (x) { x = 5; }", false, false }, | 3279 {"var {x} = {x: 4, b: (x = 5)};", true, false}, |
3280 { "function x() {}", false, false }, | 3280 // Actual non-assignments. |
3281 // Eval approximation. | 3281 {"var x;", false, false}, |
3282 { "var x; eval('');", true, false }, | 3282 {"var x = 5;", false, false}, |
3283 { "eval(''); var x;", true, false }, | 3283 {"'use strict'; let x;", false, true}, |
3284 { "'use strict'; let x; eval('');", true, true }, | 3284 {"'use strict'; let x = 6;", false, true}, |
3285 { "'use strict'; eval(''); let x;", true, true }, | 3285 {"'use strict'; var x = 0; { let x = 6; }", false, true}, |
3286 // Non-assignments not recognized, because the analysis is approximative. | 3286 {"'use strict'; var x = 0; { let x; x = 6; }", false, true}, |
3287 { "var x; var x;", true, false }, | 3287 {"'use strict'; let x = 0; { let x = 6; }", false, true}, |
3288 { "var x = 5; var x;", true, false }, | 3288 {"'use strict'; let x = 0; { let x; x = 6; }", false, true}, |
3289 { "var x; { var x; }", true, false }, | 3289 {"var x; try {} catch (x) { x = 5; }", false, false}, |
3290 { "var x; function x() {}", true, false }, | 3290 {"function x() {}", false, false}, |
3291 { "function x() {}; var x;", true, false }, | 3291 // Eval approximation. |
3292 { "var x; try {} catch (x) { var x = 5; }", true, false }, | 3292 {"var x; eval('');", true, false}, |
| 3293 {"eval(''); var x;", true, false}, |
| 3294 {"'use strict'; let x; eval('');", true, true}, |
| 3295 {"'use strict'; eval(''); let x;", true, true}, |
| 3296 // Non-assignments not recognized, because the analysis is approximative. |
| 3297 {"var x; var x;", true, false}, |
| 3298 {"var x = 5; var x;", true, false}, |
| 3299 {"var x; { var x; }", true, false}, |
| 3300 {"var x; function x() {}", true, false}, |
| 3301 {"function x() {}; var x;", true, false}, |
| 3302 {"var x; try {} catch (x) { var x = 5; }", true, false}, |
3293 }; | 3303 }; |
3294 struct { const char* source; bool assigned; bool with; } inners[] = { | 3304 struct { const char* source; bool assigned; bool with; } inners[] = { |
3295 // Actual assignments. | 3305 // Actual assignments. |
3296 { "x = 1;", true, false }, | 3306 { "x = 1;", true, false }, |
3297 { "x++;", true, false }, | 3307 { "x++;", true, false }, |
3298 { "++x;", true, false }, | 3308 { "++x;", true, false }, |
3299 { "x--;", true, false }, | 3309 { "x--;", true, false }, |
3300 { "--x;", true, false }, | 3310 { "--x;", true, false }, |
3301 { "{ x = 1; }", true, false }, | 3311 { "{ x = 1; }", true, false }, |
3302 { "'use strict'; { let x; }; x = 0;", true, false }, | 3312 { "'use strict'; { let x; }; x = 0;", true, false }, |
(...skipping 5233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8536 DCHECK_NOT_NULL(scope); | 8546 DCHECK_NOT_NULL(scope); |
8537 DCHECK_NULL(scope->sibling()); | 8547 DCHECK_NULL(scope->sibling()); |
8538 DCHECK(scope->is_function_scope()); | 8548 DCHECK(scope->is_function_scope()); |
8539 const i::AstRawString* var_name = | 8549 const i::AstRawString* var_name = |
8540 info.ast_value_factory()->GetOneByteString("my_var"); | 8550 info.ast_value_factory()->GetOneByteString("my_var"); |
8541 i::Variable* var = scope->Lookup(var_name); | 8551 i::Variable* var = scope->Lookup(var_name); |
8542 CHECK_EQ(inners[i].ctxt_allocate, | 8552 CHECK_EQ(inners[i].ctxt_allocate, |
8543 i::ScopeTestHelper::MustAllocateInContext(var)); | 8553 i::ScopeTestHelper::MustAllocateInContext(var)); |
8544 } | 8554 } |
8545 } | 8555 } |
OLD | NEW |