Chromium Code Reviews| Index: test/cctest/test-parsing.cc |
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
| index a3ee6bea045ad4c9a788922a1ed833f44b9c291e..912308d656f35cdb6937a876b37bc23c7ee9d3c2 100644 |
| --- a/test/cctest/test-parsing.cc |
| +++ b/test/cctest/test-parsing.cc |
| @@ -3505,6 +3505,56 @@ TEST(MaybeAssignedParameters) { |
| } |
| } |
| +TEST(MaybeAssignedTopLevel) { |
| + i::Isolate* isolate = CcTest::i_isolate(); |
| + i::HandleScope scope(isolate); |
| + LocalContext env; |
| + i::Factory* factory = isolate->factory(); |
| + |
| + const char* sources[] = { |
| + "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
|
| + "let foo; ext(function() {foo++}); ext(foo)", |
| + "let foo = 0; bar = () => --foo; ext(bar); ext(foo)", |
| + "let foo; function* bar() {eval(ext)}; ext(bar); ext(foo)", |
| + }; |
| + |
| + for (unsigned i = 0; i < arraysize(sources); ++i) { |
| + i::ScopedVector<char> program(Utf8LengthHelper(sources[i]) + 1); |
| + i::SNPrintF(program, "%s", sources[i]); |
| + i::Zone zone(isolate->allocator(), ZONE_NAME); |
| + |
| + i::Handle<i::String> source = |
| + factory->InternalizeUtf8String(program.start()); |
| + source->PrintOn(stdout); |
| + printf("\n"); |
| + i::Handle<i::Script> script = factory->NewScript(source); |
| + |
| + for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { |
| + for (unsigned module = 0; module < 2; ++module) { |
| + std::unique_ptr<i::ParseInfo> info; |
| + info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); |
| + info->set_module(module); |
| + info->set_allow_lazy_parsing(allow_lazy); |
| + |
| + CHECK(i::parsing::ParseProgram(info.get())); |
| + CHECK(i::Compiler::Analyze(info.get())); |
| + |
| + CHECK_NOT_NULL(info->literal()); |
| + i::Scope* scope = info->literal()->scope(); |
| + CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
| + CHECK_NULL(scope->sibling()); |
| + CHECK(module ? scope->is_module_scope() : scope->is_script_scope()); |
| + |
| + const i::AstRawString* var_name = |
| + info->ast_value_factory()->GetOneByteString("foo"); |
| + i::Variable* var = scope->Lookup(var_name); |
| + CHECK(var->is_used()); |
| + CHECK(var->maybe_assigned() == i::kMaybeAssigned); |
| + } |
| + } |
| + } |
| +} |
| + |
| namespace { |
| i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, |