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 3487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3498 const i::AstRawString* var_name = | 3498 const i::AstRawString* var_name = |
| 3499 info->ast_value_factory()->GetOneByteString("arg"); | 3499 info->ast_value_factory()->GetOneByteString("arg"); |
| 3500 i::Variable* var = scope->Lookup(var_name); | 3500 i::Variable* var = scope->Lookup(var_name); |
| 3501 CHECK(var->is_used() || !assigned); | 3501 CHECK(var->is_used() || !assigned); |
| 3502 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3502 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
| 3503 CHECK_EQ(is_maybe_assigned, assigned); | 3503 CHECK_EQ(is_maybe_assigned, assigned); |
| 3504 } | 3504 } |
| 3505 } | 3505 } |
| 3506 } | 3506 } |
| 3507 | 3507 |
| 3508 TEST(MaybeAssignedTopLevel) { | |
| 3509 i::Isolate* isolate = CcTest::i_isolate(); | |
| 3510 i::HandleScope scope(isolate); | |
| 3511 LocalContext env; | |
| 3512 i::Factory* factory = isolate->factory(); | |
| 3513 | |
| 3514 const char* sources[] = { | |
| 3515 "let foo; function bar() {foo = 42}; ext(bar); ext(foo)", | |
|
marja
2017/01/16 15:28:07
Could you add some destructuring test cases which
| |
| 3516 "let foo; ext(function() {foo++}); ext(foo)", | |
| 3517 "let foo = 0; bar = () => --foo; ext(bar); ext(foo)", | |
| 3518 "let foo; function* bar() {eval(ext)}; ext(bar); ext(foo)", | |
| 3519 }; | |
| 3520 | |
| 3521 for (unsigned i = 0; i < arraysize(sources); ++i) { | |
| 3522 i::ScopedVector<char> program(Utf8LengthHelper(sources[i]) + 1); | |
| 3523 i::SNPrintF(program, "%s", sources[i]); | |
| 3524 i::Zone zone(isolate->allocator(), ZONE_NAME); | |
| 3525 | |
| 3526 i::Handle<i::String> source = | |
| 3527 factory->InternalizeUtf8String(program.start()); | |
| 3528 source->PrintOn(stdout); | |
| 3529 printf("\n"); | |
| 3530 i::Handle<i::Script> script = factory->NewScript(source); | |
| 3531 | |
| 3532 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { | |
| 3533 for (unsigned module = 0; module < 2; ++module) { | |
| 3534 std::unique_ptr<i::ParseInfo> info; | |
| 3535 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); | |
| 3536 info->set_module(module); | |
| 3537 info->set_allow_lazy_parsing(allow_lazy); | |
| 3538 | |
| 3539 CHECK(i::parsing::ParseProgram(info.get())); | |
| 3540 CHECK(i::Compiler::Analyze(info.get())); | |
| 3541 | |
| 3542 CHECK_NOT_NULL(info->literal()); | |
| 3543 i::Scope* scope = info->literal()->scope(); | |
| 3544 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | |
| 3545 CHECK_NULL(scope->sibling()); | |
| 3546 CHECK(module ? scope->is_module_scope() : scope->is_script_scope()); | |
| 3547 | |
| 3548 const i::AstRawString* var_name = | |
| 3549 info->ast_value_factory()->GetOneByteString("foo"); | |
| 3550 i::Variable* var = scope->Lookup(var_name); | |
| 3551 CHECK(var->is_used()); | |
| 3552 CHECK(var->maybe_assigned() == i::kMaybeAssigned); | |
| 3553 } | |
| 3554 } | |
| 3555 } | |
| 3556 } | |
| 3557 | |
| 3508 namespace { | 3558 namespace { |
| 3509 | 3559 |
| 3510 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, | 3560 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, |
| 3511 i::Handle<i::JSObject> m, const char* name) { | 3561 i::Handle<i::JSObject> m, const char* name) { |
| 3512 i::AstValueFactory avf(zone, isolate->heap()->HashSeed()); | 3562 i::AstValueFactory avf(zone, isolate->heap()->HashSeed()); |
| 3513 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast( | 3563 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast( |
| 3514 i::JSReceiver::GetProperty(isolate, m, name).ToHandleChecked()); | 3564 i::JSReceiver::GetProperty(isolate, m, name).ToHandleChecked()); |
| 3515 i::DeclarationScope* script_scope = | 3565 i::DeclarationScope* script_scope = |
| 3516 new (zone) i::DeclarationScope(zone, &avf); | 3566 new (zone) i::DeclarationScope(zone, &avf); |
| 3517 i::Scope* s = i::Scope::DeserializeScopeChain( | 3567 i::Scope* s = i::Scope::DeserializeScopeChain( |
| (...skipping 5317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8835 DCHECK_NOT_NULL(scope); | 8885 DCHECK_NOT_NULL(scope); |
| 8836 DCHECK_NULL(scope->sibling()); | 8886 DCHECK_NULL(scope->sibling()); |
| 8837 DCHECK(scope->is_function_scope()); | 8887 DCHECK(scope->is_function_scope()); |
| 8838 const i::AstRawString* var_name = | 8888 const i::AstRawString* var_name = |
| 8839 info.ast_value_factory()->GetOneByteString("my_var"); | 8889 info.ast_value_factory()->GetOneByteString("my_var"); |
| 8840 i::Variable* var = scope->Lookup(var_name); | 8890 i::Variable* var = scope->Lookup(var_name); |
| 8841 CHECK_EQ(inners[i].ctxt_allocate, | 8891 CHECK_EQ(inners[i].ctxt_allocate, |
| 8842 i::ScopeTestHelper::MustAllocateInContext(var)); | 8892 i::ScopeTestHelper::MustAllocateInContext(var)); |
| 8843 } | 8893 } |
| 8844 } | 8894 } |
| OLD | NEW |