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 {
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 {
return identifier == parser_->ast_value_factory()->prototype_string();
}
......@@ -2090,13 +2086,6 @@ Statement* Parser::ParseHoistableDeclaration(
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_);
if (fni_ != NULL) fni_->PushEnclosingName(name);
FunctionLiteral* fun = ParseFunctionLiteral(
......@@ -4401,13 +4390,8 @@ Expression* Parser::ParseAsyncFunctionExpression(bool* ok) {
if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression;
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
if (this->IsAwait(name)) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return nullptr;
}
name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction,
&is_strict_reserved, CHECK_OK);
}
return ParseFunctionLiteral(name, scanner()->location(),
is_strict_reserved ? kFunctionNameIsStrictReserved
......
......@@ -177,7 +177,6 @@ class ParserTraits {
bool IsArguments(const AstRawString* identifier) const;
bool IsEvalOrArguments(const AstRawString* identifier) const;
bool IsUndefined(const AstRawString* identifier) const;
bool IsAwait(const AstRawString* identifier) const;
V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const;
// Returns true if the expression is of type "this.foo".
......
......@@ -404,13 +404,6 @@ PreParser::Statement PreParser::ParseHoistableDeclaration(
Identifier name = ParseIdentifierOrStrictReservedWord(
&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(),
is_strict_reserved ? kFunctionNameIsStrictReserved
: kFunctionNameValidityUnknown,
......@@ -1163,13 +1156,8 @@ PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) {
if (peek_any_identifier()) {
type = FunctionLiteral::kNamedExpression;
name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
if (this->IsAwait(name)) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kAwaitBindingIdentifier);
*ok = false;
return Expression::Default();
}
name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction,
&is_strict_reserved, CHECK_OK);
}
ParseFunctionLiteral(name, scanner()->location(),
......
......@@ -200,7 +200,7 @@ class Token {
}
static bool IsIdentifier(Value tok, LanguageMode language_mode,
bool is_generator, bool is_module) {
bool is_generator, bool disallow_await) {
switch (tok) {
case IDENTIFIER:
case ASYNC:
......@@ -213,7 +213,7 @@ class Token {
case YIELD:
return !is_generator && is_sloppy(language_mode);
case AWAIT:
return !is_module;
return !disallow_await;
default:
return false;
}
......
......@@ -7865,6 +7865,8 @@ TEST(AsyncAwaitErrors) {
"var f = async() => await;",
"var f = async() => { await; };",
"async function f() { return {await} }",
"var asyncFn = async function*() {}",
"async function* f() {}",
"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