diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-1.js b/test/language/module-code/privatename-not-valid-earlyerr-module-1.js new file mode 100644 index 0000000000000000000000000000000000000000..03cfdfcb626a4bc308c13607380fb442475915e3 --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-1.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename in constructor without being declared in class fields +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + constructor() { + this.#x; + } +} diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-2.js b/test/language/module-code/privatename-not-valid-earlyerr-module-2.js new file mode 100644 index 0000000000000000000000000000000000000000..004ba926a8bc6894336cdcf59030cb8cc43f3b9e --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-2.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename in function without declaring in class +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + f() { + this.#x; + } +} diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-3.js b/test/language/module-code/privatename-not-valid-earlyerr-module-3.js new file mode 100644 index 0000000000000000000000000000000000000000..496a5846a264b3466bba47d6cd6a2f8dd5ac1f3e --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-3.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename in field without being declared in class fields +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + y = this.#x; +} diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-4.js b/test/language/module-code/privatename-not-valid-earlyerr-module-4.js new file mode 100644 index 0000000000000000000000000000000000000000..055952cad15216cb004853b965a15e6c0a1f6ac0 --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-4.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename that has not been declared in class. +info: | + Static Semantics: Early Errors + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + f() { + this.#x; + class D extends C { + #x; + } + } +} diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-5.js b/test/language/module-code/privatename-not-valid-earlyerr-module-5.js new file mode 100644 index 0000000000000000000000000000000000000000..be8e95742a35174c26f2bb2abb4055b5b3621ff0 --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-5.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename outside of class +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + #x; +} + +new C().#x; diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-6.js b/test/language/module-code/privatename-not-valid-earlyerr-module-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d2deab1fd646af2b456548ae2c9e7ff8a84db7fb --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-6.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename outside of class. +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C {} + +new C().#x; diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-7.js b/test/language/module-code/privatename-not-valid-earlyerr-module-7.js new file mode 100644 index 0000000000000000000000000000000000000000..360eaf61f87b632b0a2e6039c783378ae2c584aa --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-7.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +obj = {}; + +obj.#x; diff --git a/test/language/module-code/privatename-not-valid-earlyerr-module-8.js b/test/language/module-code/privatename-not-valid-earlyerr-module-8.js new file mode 100644 index 0000000000000000000000000000000000000000..a5ff8a447533f2651824ebfd60d3021ee80e8fa9 --- /dev/null +++ b/test/language/module-code/privatename-not-valid-earlyerr-module-8.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. +features: [class-fields] +flags: [module] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +function f() { + this.#x; +} diff --git a/test/language/module-code/privatename-valid-no-earlyerr.js b/test/language/module-code/privatename-valid-no-earlyerr.js new file mode 100644 index 0000000000000000000000000000000000000000..8817d14a8f09d80959ba58ec7b07efa8677c0cbb --- /dev/null +++ b/test/language/module-code/privatename-valid-no-earlyerr.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +description: Referencing privatename in class within class does not error. +info: | + Static Semantics: Early Errors + Module : ModuleBody + It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. + + Static Semantics: AllPrivateNamesValid + AllPrivateNamesValid is an abstract operation which takes names as an argument. + + 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. + + 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. +flags: [module] +features: [class-fields] +---*/ + +class outer { + #x = 42; + + f() { + var self = this; + return class inner { + g() { + return self.#x; + } + } + } +} + +var innerclass = new outer().f(); +var test = new innerclass().g(); + +assert.equal(test, 42); diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-1.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-1.js new file mode 100644 index 0000000000000000000000000000000000000000..58419869c57a53de073e8c9205df0185a9e97002 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-1.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename in constructor without being declared in class fields +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + constructor() { + this.#x; + } +} diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-2.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e09c7009d22edd285dac504f53c1f32db034e7b5 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-2.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename in function in class without declaring in field +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + f() { + this.#x; + } +} diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-3.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d8578300081dc867c5d500d664e8c3dc42041670 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-3.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename that has not been declared in class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + y = this.#x; +} diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-4.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-4.js new file mode 100644 index 0000000000000000000000000000000000000000..4ad2c366327f40f06057f32e259628db7fc23fa3 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-4.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename that has not been declared in class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + f() { + this.#x; + class D extends C { + #x; + } + } +} diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-5.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-5.js new file mode 100644 index 0000000000000000000000000000000000000000..69c7730c8d1d0bd9d73d7058ed5ab25a4569a0b4 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-5.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename outside of class +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C { + #x; +} + +new C().#x; diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-6.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-6.js new file mode 100644 index 0000000000000000000000000000000000000000..6e48b198e08d72e55a6c437c62d83a8ec5f96032 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-6.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename outside of class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +class C {} + +new C().#x; diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-7.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-7.js new file mode 100644 index 0000000000000000000000000000000000000000..7a70a4f7dc48ec8215cdffdce5341060d3c3e330 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-7.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +obj = {}; + +obj.#x; diff --git a/test/language/statements/class/privatename-not-valid-earlyerr-script-8.js b/test/language/statements/class/privatename-not-valid-earlyerr-script-8.js new file mode 100644 index 0000000000000000000000000000000000000000..40f57259639f427fcdcd30299f6d26a9e2a43280 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-earlyerr-script-8.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +function f() { + this.#x; +} diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-1.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8f29f20bced1464d4ffad2fbdfd4d8918c83c070 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-1.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename in constructor without being declared in class fields +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +class C { + constructor() { + eval("executed = true; this.#x;"); + } +} + +assert.throws(SyntaxError, function() { + new C(); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-2.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-2.js new file mode 100644 index 0000000000000000000000000000000000000000..571b62b5550a3deb3f4176fff0818d683327cc61 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-2.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename in function in class without declaring in field +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +class C { + f() { + eval("executed = true; this.#x;"); + } +} + +assert.throws(SyntaxError, function() { + new C().f(); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-3.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-3.js new file mode 100644 index 0000000000000000000000000000000000000000..5d0818a2580ebf3cb70267ead6e9de45e817ea5c --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-3.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename that has not been declared in class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +class C { + y = eval("executed = true; this.#x;") +} + +assert.throws(SyntaxError, function() { + new C(); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-4.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-4.js new file mode 100644 index 0000000000000000000000000000000000000000..58ca403cceced2378ab2fc31b5d369bc15fa79bf --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-4.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename that has not been declared in class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +class C { + f() { + eval("executed = true; this.#x;"); + class D extends C { + #x; + } + } +} + +assert.throws(SyntaxError, function() { + new C().f(); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-5.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-5.js new file mode 100644 index 0000000000000000000000000000000000000000..5e8ba531c05d566bc52865fa4f5570f4dc89111e --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-5.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename outside of class +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +class C { + #x; +} + +assert.throws(SyntaxError, function() { + eval("executed = true; new C().#x"); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-6.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-6.js new file mode 100644 index 0000000000000000000000000000000000000000..816227e67b2c3efb4d0c77d550ee2ec31c0bc4e4 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-6.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename outside of class. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + 2. If Script is parsed directly from PerformEval, + a. Let env be the running execution context's PrivateNameEnvironment. + b. Repeat while env is not null, + i. For each binding named N in env, + 1. If names does not contain N, append N to names. + ii. Let env be env's outer environment reference. + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; +class C {} + +assert.throws(SyntaxError, function() { + eval("executed = true; new C().#x"); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-7.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-7.js new file mode 100644 index 0000000000000000000000000000000000000000..f7e39c7137abcfcf2d1dbd39f63e883259d539dd --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-7.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; +var obj = {}; + +assert.throws(SyntaxError, function() { + eval("executed = true; obj.#x;"); +}); + +assert.sameValue(executed, false); diff --git a/test/language/statements/class/privatename-not-valid-eval-earlyerr-8.js b/test/language/statements/class/privatename-not-valid-eval-earlyerr-8.js new file mode 100644 index 0000000000000000000000000000000000000000..8ffdc42deb95a0249c75056cce7d5f9b01addd96 --- /dev/null +++ b/test/language/statements/class/privatename-not-valid-eval-earlyerr-8.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Early error when referencing privatename on object, outside of class. +info: | + Static Semantics: Early Errors + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. +features: [class-fields] +---*/ + +var executed = false; + +function f() { + eval("executed = true; this.#x;"); +} + +assert.throws(SyntaxError, function() { + f(); +}); + +assert.sameValue(executed, false); + diff --git a/test/language/statements/class/privatename-valid-no-earlyerr.js b/test/language/statements/class/privatename-valid-no-earlyerr.js new file mode 100644 index 0000000000000000000000000000000000000000..3138cbd92f7d0a98fd4368787627a739e2ab7d0a --- /dev/null +++ b/test/language/statements/class/privatename-valid-no-earlyerr.js @@ -0,0 +1,49 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +description: Referencing privatename in class within class does not error. +info: | + Static Semantics: Early Errors + Script : ScriptBody + 1. Let names be an empty List. + ... + 3. If AllPrivateNamesValid of ScriptBody with the argument names is false, throw a SyntaxError exception. + + Static Semantics: AllPrivateNamesValid + AllPrivateNamesValid is an abstract operation which takes names as an argument. + + 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. + + 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-fields] +---*/ + +class outer { + #x = 42; + + f() { + var self = this; + return class inner { + g() { + return self.#x; + } + } + } +} + +var innerclass = new outer().f(); +var test = new innerclass().g(); + +assert.equal(test, 42);