Commit a126da43 authored by neis's avatar neis Committed by Commit bot

[modules] Mark namespace variables as kCreatedInitialized.

R=adamk@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2210533002
Cr-Commit-Position: refs/heads/master@{#38430}
parent c38f1011
......@@ -517,16 +517,17 @@ class Declaration : public AstNode {
class VariableDeclaration final : public Declaration {
public:
InitializationFlag initialization() const {
return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
}
InitializationFlag initialization() const { return initialization_; }
private:
friend class AstNodeFactory;
VariableDeclaration(VariableProxy* proxy, VariableMode mode, Scope* scope,
int pos)
: Declaration(proxy, mode, scope, pos, kVariableDeclaration) {}
InitializationFlag initialization, int pos)
: Declaration(proxy, mode, scope, pos, kVariableDeclaration),
initialization_(initialization) {}
InitializationFlag initialization_;
};
......@@ -3007,7 +3008,16 @@ class AstNodeFactory final BASE_EMBEDDED {
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
VariableMode mode, Scope* scope,
int pos) {
return new (zone_) VariableDeclaration(proxy, mode, scope, pos);
return NewVariableDeclaration(
proxy, mode, scope,
mode == VAR ? kCreatedInitialized : kNeedsInitialization, pos);
}
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
VariableMode mode, Scope* scope,
InitializationFlag init,
int pos) {
return new (zone_) VariableDeclaration(proxy, mode, scope, init, pos);
}
FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
......
......@@ -1523,7 +1523,8 @@ ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports(
return nullptr;
}
DeclareImport(local_name, position(), CHECK_OK);
DeclareConstVariable(local_name, kNeedsInitialization, position(),
CHECK_OK);
NamedImport* import = new (zone()) NamedImport(
import_name, local_name, scanner()->location());
......@@ -1573,7 +1574,8 @@ void Parser::ParseImportDeclaration(bool* ok) {
import_default_binding =
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
import_default_binding_loc = scanner()->location();
DeclareImport(import_default_binding, pos, CHECK_OK_VOID);
DeclareConstVariable(import_default_binding, kNeedsInitialization, pos,
CHECK_OK_VOID);
}
// Parse NameSpaceImport or NamedImports if present.
......@@ -1588,7 +1590,8 @@ void Parser::ParseImportDeclaration(bool* ok) {
module_namespace_binding =
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
module_namespace_binding_loc = scanner()->location();
DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID);
DeclareConstVariable(module_namespace_binding, kCreatedInitialized, pos,
CHECK_OK_VOID);
break;
}
......@@ -1610,22 +1613,20 @@ void Parser::ParseImportDeclaration(bool* ok) {
// Now that we have all the information, we can make the appropriate
// declarations.
// TODO(neis): Would prefer to call DeclareImport below rather than above and
// in ParseNamedImports, but then a possible error message would point to the
// wrong location. Maybe have a DeclareAt version of Declare that takes a
// location?
// TODO(neis): Would prefer to call DeclareConstVariable for each case below
// rather than above and in ParseNamedImports, but then a possible error
// message would point to the wrong location. Maybe have a DeclareAt version
// of Declare that takes a location?
if (module_namespace_binding != nullptr) {
module()->AddStarImport(module_namespace_binding, module_specifier,
module_namespace_binding_loc, zone());
// DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID);
}
if (import_default_binding != nullptr) {
module()->AddImport(ast_value_factory()->default_string(),
import_default_binding, module_specifier,
import_default_binding_loc, zone());
// DeclareImport(import_default_binding, pos, CHECK_OK_VOID);
}
if (named_imports != nullptr) {
......@@ -1636,7 +1637,6 @@ void Parser::ParseImportDeclaration(bool* ok) {
const NamedImport* import = named_imports->at(i);
module()->AddImport(import->import_name, import->local_name,
module_specifier, import->location, zone());
// DeclareImport(import->local_name, pos, CHECK_OK_VOID);
}
}
}
......@@ -1974,12 +1974,12 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
scanner()->location().end_pos);
}
void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
DCHECK_NOT_NULL(local_name);
VariableProxy* proxy = NewUnresolved(local_name, CONST);
void Parser::DeclareConstVariable(const AstRawString* name,
InitializationFlag init, int pos, bool* ok) {
DCHECK_NOT_NULL(name);
VariableProxy* proxy = NewUnresolved(name, CONST);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, CONST, scope(), pos);
factory()->NewVariableDeclaration(proxy, CONST, scope(), init, pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID);
}
......
......@@ -1084,7 +1084,8 @@ class Parser : public ParserBase<ParserTraits> {
Variable* Declare(Declaration* declaration,
DeclarationDescriptor::Kind declaration_kind, bool resolve,
bool* ok, Scope* declaration_scope = nullptr);
void DeclareImport(const AstRawString* local_name, int pos, bool* ok);
void DeclareConstVariable(const AstRawString* name, InitializationFlag init,
int pos, bool* ok);
bool TargetStackContainsLabel(const AstRawString* label);
BreakableStatement* LookupBreakTarget(const AstRawString* label, bool* ok);
......
......@@ -5958,67 +5958,80 @@ TEST(ModuleParsingInternals) {
CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET);
CHECK(declarations->at(0)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(0)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
CHECK(declarations->at(1)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(1)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(1)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n"));
CHECK(declarations->at(2)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(2)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(2)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo"));
CHECK(declarations->at(3)->proxy()->var()->mode() == i::VAR);
CHECK(!declarations->at(3)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(3)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo"));
CHECK(declarations->at(4)->proxy()->var()->mode() == i::LET);
CHECK(!declarations->at(4)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(4)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo"));
CHECK(declarations->at(5)->proxy()->var()->mode() == i::LET);
CHECK(declarations->at(5)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(5)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo"));
CHECK(declarations->at(6)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(6)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(6)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(
declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*"));
CHECK(declarations->at(7)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(7)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(7)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(
declarations->at(8)->proxy()->raw_name()->IsOneByteEqualTo("nonexport"));
CHECK(declarations->at(8)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(8)->proxy()->var()->location() !=
i::VariableLocation::MODULE);
CHECK(declarations->at(9)->proxy()->raw_name()->IsOneByteEqualTo("mm"));
CHECK(declarations->at(9)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(9)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(9)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(10)->proxy()->raw_name()->IsOneByteEqualTo("aa"));
CHECK(declarations->at(10)->proxy()->var()->mode() == i::CONST);
CHECK(declarations->at(10)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(10)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
CHECK(declarations->at(11)->proxy()->raw_name()->IsOneByteEqualTo("loo"));
CHECK(declarations->at(11)->proxy()->var()->mode() == i::CONST);
CHECK(!declarations->at(11)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(11)->proxy()->var()->location() !=
i::VariableLocation::MODULE);
CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init());
CHECK(declarations->at(12)->proxy()->var()->location() ==
i::VariableLocation::MODULE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment