summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2022-06-17 20:35:08 +0200
committerMartok <martok@martoks-place.de>2022-06-17 20:42:40 +0200
commita90b552eb4ca9550a7b2aab58a6fcf66b1f740d8 (patch)
tree67179aa5051c3491d206c46ba8eb8e0701567356
parent5652238ba898931d9705c9df37259284bb76619e (diff)
downloaduxp-a90b552eb4ca9550a7b2aab58a6fcf66b1f740d8.tar.gz
Issue #1918 - m-c 1358246: Report syntax error for stray "async" keyword in object literal property name.
-rw-r--r--js/src/frontend/Parser.cpp36
-rw-r--r--js/src/tests/ecma_2017/AsyncFunctions/async-property-name-error.js21
2 files changed, 39 insertions, 18 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index a66183b4a8..15c3448013 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -9771,6 +9771,21 @@ Parser<ParseHandler>::propertyName(YieldHandling yieldHandling,
return null();
break;
+ case TOK_STRING: {
+ propAtom.set(tokenStream.currentToken().atom());
+ uint32_t index;
+ if (propAtom->isIndex(&index)) {
+ propName = handler.newNumber(index, NoDecimal, pos());
+ if (!propName)
+ return null();
+ break;
+ }
+ propName = stringLiteral();
+ if (!propName)
+ return null();
+ break;
+ }
+
case TOK_LB:
propName = computedPropertyName(yieldHandling, maybeDecl, propList);
if (!propName)
@@ -9784,7 +9799,7 @@ Parser<ParseHandler>::propertyName(YieldHandling yieldHandling,
}
propAtom.set(tokenStream.currentName());
- // Do not look for accessor syntax on generators
+ // Do not look for accessor syntax on generator or async methods.
if (isGenerator || isAsync || !(ltok == TOK_GET || ltok == TOK_SET)) {
propName = handler.newObjectLiteralPropertyName(propAtom, pos());
if (!propName)
@@ -9839,21 +9854,6 @@ Parser<ParseHandler>::propertyName(YieldHandling yieldHandling,
return null();
break;
}
-
- case TOK_STRING: {
- propAtom.set(tokenStream.currentToken().atom());
- uint32_t index;
- if (propAtom->isIndex(&index)) {
- propName = handler.newNumber(index, NoDecimal, pos());
- if (!propName)
- return null();
- break;
- }
- propName = stringLiteral();
- if (!propName)
- return null();
- break;
- }
}
TokenKind tt;
@@ -9861,7 +9861,7 @@ Parser<ParseHandler>::propertyName(YieldHandling yieldHandling,
return null();
if (tt == TOK_COLON) {
- if (isGenerator) {
+ if (isGenerator || isAsync) {
error(JSMSG_BAD_PROP_ID);
return null();
}
@@ -9872,7 +9872,7 @@ Parser<ParseHandler>::propertyName(YieldHandling yieldHandling,
if (TokenKindIsPossibleIdentifierName(ltok) &&
(tt == TOK_COMMA || tt == TOK_RC || tt == TOK_ASSIGN))
{
- if (isGenerator) {
+ if (isGenerator || isAsync) {
error(JSMSG_BAD_PROP_ID);
return null();
}
diff --git a/js/src/tests/ecma_2017/AsyncFunctions/async-property-name-error.js b/js/src/tests/ecma_2017/AsyncFunctions/async-property-name-error.js
new file mode 100644
index 0000000000..926794e5d0
--- /dev/null
+++ b/js/src/tests/ecma_2017/AsyncFunctions/async-property-name-error.js
@@ -0,0 +1,21 @@
+function assertSyntaxError(code) {
+ assertThrowsInstanceOf(() => { Function(code); }, SyntaxError, "Function:" + code);
+ assertThrowsInstanceOf(() => { eval(code); }, SyntaxError, "eval:" + code);
+ var ieval = eval;
+ assertThrowsInstanceOf(() => { ieval(code); }, SyntaxError, "indirect eval:" + code);
+}
+
+assertSyntaxError(`({async async: 0})`);
+assertSyntaxError(`({async async})`);
+assertSyntaxError(`({async async, })`);
+assertSyntaxError(`({async async = 0} = {})`);
+
+for (let decl of ["var", "let", "const"]) {
+ assertSyntaxError(`${decl} {async async: a} = {}`);
+ assertSyntaxError(`${decl} {async async} = {}`);
+ assertSyntaxError(`${decl} {async async, } = {}`);
+ assertSyntaxError(`${decl} {async async = 0} = {}`);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);