From 8b2b4c35ca4c0a07dbd9ef603b63afcee8c3bcf1 Mon Sep 17 00:00:00 2001 From: Leo Balter <leonardo.balter@gmail.com> Date: Fri, 30 Nov 2018 18:28:03 -0500 Subject: [PATCH] Templates and cases for invalid private names --- .../call-expression-bad-reference.case | 23 ++++++++++ .../call-expression-this.case | 23 ++++++++++ .../default/block.template | 26 +++++++++++ .../cls-decl-field-initializer-fn.template | 29 ++++++++++++ ...s-decl-field-initializer-heritage.template | 44 ++++++++++++++++++ .../cls-decl-field-initializer.template | 29 ++++++++++++ .../default/cls-decl-inner-method.template | 44 ++++++++++++++++++ .../default/cls-decl-method-fn.template | 31 +++++++++++++ .../default/cls-decl-method-heritage.template | 45 +++++++++++++++++++ .../default/cls-decl-method.template | 29 ++++++++++++ .../default/cls-decl-outter-method.template | 45 +++++++++++++++++++ .../cls-expr-field-initializer-fn.template | 39 ++++++++++++++++ ...s-expr-field-initializer-heritage.template | 43 ++++++++++++++++++ .../cls-expr-field-initializer.template | 39 ++++++++++++++++ .../default/cls-expr-inner-method.template | 44 ++++++++++++++++++ .../default/cls-expr-method-fn.template | 41 +++++++++++++++++ .../default/cls-expr-method-heritage.template | 45 +++++++++++++++++++ .../default/cls-expr-method.template | 39 ++++++++++++++++ .../default/cls-expr-outter-method.template | 45 +++++++++++++++++++ .../default/convention.md | 1 + .../default/function-decl.template | 26 +++++++++++ .../default/function-expr.template | 26 +++++++++++ .../default/top-level-modulebody.template | 27 +++++++++++ .../default/top-level-scriptbody.template | 26 +++++++++++ .../member-expression-bad-reference.case | 23 ++++++++++ .../member-expression-this.case | 23 ++++++++++ 26 files changed, 855 insertions(+) create mode 100644 src/invalid-private-names/call-expression-bad-reference.case create mode 100644 src/invalid-private-names/call-expression-this.case create mode 100644 src/invalid-private-names/default/block.template create mode 100644 src/invalid-private-names/default/cls-decl-field-initializer-fn.template create mode 100644 src/invalid-private-names/default/cls-decl-field-initializer-heritage.template create mode 100644 src/invalid-private-names/default/cls-decl-field-initializer.template create mode 100644 src/invalid-private-names/default/cls-decl-inner-method.template create mode 100644 src/invalid-private-names/default/cls-decl-method-fn.template create mode 100644 src/invalid-private-names/default/cls-decl-method-heritage.template create mode 100644 src/invalid-private-names/default/cls-decl-method.template create mode 100644 src/invalid-private-names/default/cls-decl-outter-method.template create mode 100644 src/invalid-private-names/default/cls-expr-field-initializer-fn.template create mode 100644 src/invalid-private-names/default/cls-expr-field-initializer-heritage.template create mode 100644 src/invalid-private-names/default/cls-expr-field-initializer.template create mode 100644 src/invalid-private-names/default/cls-expr-inner-method.template create mode 100644 src/invalid-private-names/default/cls-expr-method-fn.template create mode 100644 src/invalid-private-names/default/cls-expr-method-heritage.template create mode 100644 src/invalid-private-names/default/cls-expr-method.template create mode 100644 src/invalid-private-names/default/cls-expr-outter-method.template create mode 100644 src/invalid-private-names/default/convention.md create mode 100644 src/invalid-private-names/default/function-decl.template create mode 100644 src/invalid-private-names/default/function-expr.template create mode 100644 src/invalid-private-names/default/top-level-modulebody.template create mode 100644 src/invalid-private-names/default/top-level-scriptbody.template create mode 100644 src/invalid-private-names/member-expression-bad-reference.case create mode 100644 src/invalid-private-names/member-expression-this.case diff --git a/src/invalid-private-names/call-expression-bad-reference.case b/src/invalid-private-names/call-expression-bad-reference.case new file mode 100644 index 0000000000..3222878e05 --- /dev/null +++ b/src/invalid-private-names/call-expression-bad-reference.case @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: bad reference in call expression +info: | + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. +template: default +features: [class-fields-private] +---*/ + +//- body +(() => {})().#x diff --git a/src/invalid-private-names/call-expression-this.case b/src/invalid-private-names/call-expression-this.case new file mode 100644 index 0000000000..acfae7d92f --- /dev/null +++ b/src/invalid-private-names/call-expression-this.case @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: this evaluated in call expression +info: | + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. +template: default +features: [class-fields-private] +---*/ + +//- body +(() => this)().#x diff --git a/src/invalid-private-names/default/block.template b/src/invalid-private-names/default/block.template new file mode 100644 index 0000000000..f6af760c03 --- /dev/null +++ b/src/invalid-private-names/default/block.template @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/block/early-errors/invalid-names- +name: > + Invalid private names should throw a SyntaxError, + block statement +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +{ /*{ body }*/ } diff --git a/src/invalid-private-names/default/cls-decl-field-initializer-fn.template b/src/invalid-private-names/default/cls-decl-field-initializer-fn.template new file mode 100644 index 0000000000..b4da088fc3 --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-field-initializer-fn.template @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/field-init-fn- +name: > + Invalid private names should throw a SyntaxError, + function in class field initializer in class declaration +features: [class, class-fields-public] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + f = function() { /*{ body }*/ } +} diff --git a/src/invalid-private-names/default/cls-decl-field-initializer-heritage.template b/src/invalid-private-names/default/cls-decl-field-initializer-heritage.template new file mode 100644 index 0000000000..c4a22bbba4 --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-field-initializer-heritage.template @@ -0,0 +1,44 @@ + +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/fields-init-heritage- +name: > + Invalid private names should throw a SyntaxError, + class field initializer in class declaration +features: [class, class-fields-private] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Parent { + #x = 42; +} + +class C extends Parent { + f = /*{ body }*/ +} diff --git a/src/invalid-private-names/default/cls-decl-field-initializer.template b/src/invalid-private-names/default/cls-decl-field-initializer.template new file mode 100644 index 0000000000..7e40eced0f --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-field-initializer.template @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/field-init- +name: > + Invalid private names should throw a SyntaxError, + class field initializer in class declaration +features: [class, class-fields-public] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + f = /*{ body }*/ +} diff --git a/src/invalid-private-names/default/cls-decl-inner-method.template b/src/invalid-private-names/default/cls-decl-inner-method.template new file mode 100644 index 0000000000..23bb2862c9 --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-inner-method.template @@ -0,0 +1,44 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/method-inner- +name: > + Invalid private names should throw a SyntaxError, + method in inner class declaration +features: [class, class-fields-private] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + #x = 42; + m() { + class Inner { + z() { /*{ body }*/ } + } + } +} diff --git a/src/invalid-private-names/default/cls-decl-method-fn.template b/src/invalid-private-names/default/cls-decl-method-fn.template new file mode 100644 index 0000000000..f4f4ee3fb3 --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-method-fn.template @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/method-fn- +name: > + Invalid private names should throw a SyntaxError, + inner function in method in class declaration +features: [class] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + m() { + function fn() { /*{ body }*/ } + } +} diff --git a/src/invalid-private-names/default/cls-decl-method-heritage.template b/src/invalid-private-names/default/cls-decl-method-heritage.template new file mode 100644 index 0000000000..758909c8ad --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-method-heritage.template @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/method-heritage- +name: > + Invalid private names should throw a SyntaxError, + method in class declaration +features: [class, class-fields-private] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Parent { + #x = 42; +} + +class C extends Parent { + m() { + /*{ body }*/ + } +} diff --git a/src/invalid-private-names/default/cls-decl-method.template b/src/invalid-private-names/default/cls-decl-method.template new file mode 100644 index 0000000000..776dee46aa --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-method.template @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/method- +name: > + Invalid private names should throw a SyntaxError, + method in class declaration +features: [class] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + m() { /*{ body }*/ } +} diff --git a/src/invalid-private-names/default/cls-decl-outter-method.template b/src/invalid-private-names/default/cls-decl-outter-method.template new file mode 100644 index 0000000000..d4b6a3c7cd --- /dev/null +++ b/src/invalid-private-names/default/cls-decl-outter-method.template @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/syntax/early-errors/invalid-names/method-outter- +name: > + Invalid private names should throw a SyntaxError, + method in outter class declaration +features: [class, class-fields-private] +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class C { + m() { + class Outter { + #x = 42; + } + + this.#x; + } +} diff --git a/src/invalid-private-names/default/cls-expr-field-initializer-fn.template b/src/invalid-private-names/default/cls-expr-field-initializer-fn.template new file mode 100644 index 0000000000..8a2ad2d19c --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-field-initializer-fn.template @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/field-init-fn- +name: > + Invalid private names should throw a SyntaxError, + function in class field initializer in class expression +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +features: [class, class-fields-public] +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + f = function() { /*{ body }*/ } +}; diff --git a/src/invalid-private-names/default/cls-expr-field-initializer-heritage.template b/src/invalid-private-names/default/cls-expr-field-initializer-heritage.template new file mode 100644 index 0000000000..d743217e63 --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-field-initializer-heritage.template @@ -0,0 +1,43 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/field-init-heritage- +name: > + Invalid private names should throw a SyntaxError, + field initializer in inner class expression +features: [class, class-fields-private] +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Parent { + #x = 42; +} + +var C = class extends Parent { + f = /*{ body }*/ +}; diff --git a/src/invalid-private-names/default/cls-expr-field-initializer.template b/src/invalid-private-names/default/cls-expr-field-initializer.template new file mode 100644 index 0000000000..e49e9f3316 --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-field-initializer.template @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/field-init- +name: > + Invalid private names should throw a SyntaxError, + class field initializer in class expression +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +features: [class, class-fields-public] +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + f = /*{ body }*/ +}; diff --git a/src/invalid-private-names/default/cls-expr-inner-method.template b/src/invalid-private-names/default/cls-expr-inner-method.template new file mode 100644 index 0000000000..f0081d3310 --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-inner-method.template @@ -0,0 +1,44 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/method-inner- +name: > + Invalid private names should throw a SyntaxError, + method in inner class expression +features: [class, class-fields-private] +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + #x = 42; + m() { + class Inner { + z() { /*{ body }*/ } + } + } +}; diff --git a/src/invalid-private-names/default/cls-expr-method-fn.template b/src/invalid-private-names/default/cls-expr-method-fn.template new file mode 100644 index 0000000000..68e7db30dd --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-method-fn.template @@ -0,0 +1,41 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/method-fn- +name: > + Invalid private names should throw a SyntaxError, + inner function in method in class expression +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +features: [class] +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + m() { + function fn() { /*{ body }*/ } + } +}; diff --git a/src/invalid-private-names/default/cls-expr-method-heritage.template b/src/invalid-private-names/default/cls-expr-method-heritage.template new file mode 100644 index 0000000000..a38c4532bc --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-method-heritage.template @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/method-heritage- +name: > + Invalid private names should throw a SyntaxError, + method in inner class expression +features: [class, class-fields-private] +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Parent { + #x = 42; +} + +var C = class extends Parent { + m() { + /*{ body }*/ + } +}; diff --git a/src/invalid-private-names/default/cls-expr-method.template b/src/invalid-private-names/default/cls-expr-method.template new file mode 100644 index 0000000000..25ed93ad45 --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-method.template @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/method- +name: > + Invalid private names should throw a SyntaxError, + method in class expression +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +features: [class] +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + m() { /*{ body }*/ } +}; diff --git a/src/invalid-private-names/default/cls-expr-outter-method.template b/src/invalid-private-names/default/cls-expr-outter-method.template new file mode 100644 index 0000000000..0936f7991a --- /dev/null +++ b/src/invalid-private-names/default/cls-expr-outter-method.template @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/syntax/early-errors/invalid-names/method-outter- +name: > + Invalid private names should throw a SyntaxError, + method in outter class expression +features: [class, class-fields-private] +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + Static Semantics: AllPrivateNamesValid + + ClassBody : ClassElementList + 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. + 2. Return AllPrivateNamesValid of ClassElementList with the argument newNames. + + For all other grammatical productions, recurse on subexpressions/substatements, + passing in the names of the caller. If all pieces return true, then return true. + If any returns false, return false. +esid: sec-static-semantics-early-errors +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var C = class { + m() { + class Outter { + #x = 42; + } + + this.#x; + } +}; diff --git a/src/invalid-private-names/default/convention.md b/src/invalid-private-names/default/convention.md new file mode 100644 index 0000000000..e922e88f78 --- /dev/null +++ b/src/invalid-private-names/default/convention.md @@ -0,0 +1 @@ +Cases conventionally use #x as the private name reference to be flagged as invalid. diff --git a/src/invalid-private-names/default/function-decl.template b/src/invalid-private-names/default/function-decl.template new file mode 100644 index 0000000000..b170a2904e --- /dev/null +++ b/src/invalid-private-names/default/function-decl.template @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/function/early-errors/invalid-names- +name: > + Invalid private names should throw a SyntaxError, + inside function declaration +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function fn() { /*{ body }*/ } diff --git a/src/invalid-private-names/default/function-expr.template b/src/invalid-private-names/default/function-expr.template new file mode 100644 index 0000000000..9a3f4e569e --- /dev/null +++ b/src/invalid-private-names/default/function-expr.template @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/function/early-errors/invalid-names- +name: > + Invalid private names should throw a SyntaxError, + inside function expression +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var fn = function() { /*{ body }*/ }; diff --git a/src/invalid-private-names/default/top-level-modulebody.template b/src/invalid-private-names/default/top-level-modulebody.template new file mode 100644 index 0000000000..ea3adb5626 --- /dev/null +++ b/src/invalid-private-names/default/top-level-modulebody.template @@ -0,0 +1,27 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/module-code/invalid-private-names- +name: > + Invalid private names should throw a SyntaxError, + top level of module body +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +flags: [module] +---*/ + +$DONOTEVALUATE(); + +/*{ body }*/ diff --git a/src/invalid-private-names/default/top-level-scriptbody.template b/src/invalid-private-names/default/top-level-scriptbody.template new file mode 100644 index 0000000000..41d179b091 --- /dev/null +++ b/src/invalid-private-names/default/top-level-scriptbody.template @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/global-code/invalid-private-names- +name: > + Invalid private names should throw a SyntaxError, + top level of script body +esid: sec-static-semantics-early-errors +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +/*{ body }*/ diff --git a/src/invalid-private-names/member-expression-bad-reference.case b/src/invalid-private-names/member-expression-bad-reference.case new file mode 100644 index 0000000000..8ba7510ed4 --- /dev/null +++ b/src/invalid-private-names/member-expression-bad-reference.case @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: bad reference in member expression +info: | + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. +template: default +features: [class-fields-private] +---*/ + +//- body +something.#x diff --git a/src/invalid-private-names/member-expression-this.case b/src/invalid-private-names/member-expression-this.case new file mode 100644 index 0000000000..e5797d916c --- /dev/null +++ b/src/invalid-private-names/member-expression-this.case @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: this reference in member expression +info: | + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. +template: default +features: [class-fields-private] +---*/ + +//- body +this.#x -- GitLab