From 4c62f6dd73e98ffaab7ee2d04ac7f2e94dcbbc17 Mon Sep 17 00:00:00 2001 From: Caio Lima Date: Thu, 2 May 2019 16:29:43 -0300 Subject: [PATCH] Adding case to verify if PrivateEnvironment is properly set when evaluating 'ClassHeritage' --- ...private-environment-on-class-heritage.case | 34 ++++++++++++++++ ...r-private-environment-on-class-heritage.js | 39 +++++++++++++++++++ ...r-private-environment-on-class-heritage.js | 39 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 src/class-elements/grammar-private-environment-on-class-heritage.case create mode 100644 test/language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js create mode 100644 test/language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js diff --git a/src/class-elements/grammar-private-environment-on-class-heritage.case b/src/class-elements/grammar-private-environment-on-class-heritage.case new file mode 100644 index 0000000000..c961ccc762 --- /dev/null +++ b/src/class-elements/grammar-private-environment-on-class-heritage.case @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Caio Lima (Igalia S.L). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: It's a SyntaxError if a class expression evaluated on ClassHeritage uses an undeclared private name. +info: | + Runtime Semantics: ClassDefinitionEvaluation + + ClassTail : ClassHeritage { ClassBody } + ... + 5. Let outerPrivateEnvironment be the PrivateEnvironment of the running execution context. + 6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment). + 7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord. + 8. If ClassBodyopt is present, then + a. For each element dn of the PrivateBoundIdentifiers of ClassBodyopt, + i. Perform classPrivateEnvRec.CreateImmutableBinding(dn, true). + 9. If ClassHeritageopt is not present, then + a. Let protoParent be the intrinsic object %ObjectPrototype%. + b. Let constructorParent be the intrinsic object %FunctionPrototype%. + 10. Else, + a. Set the running execution context's LexicalEnvironment to classScope. + b. NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage. + ... +template: syntax/invalid +features: [class-fields-private, class-fields-public] +---*/ + +//- heritage + +extends class { x = this.#foo; } + +//- elements + +#foo; diff --git a/test/language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js b/test/language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js new file mode 100644 index 0000000000..7089a34ed2 --- /dev/null +++ b/test/language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/grammar-private-environment-on-class-heritage.case +// - src/class-elements/syntax/invalid/cls-expr-elements-invalid-syntax.template +/*--- +description: It's a SyntaxError if a class expression evaluated on ClassHeritage uses an undeclared private name. (class expression) +esid: prod-ClassElement +features: [class-fields-private, class-fields-public, class] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Runtime Semantics: ClassDefinitionEvaluation + + ClassTail : ClassHeritage { ClassBody } + ... + 5. Let outerPrivateEnvironment be the PrivateEnvironment of the running execution context. + 6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment). + 7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord. + 8. If ClassBodyopt is present, then + a. For each element dn of the PrivateBoundIdentifiers of ClassBodyopt, + i. Perform classPrivateEnvRec.CreateImmutableBinding(dn, true). + 9. If ClassHeritageopt is not present, then + a. Let protoParent be the intrinsic object %ObjectPrototype%. + b. Let constructorParent be the intrinsic object %FunctionPrototype%. + 10. Else, + a. Set the running execution context's LexicalEnvironment to classScope. + b. NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage. + ... + +---*/ + + +$DONOTEVALUATE(); + +var C = class extends class { x = this.#foo; } +{ + #foo; +}; diff --git a/test/language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js b/test/language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js new file mode 100644 index 0000000000..a4731a80c3 --- /dev/null +++ b/test/language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/grammar-private-environment-on-class-heritage.case +// - src/class-elements/syntax/invalid/cls-decl-elements-invalid-syntax.template +/*--- +description: It's a SyntaxError if a class expression evaluated on ClassHeritage uses an undeclared private name. (class declaration) +esid: prod-ClassElement +features: [class-fields-private, class-fields-public, class] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Runtime Semantics: ClassDefinitionEvaluation + + ClassTail : ClassHeritage { ClassBody } + ... + 5. Let outerPrivateEnvironment be the PrivateEnvironment of the running execution context. + 6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment). + 7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord. + 8. If ClassBodyopt is present, then + a. For each element dn of the PrivateBoundIdentifiers of ClassBodyopt, + i. Perform classPrivateEnvRec.CreateImmutableBinding(dn, true). + 9. If ClassHeritageopt is not present, then + a. Let protoParent be the intrinsic object %ObjectPrototype%. + b. Let constructorParent be the intrinsic object %FunctionPrototype%. + 10. Else, + a. Set the running execution context's LexicalEnvironment to classScope. + b. NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage. + ... + +---*/ + + +$DONOTEVALUATE(); + +class C extends class { x = this.#foo; } +{ + #foo; +}