Commit 253d4e84 authored by adamk's avatar adamk Committed by Commit bot

Disallow 'await' in object literal shorthand position

Also lots of cleanup around the checking for 'await' as an identifier
throughout the parser and preparser.

R=caitp@igalia.com, littledan@chromium.org
BUG=v8:4483,v8:5298

Review-Url: https://codereview.chromium.org/2267493002
Cr-Commit-Position: refs/heads/master@{#38798}
parent 6ed87bfb
This diff is collapsed.
...@@ -313,10 +313,6 @@ bool ParserTraits::IsUndefined(const AstRawString* identifier) const { ...@@ -313,10 +313,6 @@ bool ParserTraits::IsUndefined(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory()->undefined_string(); return identifier == parser_->ast_value_factory()->undefined_string();
} }
bool ParserTraits::IsAwait(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory()->await_string();
}
bool ParserTraits::IsPrototype(const AstRawString* identifier) const { bool ParserTraits::IsPrototype(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory()->prototype_string(); return identifier == parser_->ast_value_factory()->prototype_string();
} }
...@@ -2090,13 +2086,6 @@ Statement* Parser::ParseHoistableDeclaration( ...@@ -2090,13 +2086,6 @@ Statement* Parser::ParseHoistableDeclaration(
variable_name = name; variable_name = name;
} }
if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return nullptr;
}
FuncNameInferrer::State fni_state(fni_); FuncNameInferrer::State fni_state(fni_);
if (fni_ != NULL) fni_->PushEnclosingName(name); if (fni_ != NULL) fni_->PushEnclosingName(name);
FunctionLiteral* fun = ParseFunctionLiteral( FunctionLiteral* fun = ParseFunctionLiteral(
...@@ -4401,13 +4390,8 @@ Expression* Parser::ParseAsyncFunctionExpression(bool* ok) { ...@@ -4401,13 +4390,8 @@ Expression* Parser::ParseAsyncFunctionExpression(bool* ok) {
if (peek_any_identifier()) { if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression; type = FunctionLiteral::kNamedExpression;
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction,
if (this->IsAwait(name)) { &is_strict_reserved, CHECK_OK);
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return nullptr;
}
} }
return ParseFunctionLiteral(name, scanner()->location(), return ParseFunctionLiteral(name, scanner()->location(),
is_strict_reserved ? kFunctionNameIsStrictReserved is_strict_reserved ? kFunctionNameIsStrictReserved
......
...@@ -177,7 +177,6 @@ class ParserTraits { ...@@ -177,7 +177,6 @@ class ParserTraits {
bool IsArguments(const AstRawString* identifier) const; bool IsArguments(const AstRawString* identifier) const;
bool IsEvalOrArguments(const AstRawString* identifier) const; bool IsEvalOrArguments(const AstRawString* identifier) const;
bool IsUndefined(const AstRawString* identifier) const; bool IsUndefined(const AstRawString* identifier) const;
bool IsAwait(const AstRawString* identifier) const;
V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const;
// Returns true if the expression is of type "this.foo". // Returns true if the expression is of type "this.foo".
......
...@@ -404,13 +404,6 @@ PreParser::Statement PreParser::ParseHoistableDeclaration( ...@@ -404,13 +404,6 @@ PreParser::Statement PreParser::ParseHoistableDeclaration(
Identifier name = ParseIdentifierOrStrictReservedWord( Identifier name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK); &is_strict_reserved, CHECK_OK);
if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return Statement::Default();
}
ParseFunctionLiteral(name, scanner()->location(), ParseFunctionLiteral(name, scanner()->location(),
is_strict_reserved ? kFunctionNameIsStrictReserved is_strict_reserved ? kFunctionNameIsStrictReserved
: kFunctionNameValidityUnknown, : kFunctionNameValidityUnknown,
...@@ -1163,13 +1156,8 @@ PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { ...@@ -1163,13 +1156,8 @@ PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) {
if (peek_any_identifier()) { if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression; type = FunctionLiteral::kNamedExpression;
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction,
if (this->IsAwait(name)) { &is_strict_reserved, CHECK_OK);
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return Expression::Default();
}
} }
ParseFunctionLiteral(name, scanner()->location(), ParseFunctionLiteral(name, scanner()->location(),
......
...@@ -200,7 +200,7 @@ class Token { ...@@ -200,7 +200,7 @@ class Token {
} }
static bool IsIdentifier(Value tok, LanguageMode language_mode, static bool IsIdentifier(Value tok, LanguageMode language_mode,
bool is_generator, bool is_module) { bool is_generator, bool disallow_await) {
switch (tok) { switch (tok) {
case IDENTIFIER: case IDENTIFIER:
case ASYNC: case ASYNC:
...@@ -213,7 +213,7 @@ class Token { ...@@ -213,7 +213,7 @@ class Token {
case YIELD: case YIELD:
return !is_generator && is_sloppy(language_mode); return !is_generator && is_sloppy(language_mode);
case AWAIT: case AWAIT:
return !is_module; return !disallow_await;
default: default:
return false; return false;
} }
......
...@@ -7865,6 +7865,8 @@ TEST(AsyncAwaitErrors) { ...@@ -7865,6 +7865,8 @@ TEST(AsyncAwaitErrors) {
"var f = async() => await;", "var f = async() => await;",
"var f = async() => { await; };", "var f = async() => { await; };",
"async function f() { return {await} }",
"var asyncFn = async function*() {}", "var asyncFn = async function*() {}",
"async function* f() {}", "async function* f() {}",
"var O = { *async method() {} };", "var O = { *async method() {} };",
......
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