Chromium Code Reviews| 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 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3432 } | 3432 } |
| 3433 } | 3433 } |
| 3434 | 3434 |
| 3435 TEST(MaybeAssignedParameters) { | 3435 TEST(MaybeAssignedParameters) { |
| 3436 i::Isolate* isolate = CcTest::i_isolate(); | 3436 i::Isolate* isolate = CcTest::i_isolate(); |
| 3437 i::HandleScope scope(isolate); | 3437 i::HandleScope scope(isolate); |
| 3438 LocalContext env; | 3438 LocalContext env; |
| 3439 | 3439 |
| 3440 struct { | 3440 struct { |
| 3441 bool arg_assigned; | 3441 bool arg_assigned; |
| 3442 bool imprecise_when_lazy; | |
| 3442 const char* source; | 3443 const char* source; |
| 3443 } tests[] = { | 3444 } tests[] = { |
| 3444 {false, "function f(arg) {}"}, | 3445 {false, false, "function f(arg) {}"}, |
| 3445 {false, "function f(arg) {g(arg)}"}, | 3446 {false, false, "function f(arg) {g(arg)}"}, |
| 3446 {false, "function f(arg) {function h() { g(arg) }; h()}"}, | 3447 {false, false, "function f(arg) {function h() { g(arg) }; h()}"}, |
| 3447 {false, "function f(arg) {function h() { g(arg) }; return h}"}, | 3448 {false, false, "function f(arg) {function h() { g(arg) }; return h}"}, |
| 3448 {false, "function f(arg=1) {}"}, | 3449 {false, false, "function f(arg=1) {}"}, |
| 3449 {false, "function f(arg=1) {g(arg)}"}, | 3450 {false, false, "function f(arg=1) {g(arg)}"}, |
| 3450 {false, "function f(arg, arguments) {g(arg); arguments[0] = 42; g(arg)}"}, | 3451 {false, false, |
| 3451 {false, | 3452 "function f(arg, arguments) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3453 {false, false, | |
| 3452 "function f(arg, ...arguments) {g(arg); arguments[0] = 42; g(arg)}"}, | 3454 "function f(arg, ...arguments) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3453 {false, | 3455 {false, false, |
| 3454 "function f(arg, arguments=[]) {g(arg); arguments[0] = 42; g(arg)}"}, | 3456 "function f(arg, arguments=[]) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3455 {false, "function f(...arg) {g(arg); arguments[0] = 42; g(arg)}"}, | 3457 {false, false, "function f(...arg) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3458 {false, true, | |
| 3459 "function f(arg) {g(arg); g(function() {arguments[0] = 42}); g(arg)}"}, | |
|
neis
2016/12/16 10:12:54
This test is the reason for adding the imprecise_w
| |
| 3456 | 3460 |
| 3457 // strict arguments object | 3461 // strict arguments object |
| 3458 {false, "function f(arg, x=1) {g(arg); arguments[0] = 42; g(arg)}"}, | 3462 {false, false, |
| 3459 {false, "function f(arg, ...x) {g(arg); arguments[0] = 42; g(arg)}"}, | 3463 "function f(arg, x=1) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3460 {false, "function f(arg=1) {g(arg); arguments[0] = 42; g(arg)}"}, | 3464 {false, false, |
| 3461 {false, | 3465 "function f(arg, ...x) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3466 {false, false, "function f(arg=1) {g(arg); arguments[0] = 42; g(arg)}"}, | |
| 3467 {false, false, | |
| 3462 "function f(arg) {'use strict'; g(arg); arguments[0] = 42; g(arg)}"}, | 3468 "function f(arg) {'use strict'; g(arg); arguments[0] = 42; g(arg)}"}, |
| 3463 {false, "function f(arg) {g(arg); f.arguments[0] = 42; g(arg)}"}, | 3469 {false, false, "function f(arg) {g(arg); f.arguments[0] = 42; g(arg)}"}, |
| 3464 {false, "function f(arg, args=arguments) {g(arg); args[0] = 42; g(arg)}"}, | 3470 {false, false, |
| 3471 "function f(arg, args=arguments) {g(arg); args[0] = 42; g(arg)}"}, | |
| 3465 | 3472 |
| 3466 {true, "function f(arg) {g(arg); arg = 42; g(arg)}"}, | 3473 {true, false, "function f(arg) {g(arg); arg = 42; g(arg)}"}, |
| 3467 {true, "function f(arg) {g(arg); eval('arg = 42'); g(arg)}"}, | 3474 {true, false, "function f(arg) {g(arg); eval('arg = 42'); g(arg)}"}, |
| 3468 {true, "function f(arg) {g(arg); var arg = 42; g(arg)}"}, | 3475 {true, false, "function f(arg) {g(arg); var arg = 42; g(arg)}"}, |
| 3469 {true, "function f(arg, x=1) {g(arg); arg = 42; g(arg)}"}, | 3476 {true, false, "function f(arg, x=1) {g(arg); arg = 42; g(arg)}"}, |
| 3470 {true, "function f(arg, ...x) {g(arg); arg = 42; g(arg)}"}, | 3477 {true, false, "function f(arg, ...x) {g(arg); arg = 42; g(arg)}"}, |
| 3471 {true, "function f(arg=1) {g(arg); arg = 42; g(arg)}"}, | 3478 {true, false, "function f(arg=1) {g(arg); arg = 42; g(arg)}"}, |
| 3472 {true, "function f(arg) {'use strict'; g(arg); arg = 42; g(arg)}"}, | 3479 {true, false, "function f(arg) {'use strict'; g(arg); arg = 42; g(arg)}"}, |
| 3473 {true, "function f(arg, {a=(g(arg), arg=42)}) {g(arg)}"}, | 3480 {true, false, "function f(arg, {a=(g(arg), arg=42)}) {g(arg)}"}, |
| 3474 {true, "function f(arg) {g(arg); g(() => arg = 42); g(arg)}"}, | 3481 {true, false, |
| 3475 {true, "function f(arg) {g(arg); g(() => eval('arg = 42')); g(arg)}"}, | 3482 "function f(arg) {g(arg); g(function() {arg = 42}); g(arg)}"}, |
| 3476 {true, "function f(arg) {g(arg); g(() => arguments[0] = 42); g(arg)}"}, | 3483 {true, false, |
| 3477 {true, "function f(...arg) {g(arg); eval('arg = 42'); g(arg)}"}, | 3484 "function f(arg) {g(arg); g(function() {eval('arg = 42')}); g(arg)}"}, |
| 3485 {true, false, "function f(arg) {g(arg); g(() => arg = 42); g(arg)}"}, | |
| 3486 {true, false, | |
| 3487 "function f(arg) {g(arg); g(() => eval('arg = 42')); g(arg)}"}, | |
| 3488 {true, false, "function f(...arg) {g(arg); eval('arg = 42'); g(arg)}"}, | |
| 3478 | 3489 |
| 3479 // sloppy arguments object | 3490 // sloppy arguments object |
| 3480 {true, "function f(arg) {g(arg); arguments[0] = 42; g(arg)}"}, | 3491 {true, false, "function f(arg) {g(arg); arguments[0] = 42; g(arg)}"}, |
| 3481 {true, "function f(arg) {g(arg); h(arguments); g(arg)}"}, | 3492 {true, false, "function f(arg) {g(arg); h(arguments); g(arg)}"}, |
| 3482 {true, | 3493 {true, false, |
| 3483 "function f(arg) {((args) => {arguments[0] = 42})(arguments); " | 3494 "function f(arg) {((args) => {arguments[0] = 42})(arguments); " |
| 3484 "g(arg)}"}, | 3495 "g(arg)}"}, |
| 3485 {true, "function f(arg) {g(arg); eval('arguments[0] = 42'); g(arg)}"}, | 3496 {true, false, |
| 3497 "function f(arg) {g(arg); eval('arguments[0] = 42'); g(arg)}"}, | |
| 3498 {true, false, | |
| 3499 "function f(arg) {g(arg); g(() => arguments[0] = 42); g(arg)}"}, | |
| 3486 }; | 3500 }; |
| 3487 | 3501 |
| 3488 const char* suffix = "; f"; | 3502 const char* suffix = "; f"; |
| 3489 | 3503 |
| 3490 for (unsigned i = 0; i < arraysize(tests); ++i) { | 3504 for (unsigned i = 0; i < arraysize(tests); ++i) { |
| 3491 bool assigned = tests[i].arg_assigned; | 3505 bool assigned = tests[i].arg_assigned; |
| 3492 const char* source = tests[i].source; | 3506 const char* source = tests[i].source; |
| 3493 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | 3507 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
| 3494 i::ScopedVector<char> program(Utf8LengthHelper(source) + | 3508 i::ScopedVector<char> program(Utf8LengthHelper(source) + |
| 3495 Utf8LengthHelper(suffix) + 1); | 3509 Utf8LengthHelper(suffix) + 1); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3509 | 3523 |
| 3510 i::Scope* scope = info->literal()->scope(); | 3524 i::Scope* scope = info->literal()->scope(); |
| 3511 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | 3525 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
| 3512 CHECK_NULL(scope->sibling()); | 3526 CHECK_NULL(scope->sibling()); |
| 3513 CHECK(scope->is_function_scope()); | 3527 CHECK(scope->is_function_scope()); |
| 3514 const i::AstRawString* var_name = | 3528 const i::AstRawString* var_name = |
| 3515 info->ast_value_factory()->GetOneByteString("arg"); | 3529 info->ast_value_factory()->GetOneByteString("arg"); |
| 3516 i::Variable* var = scope->Lookup(var_name); | 3530 i::Variable* var = scope->Lookup(var_name); |
| 3517 CHECK(var->is_used() || !assigned); | 3531 CHECK(var->is_used() || !assigned); |
| 3518 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3532 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
| 3519 CHECK_EQ(is_maybe_assigned, assigned); | 3533 if (allow_lazy && tests[i].imprecise_when_lazy) { |
| 3534 CHECK_IMPLIES(assigned, is_maybe_assigned); | |
| 3535 } else { | |
| 3536 CHECK_EQ(assigned, is_maybe_assigned); | |
| 3537 } | |
| 3520 } | 3538 } |
| 3521 } | 3539 } |
| 3522 } | 3540 } |
| 3523 | 3541 |
| 3524 namespace { | 3542 namespace { |
| 3525 | 3543 |
| 3526 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, | 3544 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, |
| 3527 i::Handle<i::JSObject> m, const char* name) { | 3545 i::Handle<i::JSObject> m, const char* name) { |
| 3528 i::AstValueFactory avf(zone, isolate->heap()->HashSeed()); | 3546 i::AstValueFactory avf(zone, isolate->heap()->HashSeed()); |
| 3529 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast( | 3547 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast( |
| (...skipping 5165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8695 DCHECK_NOT_NULL(scope); | 8713 DCHECK_NOT_NULL(scope); |
| 8696 DCHECK_NULL(scope->sibling()); | 8714 DCHECK_NULL(scope->sibling()); |
| 8697 DCHECK(scope->is_function_scope()); | 8715 DCHECK(scope->is_function_scope()); |
| 8698 const i::AstRawString* var_name = | 8716 const i::AstRawString* var_name = |
| 8699 info.ast_value_factory()->GetOneByteString("my_var"); | 8717 info.ast_value_factory()->GetOneByteString("my_var"); |
| 8700 i::Variable* var = scope->Lookup(var_name); | 8718 i::Variable* var = scope->Lookup(var_name); |
| 8701 CHECK_EQ(inners[i].ctxt_allocate, | 8719 CHECK_EQ(inners[i].ctxt_allocate, |
| 8702 i::ScopeTestHelper::MustAllocateInContext(var)); | 8720 i::ScopeTestHelper::MustAllocateInContext(var)); |
| 8703 } | 8721 } |
| 8704 } | 8722 } |
| OLD | NEW |