зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1041341 - Part 2: Report a SyntaxError for destructuring rest with trailing comma. r=arai
--HG-- extra : rebase_source : 686eb8d6fb58998255365d53bdfc71b4d5ec50a9
This commit is contained in:
Родитель
b1c8fefe38
Коммит
b847ec2cfd
|
@ -8571,6 +8571,8 @@ Parser<ParseHandler>::arrayInitializer(YieldHandling yieldHandling, PossibleErro
|
|||
modifier = TokenStream::None;
|
||||
break;
|
||||
}
|
||||
if (tt == TOK_TRIPLEDOT && possibleError)
|
||||
possibleError->setPendingDestructuringError(null(), JSMSG_REST_WITH_COMMA);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,7 @@ assertThrowsInstanceOf(() => new Function('[...!a] = []'), SyntaxError, 'unary e
|
|||
assertThrowsInstanceOf(() => new Function('[...a+b] = []'), SyntaxError, 'binary expression');
|
||||
assertThrowsInstanceOf(() => new Function('var [...a.x] = []'), SyntaxError, 'lvalue expression in declaration');
|
||||
assertThrowsInstanceOf(() => new Function('var [...(b)] = []'), SyntaxError);
|
||||
|
||||
// XXX: The way the current parser works, a trailing comma is lost before we
|
||||
// check for destructuring. See bug 1041341. Once fixed, please update
|
||||
// this assertion.
|
||||
assertThrowsInstanceOf(() =>
|
||||
assertThrowsInstanceOf(() => new Function('[...b,] = []'), SyntaxError)
|
||||
, Error);
|
||||
assertThrowsInstanceOf(() => new Function('[...b,] = []'), SyntaxError);
|
||||
|
||||
assertThrowsInstanceOf(() => {
|
||||
try {
|
||||
|
|
|
@ -301,6 +301,7 @@ MSG_DEF(JSMSG_RC_AFTER_EXPORT_SPEC_LIST, 0, JSEXN_SYNTAXERR, "missing '}' after
|
|||
MSG_DEF(JSMSG_RC_AFTER_IMPORT_SPEC_LIST, 0, JSEXN_SYNTAXERR, "missing '}' after module specifier list")
|
||||
MSG_DEF(JSMSG_REDECLARED_CATCH_IDENTIFIER, 1, JSEXN_SYNTAXERR, "redeclaration of identifier '{0}' in catch")
|
||||
MSG_DEF(JSMSG_RESERVED_ID, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier")
|
||||
MSG_DEF(JSMSG_REST_WITH_COMMA, 0, JSEXN_SYNTAXERR, "rest element may not have a trailing comma")
|
||||
MSG_DEF(JSMSG_REST_WITH_DEFAULT, 0, JSEXN_SYNTAXERR, "rest parameter may not have a default")
|
||||
MSG_DEF(JSMSG_SELFHOSTED_TOP_LEVEL_LEXICAL, 1, JSEXN_SYNTAXERR, "self-hosted code cannot contain top-level {0} declarations")
|
||||
MSG_DEF(JSMSG_SELFHOSTED_METHOD_CALL, 0, JSEXN_SYNTAXERR, "self-hosted code may not contain direct method calls. Use callFunction() or callContentFunction()")
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const invalidSyntax = [
|
||||
"[...r, ]",
|
||||
"[a, ...r, ]",
|
||||
"[a = 0, ...r, ]",
|
||||
"[[], ...r, ]",
|
||||
"[[...r,]]",
|
||||
"[[...r,], ]",
|
||||
"[[...r,], a]",
|
||||
];
|
||||
|
||||
const validSyntax = [
|
||||
"[, ]",
|
||||
"[a, ]",
|
||||
"[[], ]",
|
||||
];
|
||||
|
||||
const destructuringForms = [
|
||||
a => `${a} = [];`,
|
||||
a => `var ${a} = [];`,
|
||||
a => `let ${a} = [];`,
|
||||
a => `const ${a} = [];`,
|
||||
a => `(${a}) => {};`,
|
||||
a => `(${a} = []) => {};`,
|
||||
a => `function f(${a}) {}`,
|
||||
];
|
||||
|
||||
for (let invalid of invalidSyntax) {
|
||||
for (let fn of destructuringForms) {
|
||||
assertThrowsInstanceOf(() => Function(fn(invalid)), SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
for (let invalid of validSyntax) {
|
||||
for (let fn of destructuringForms) {
|
||||
Function(fn(invalid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0);
|
Загрузка…
Ссылка в новой задаче