[parser] don't report error for CoverInitializedNames in async arrow formals
BUG=v8:4483, v8:5148 R=littledan@chromium.org, adamk@chromium.org, jwolfe@igalia.com, nikolaos@chromium.org Review-Url: https://codereview.chromium.org/2091313002 Cr-Commit-Position: refs/heads/master@{#37260}
This commit is contained in:
parent
b2ce1fa20c
commit
4bb1f70e66
@ -2160,7 +2160,10 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
|
||||
ExpressionT argument = this->ParseAssignmentExpression(
|
||||
true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
|
||||
CheckNoTailCallExpressions(classifier, CHECK_OK_CUSTOM(NullExpressionList));
|
||||
Traits::RewriteNonPattern(classifier, CHECK_OK_CUSTOM(NullExpressionList));
|
||||
if (!maybe_arrow) {
|
||||
Traits::RewriteNonPattern(classifier,
|
||||
CHECK_OK_CUSTOM(NullExpressionList));
|
||||
}
|
||||
if (is_spread) {
|
||||
if (!spread_arg.IsValid()) {
|
||||
spread_arg.beg_pos = start_pos;
|
||||
@ -2197,11 +2200,17 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
|
||||
}
|
||||
*first_spread_arg_loc = spread_arg;
|
||||
|
||||
if ((!maybe_arrow || peek() != Token::ARROW) && spread_arg.IsValid()) {
|
||||
// Unspread parameter sequences are translated into array literals in the
|
||||
// parser. Ensure that the number of materialized literals matches between
|
||||
// the parser and preparser
|
||||
Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count);
|
||||
if (!maybe_arrow || peek() != Token::ARROW) {
|
||||
if (maybe_arrow) {
|
||||
Traits::RewriteNonPattern(classifier,
|
||||
CHECK_OK_CUSTOM(NullExpressionList));
|
||||
}
|
||||
if (spread_arg.IsValid()) {
|
||||
// Unspread parameter sequences are translated into array literals in the
|
||||
// parser. Ensure that the number of materialized literals matches between
|
||||
// the parser and preparser
|
||||
Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -7504,6 +7504,9 @@ TEST(AsyncAwait) {
|
||||
"var O = { async 'method'() { await 1; } }",
|
||||
"var O = { async 0() { await 1; } }",
|
||||
"async function await() {}",
|
||||
|
||||
"var asyncFn = async({ foo = 1 }) => foo;",
|
||||
"var asyncFn = async({ foo = 1 } = {}) => foo;",
|
||||
NULL
|
||||
};
|
||||
// clang-format on
|
||||
@ -7665,6 +7668,10 @@ TEST(AsyncAwaitErrors) {
|
||||
"(async`foo`.bar => 1)",
|
||||
"(async`foo`.bar foo => 1)",
|
||||
"(async`foo`.bar () => 1)",
|
||||
|
||||
// v8:5148 assert that errors are still thrown for calls that may have been
|
||||
// async functions
|
||||
"async({ foo = 1 })",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -7686,6 +7693,22 @@ TEST(AsyncAwaitErrors) {
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
const char* formal_parameters_data[] = {
|
||||
"var f = async({ await }) => 1;",
|
||||
"var f = async({ await = 1 }) => 1;",
|
||||
"var f = async({ await } = {}) => 1;",
|
||||
"var f = async({ await = 1 } = {}) => 1;",
|
||||
"var f = async([await]) => 1;",
|
||||
"var f = async([await] = []) => 1;",
|
||||
"var f = async([await = 1]) => 1;",
|
||||
"var f = async([await = 1] = []) => 1;",
|
||||
"var f = async(...await) => 1;",
|
||||
"var f = async(await) => 1;",
|
||||
"var f = async(await = 1) => 1;",
|
||||
"var f = async(...[await]) => 1;",
|
||||
NULL
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
|
||||
@ -7693,6 +7716,17 @@ TEST(AsyncAwaitErrors) {
|
||||
arraysize(always_flags));
|
||||
RunParserSyncTest(strict_context_data, strict_error_data, kError, NULL, 0,
|
||||
always_flags, arraysize(always_flags));
|
||||
{
|
||||
// TODO(caitp): support these early errors in preparser
|
||||
USE(formal_parameters_data);
|
||||
// const bool kIsModule = false;
|
||||
// const bool kTestPreparser = false;
|
||||
// TODO(caitp): These tests seem to fail test-parsing.cc, even with
|
||||
// test_preparser disabled.
|
||||
// RunParserSyncTest(context_data, formal_parameters_data, kError, NULL, 0,
|
||||
// always_flags, arraysize(always_flags), NULL, 0,
|
||||
// kIsModule, kTestPreparser);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AsyncAwaitModule) {
|
||||
|
@ -343,8 +343,20 @@ assertEquals("async function () {}", async function() {}.toString());
|
||||
assertEquals("async x => x", (async x => x).toString());
|
||||
assertEquals("async x => { return x }", (async x => { return x }).toString());
|
||||
class AsyncMethod { async foo() { } }
|
||||
assertEquals("async foo() { }", Function.prototype.toString.call(AsyncMethod.prototype.foo));
|
||||
assertEquals("async foo() { }", Function.prototype.toString.call({async foo() { }}.foo));
|
||||
assertEquals("async foo() { }",
|
||||
Function.prototype.toString.call(AsyncMethod.prototype.foo));
|
||||
assertEquals("async foo() { }",
|
||||
Function.prototype.toString.call({async foo() { }}.foo));
|
||||
|
||||
// Async functions are not constructible
|
||||
assertThrows(() => class extends (async function() {}) {}, TypeError);
|
||||
|
||||
// Regress v8:5148
|
||||
assertEqualsAsync("1", () => (async({ a = NaN }) => a)({ a: "1" }));
|
||||
assertEqualsAsync(
|
||||
"10", () => (async(foo, { a = NaN }) => foo + a)("1", { a: "0" }));
|
||||
assertEqualsAsync("2", () => (async({ a = "2" }) => a)({ a: undefined }));
|
||||
assertEqualsAsync(
|
||||
"20", () => (async(foo, { a = "0" }) => foo + a)("2", { a: undefined }));
|
||||
assertThrows(() => eval("async({ foo = 1 })"), SyntaxError);
|
||||
assertThrows(() => eval("async(a, { foo = 1 })"), SyntaxError);
|
||||
|
Loading…
Reference in New Issue
Block a user