Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 2634123002: [parser] Pessimistically assume top-level variables will be assigned. (Closed)
Patch Set: Feedback. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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* prefixes[] = {
3515 "let foo; ", "let foo = 0; ",
3516 "let [foo] = [1]; ", "let {foo} = {foo: 2}; ",
3517 "let {foo=3} = {}; ",
3518 };
3519 const char* sources[] = {
3520 "function bar() {foo = 42}; ext(bar); ext(foo)",
3521 "ext(function() {foo++}); ext(foo)",
3522 "bar = () => --foo; ext(bar); ext(foo)",
3523 "function* bar() {eval(ext)}; ext(bar); ext(foo)",
3524 };
3525
3526 for (unsigned i = 0; i < arraysize(prefixes); ++i) {
3527 const char* prefix = prefixes[i];
3528 for (unsigned j = 0; j < arraysize(sources); ++j) {
3529 const char* source = sources[j];
3530 i::ScopedVector<char> program(Utf8LengthHelper(prefix) +
3531 Utf8LengthHelper(source) + 1);
3532 i::SNPrintF(program, "%s%s", prefix, source);
3533 i::Zone zone(isolate->allocator(), ZONE_NAME);
3534
3535 i::Handle<i::String> string =
3536 factory->InternalizeUtf8String(program.start());
3537 string->PrintOn(stdout);
3538 printf("\n");
3539 i::Handle<i::Script> script = factory->NewScript(string);
3540
3541 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) {
3542 for (unsigned module = 0; module < 2; ++module) {
3543 std::unique_ptr<i::ParseInfo> info;
3544 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
3545 info->set_module(module);
3546 info->set_allow_lazy_parsing(allow_lazy);
3547
3548 CHECK(i::parsing::ParseProgram(info.get()));
3549 CHECK(i::Compiler::Analyze(info.get()));
3550
3551 CHECK_NOT_NULL(info->literal());
3552 i::Scope* scope = info->literal()->scope();
3553 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed());
3554 CHECK_NULL(scope->sibling());
3555 CHECK(module ? scope->is_module_scope() : scope->is_script_scope());
3556
3557 const i::AstRawString* var_name =
3558 info->ast_value_factory()->GetOneByteString("foo");
3559 i::Variable* var = scope->Lookup(var_name);
3560 CHECK(var->is_used());
3561 CHECK(var->maybe_assigned() == i::kMaybeAssigned);
3562 }
3563 }
3564 }
3565 }
3566 }
3567
3508 namespace { 3568 namespace {
3509 3569
3510 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone, 3570 i::Scope* DeserializeFunctionScope(i::Isolate* isolate, i::Zone* zone,
3511 i::Handle<i::JSObject> m, const char* name) { 3571 i::Handle<i::JSObject> m, const char* name) {
3512 i::AstValueFactory avf(zone, isolate->heap()->HashSeed()); 3572 i::AstValueFactory avf(zone, isolate->heap()->HashSeed());
3513 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast( 3573 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(
3514 i::JSReceiver::GetProperty(isolate, m, name).ToHandleChecked()); 3574 i::JSReceiver::GetProperty(isolate, m, name).ToHandleChecked());
3515 i::DeclarationScope* script_scope = 3575 i::DeclarationScope* script_scope =
3516 new (zone) i::DeclarationScope(zone, &avf); 3576 new (zone) i::DeclarationScope(zone, &avf);
3517 i::Scope* s = i::Scope::DeserializeScopeChain( 3577 i::Scope* s = i::Scope::DeserializeScopeChain(
(...skipping 5317 matching lines...) Expand 10 before | Expand all | Expand 10 after
8835 DCHECK_NOT_NULL(scope); 8895 DCHECK_NOT_NULL(scope);
8836 DCHECK_NULL(scope->sibling()); 8896 DCHECK_NULL(scope->sibling());
8837 DCHECK(scope->is_function_scope()); 8897 DCHECK(scope->is_function_scope());
8838 const i::AstRawString* var_name = 8898 const i::AstRawString* var_name =
8839 info.ast_value_factory()->GetOneByteString("my_var"); 8899 info.ast_value_factory()->GetOneByteString("my_var");
8840 i::Variable* var = scope->Lookup(var_name); 8900 i::Variable* var = scope->Lookup(var_name);
8841 CHECK_EQ(inners[i].ctxt_allocate, 8901 CHECK_EQ(inners[i].ctxt_allocate,
8842 i::ScopeTestHelper::MustAllocateInContext(var)); 8902 i::ScopeTestHelper::MustAllocateInContext(var));
8843 } 8903 }
8844 } 8904 }
OLDNEW
« src/parsing/pattern-rewriter.cc ('K') | « src/parsing/pattern-rewriter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698