From 9fccd9852e1bcc32e3b237937e7c9d249f6c8dca Mon Sep 17 00:00:00 2001 From: jugglinmike <mike@mikepennisi.com> Date: Wed, 23 Jan 2019 11:07:19 -0500 Subject: [PATCH] Improve coverage for UniqueFormalParameters (#2043) Previously, the early error prohibiting duplicate entries in UniqueFormalParameters was only tested in terms of async functions. In one case, this was misattributed to UniqeFormalParameters and only enforced for strict mode code. Extend coverage to the other function-creating productions which include UniqueFormalParameters (i.e. method definitions and non-async arrow functions), and update the existing tests to more accurately describe the source of the error. --- .../arrow-function/params-duplicate.js | 33 +++++++++++++++++++ ...early-errors-arrow-duplicate-parameters.js | 25 +++++++++++--- ...bject-async-method-duplicate-parameters.js | 28 ++++++++++++++++ ...rors-object-method-duplicate-parameters.js | 22 +++++++++---- ...class-async-method-duplicate-parameters.js | 29 ++++++++++++++++ ...rrors-class-method-duplicate-parameters.js | 22 +++++++++---- 6 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 test/language/expressions/arrow-function/params-duplicate.js create mode 100644 test/language/expressions/object/method-definition/early-errors-object-async-method-duplicate-parameters.js create mode 100644 test/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js diff --git a/test/language/expressions/arrow-function/params-duplicate.js b/test/language/expressions/arrow-function/params-duplicate.js new file mode 100644 index 0000000000..14fde6fbd0 --- /dev/null +++ b/test/language/expressions/arrow-function/params-duplicate.js @@ -0,0 +1,33 @@ +// Copyright 2019 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arrow-function-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.2 Arrow Function Definitions + + When the production + + ArrowParameters:CoverParenthesizedExpressionAndArrowParameterList + + is recognized the following grammar is used to refine the interpretation + of CoverParenthesizedExpressionAndArrowParameterList: + + ArrowFormalParameters[Yield, Await]: + (UniqueFormalParameters[?Yield, ?Await]) + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +0, (a, a) => { }; diff --git a/test/language/expressions/async-arrow-function/early-errors-arrow-duplicate-parameters.js b/test/language/expressions/async-arrow-function/early-errors-arrow-duplicate-parameters.js index b0be62af49..a6783b9889 100644 --- a/test/language/expressions/async-arrow-function/early-errors-arrow-duplicate-parameters.js +++ b/test/language/expressions/async-arrow-function/early-errors-arrow-duplicate-parameters.js @@ -3,13 +3,30 @@ /*--- author: Brian Terlson <brian.terlson@microsoft.com> -esid: pending -description: > - If strict mode, early error rules for StrictFormalParameters are applied +esid: sec-async-arrow-function-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.2 Arrow Function Definitions + + When the production + + ArrowParameters:CoverParenthesizedExpressionAndArrowParameterList + + is recognized the following grammar is used to refine the interpretation + of CoverParenthesizedExpressionAndArrowParameterList: + + ArrowFormalParameters[Yield, Await]: + (UniqueFormalParameters[?Yield, ?Await]) + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. negative: phase: parse type: SyntaxError -flags: [onlyStrict] ---*/ $DONOTEVALUATE(); diff --git a/test/language/expressions/object/method-definition/early-errors-object-async-method-duplicate-parameters.js b/test/language/expressions/object/method-definition/early-errors-object-async-method-duplicate-parameters.js new file mode 100644 index 0000000000..bbf97846b2 --- /dev/null +++ b/test/language/expressions/object/method-definition/early-errors-object-async-method-duplicate-parameters.js @@ -0,0 +1,28 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.7 Async Function Definitions + + AsyncMethod[Yield, Await]: + async[no LineTerminator here]PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +({ + async foo(a, a) { } +}) diff --git a/test/language/expressions/object/method-definition/early-errors-object-method-duplicate-parameters.js b/test/language/expressions/object/method-definition/early-errors-object-method-duplicate-parameters.js index 79b0c13659..dbd6eed492 100644 --- a/test/language/expressions/object/method-definition/early-errors-object-method-duplicate-parameters.js +++ b/test/language/expressions/object/method-definition/early-errors-object-method-duplicate-parameters.js @@ -1,11 +1,21 @@ -// Copyright 2016 Microsoft, Inc. All rights reserved. +// Copyright 2019 Mike Pennisi. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -author: Brian Terlson <brian.terlson@microsoft.com> -esid: pending -description: > - Early error rules for StrictFormalParameters are applied +esid: sec-method-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.3 Method Definitions + + MethodDefinition[Yield, Await]: + PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, ~Await]){FunctionBody[~Yield, ~Await]} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. negative: phase: parse type: SyntaxError @@ -13,5 +23,5 @@ negative: $DONOTEVALUATE(); ({ - async foo(a, a) { } + foo(a, a) { } }) diff --git a/test/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js b/test/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js new file mode 100644 index 0000000000..e9f6115277 --- /dev/null +++ b/test/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js @@ -0,0 +1,29 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.7 Arrow Function Definitions + + AsyncMethod[Yield, Await]: + async[no LineTerminator here]PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Foo { + async foo(a, a) { } +} diff --git a/test/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js b/test/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js index 8187b54e95..93077124d2 100644 --- a/test/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js +++ b/test/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js @@ -1,11 +1,21 @@ -// Copyright 2016 Microsoft, Inc. All rights reserved. +// Copyright 2019 Mike Pennisi. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -author: Brian Terlson <brian.terlson@microsoft.com> -esid: pending -description: > - Early error rules for StrictFormalParameters are applied +esid: sec-method-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.3 Method Definitions + + MethodDefinition[Yield, Await]: + PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, ~Await]){FunctionBody[~Yield, ~Await]} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. negative: phase: parse type: SyntaxError @@ -14,5 +24,5 @@ negative: $DONOTEVALUATE(); class Foo { - async foo(a, a) { } + foo(a, a) { } } -- GitLab