Commit cad3c5a1 authored by Daniel Ehrenberg's avatar Daniel Ehrenberg Committed by Commit Bot

[parser] Disallow async functions as destructuring targets

This patch teaches the parser that async functions are not valid
destructuring targets so that it can cleanly exit with a SyntaxError.
Previously, async functions used in the wrong position would lead
to a check failure.

Bug: chromium:740366
Change-Id: Ie5b0cf50326c3f96174c6b29d0ccedb5da4f75a2
Reviewed-on: https://chromium-review.googlesource.com/567002Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarCaitlin Potter <caitp@igalia.com>
Commit-Queue: Daniel Ehrenberg <littledan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46587}
parent 869dd9b3
...@@ -1865,6 +1865,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( ...@@ -1865,6 +1865,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
case Token::ASYNC: case Token::ASYNC:
if (!scanner()->HasAnyLineTerminatorAfterNext() && if (!scanner()->HasAnyLineTerminatorAfterNext() &&
PeekAhead() == Token::FUNCTION) { PeekAhead() == Token::FUNCTION) {
BindingPatternUnexpectedToken();
Consume(Token::ASYNC); Consume(Token::ASYNC);
return ParseAsyncFunctionLiteral(CHECK_OK); return ParseAsyncFunctionLiteral(CHECK_OK);
} }
......
...@@ -7459,6 +7459,9 @@ TEST(DestructuringNegativeTests) { ...@@ -7459,6 +7459,9 @@ TEST(DestructuringNegativeTests) {
"{ x : y++ }", "{ x : y++ }",
"[a++]", "[a++]",
"(x => y)", "(x => y)",
"(async x => y)",
"((x, z) => y)",
"(async (x, z) => y)",
"a[i]", "a()", "a[i]", "a()",
"a.b", "a.b",
"new a", "new a",
...@@ -7473,6 +7476,8 @@ TEST(DestructuringNegativeTests) { ...@@ -7473,6 +7476,8 @@ TEST(DestructuringNegativeTests) {
"a <<< a", "a <<< a",
"a >>> a", "a >>> a",
"function a() {}", "function a() {}",
"function* a() {}",
"async function a() {}",
"a`bcd`", "a`bcd`",
"this", "this",
"null", "null",
...@@ -7539,6 +7544,11 @@ TEST(DestructuringNegativeTests) { ...@@ -7539,6 +7544,11 @@ TEST(DestructuringNegativeTests) {
NULL NULL
}; };
const char* async_gen_data[] = {
"async function* a() {}",
NULL
};
// clang-format on // clang-format on
RunParserSyncTest(context_data, data, kError); RunParserSyncTest(context_data, data, kError);
RunParserSyncTest(context_data, rest_data, kError); RunParserSyncTest(context_data, rest_data, kError);
...@@ -7547,6 +7557,9 @@ TEST(DestructuringNegativeTests) { ...@@ -7547,6 +7557,9 @@ TEST(DestructuringNegativeTests) {
arraysize(flags)); arraysize(flags));
RunParserSyncTest(context_data, rest_data, kError, NULL, 0, flags, RunParserSyncTest(context_data, rest_data, kError, NULL, 0, flags,
arraysize(flags)); arraysize(flags));
static const ParserFlag async_gen_flags[] = {kAllowHarmonyAsyncIteration};
RunParserSyncTest(context_data, async_gen_data, kError, NULL, 0,
async_gen_flags, arraysize(async_gen_flags));
} }
{ // All modes. { // All modes.
...@@ -7922,9 +7935,13 @@ TEST(DestructuringAssignmentNegativeTests) { ...@@ -7922,9 +7935,13 @@ TEST(DestructuringAssignmentNegativeTests) {
"[super]", "[super]",
"[super = 1]", "[super = 1]",
"[function f() {}]", "[function f() {}]",
"[async function f() {}]",
"[function* f() {}]",
"[50]", "[50]",
"[(50)]", "[(50)]",
"[(function() {})]", "[(function() {})]",
"[(async function() {})]",
"[(function*() {})]",
"[(foo())]", "[(foo())]",
"{ x: 50 }", "{ x: 50 }",
"{ x: (50) }", "{ x: (50) }",
...@@ -7932,11 +7949,21 @@ TEST(DestructuringAssignmentNegativeTests) { ...@@ -7932,11 +7949,21 @@ TEST(DestructuringAssignmentNegativeTests) {
"{ x: 'str' }", "{ x: 'str' }",
"{ x: ('str') }", "{ x: ('str') }",
"{ x: (foo()) }", "{ x: (foo()) }",
"{ x: function() {} }",
"{ x: async function() {} }",
"{ x: function*() {} }",
"{ x: (function() {}) }", "{ x: (function() {}) }",
"{ x: (async function() {}) }",
"{ x: (function*() {}) }",
"{ x: y } = 'str'", "{ x: y } = 'str'",
"[x, y] = 'str'", "[x, y] = 'str'",
"[(x,y) => z]", "[(x,y) => z]",
"[async(x,y) => z]",
"[async x => z]",
"{x: (y) => z}", "{x: (y) => z}",
"{x: (y,w) => z}",
"{x: async (y) => z}",
"{x: async (y,w) => z}",
"[x, ...y, z]", "[x, ...y, z]",
"[...x,]", "[...x,]",
"[x, y, ...z = 1]", "[x, y, ...z = 1]",
......
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