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

Unified Diff: test/cctest/test-parsing.cc

Issue 2634123002: [parser] Pessimistically assume top-level variables will be assigned. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/pattern-rewriter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « src/parsing/pattern-rewriter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698