From 01e89a8a0a027a3476c1bc10bb2de9eac7eb0690 Mon Sep 17 00:00:00 2001 From: Caio Lima Date: Mon, 19 Aug 2019 18:10:23 -0300 Subject: [PATCH] Generated tests --- ...getter-access-on-inner-arrow-function.case | 3 +- ...-private-getter-access-on-inner-class.case | 3 +- ...ivate-getter-access-on-inner-function.case | 3 +- src/class-elements/static-private-getter.case | 16 +++--- ...setter-access-on-inner-arrow-function.case | 3 +- ...-private-setter-access-on-inner-class.case | 2 +- ...ivate-setter-access-on-inner-function.case | 3 +- src/class-elements/static-private-setter.case | 16 +++--- ...e-getter-access-on-inner-arrow-function.js | 44 +++++++++++++++ ...ic-private-getter-access-on-inner-class.js | 42 ++++++++++++++ ...private-getter-access-on-inner-function.js | 46 +++++++++++++++ .../class/elements/static-private-getter.js | 55 ++++++++++++++++++ ...e-setter-access-on-inner-arrow-function.js | 45 +++++++++++++++ ...ic-private-setter-access-on-inner-class.js | 44 +++++++++++++++ ...private-setter-access-on-inner-function.js | 47 ++++++++++++++++ .../class/elements/static-private-setter.js | 56 +++++++++++++++++++ ...e-getter-access-on-inner-arrow-function.js | 44 +++++++++++++++ ...ic-private-getter-access-on-inner-class.js | 42 ++++++++++++++ ...private-getter-access-on-inner-function.js | 46 +++++++++++++++ .../class/elements/static-private-getter.js | 55 ++++++++++++++++++ ...e-setter-access-on-inner-arrow-function.js | 45 +++++++++++++++ ...ic-private-setter-access-on-inner-class.js | 44 +++++++++++++++ ...private-setter-access-on-inner-function.js | 47 ++++++++++++++++ .../class/elements/static-private-setter.js | 56 +++++++++++++++++++ 24 files changed, 778 insertions(+), 29 deletions(-) create mode 100644 test/language/expressions/class/elements/static-private-getter-access-on-inner-arrow-function.js create mode 100644 test/language/expressions/class/elements/static-private-getter-access-on-inner-class.js create mode 100644 test/language/expressions/class/elements/static-private-getter-access-on-inner-function.js create mode 100644 test/language/expressions/class/elements/static-private-getter.js create mode 100644 test/language/expressions/class/elements/static-private-setter-access-on-inner-arrow-function.js create mode 100644 test/language/expressions/class/elements/static-private-setter-access-on-inner-class.js create mode 100644 test/language/expressions/class/elements/static-private-setter-access-on-inner-function.js create mode 100644 test/language/expressions/class/elements/static-private-setter.js create mode 100644 test/language/statements/class/elements/static-private-getter-access-on-inner-arrow-function.js create mode 100644 test/language/statements/class/elements/static-private-getter-access-on-inner-class.js create mode 100644 test/language/statements/class/elements/static-private-getter-access-on-inner-function.js create mode 100644 test/language/statements/class/elements/static-private-getter.js create mode 100644 test/language/statements/class/elements/static-private-setter-access-on-inner-arrow-function.js create mode 100644 test/language/statements/class/elements/static-private-setter-access-on-inner-class.js create mode 100644 test/language/statements/class/elements/static-private-setter-access-on-inner-function.js create mode 100644 test/language/statements/class/elements/static-private-setter.js diff --git a/src/class-elements/static-private-getter-access-on-inner-arrow-function.case b/src/class-elements/static-private-getter-access-on-inner-arrow-function.case index 3088dadecd..6e41143193 100644 --- a/src/class-elements/static-private-getter-access-on-inner-arrow-function.case +++ b/src/class-elements/static-private-getter-access-on-inner-arrow-function.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. @@ -33,7 +33,6 @@ static access() { return arrowFunction(); } - //- assertions assert.sameValue(C.access(), 'Test262'); assert.throws(TypeError, function() { diff --git a/src/class-elements/static-private-getter-access-on-inner-class.case b/src/class-elements/static-private-getter-access-on-inner-class.case index f2fd9e12ea..c521d1eab8 100644 --- a/src/class-elements/static-private-getter-access-on-inner-class.case +++ b/src/class-elements/static-private-getter-access-on-inner-class.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. @@ -31,7 +31,6 @@ static Inner = class { return o.#f; } } - //- assertions assert.sameValue(C.Inner.access(C), 'Test262'); assert.throws(TypeError, function() { diff --git a/src/class-elements/static-private-getter-access-on-inner-function.case b/src/class-elements/static-private-getter-access-on-inner-function.case index 267269c527..0c91a47df6 100644 --- a/src/class-elements/static-private-getter-access-on-inner-function.case +++ b/src/class-elements/static-private-getter-access-on-inner-function.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. @@ -35,7 +35,6 @@ static access() { return innerFunction(); } - //- assertions assert.sameValue(C.access(), 'Test262'); assert.throws(TypeError, function() { diff --git a/src/class-elements/static-private-getter.case b/src/class-elements/static-private-getter.case index 8d472769e3..32e1ce01f2 100644 --- a/src/class-elements/static-private-getter.case +++ b/src/class-elements/static-private-getter.case @@ -4,26 +4,25 @@ /*--- desc: static private getter declaration and usage info: | - MethodDefinition : get ClassElementName () { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } ClassTail : ClassHeritage { ClassBody } - ... - 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, - a. PrivateBrandAdd(F, F). - 34. For each item fieldRecord in order from staticFields, - a. Perform ? DefineField(F, field). + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). PrivateFieldGet (P, O) 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", - ... + ... 6. Else, a. Assert: P.[[Kind]] is "accessor". b. If P does not have a [[Get]] field, throw a TypeError exception. @@ -45,7 +44,6 @@ static get #f() { static access() { return this.#f; } - //- assertions assert.sameValue(C.access(), 'Test262'); assert.throws(TypeError, function() { diff --git a/src/class-elements/static-private-setter-access-on-inner-arrow-function.case b/src/class-elements/static-private-setter-access-on-inner-arrow-function.case index 13b75a8d4e..1cc0de54ee 100644 --- a/src/class-elements/static-private-setter-access-on-inner-arrow-function.case +++ b/src/class-elements/static-private-setter-access-on-inner-arrow-function.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. @@ -33,7 +33,6 @@ static access() { arrowFunction(); } - //- assertions C.access(); assert.sameValue(C._v, 'Test262'); diff --git a/src/class-elements/static-private-setter-access-on-inner-class.case b/src/class-elements/static-private-setter-access-on-inner-class.case index 4e60da9881..f8e693845d 100644 --- a/src/class-elements/static-private-setter-access-on-inner-class.case +++ b/src/class-elements/static-private-setter-access-on-inner-class.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. diff --git a/src/class-elements/static-private-setter-access-on-inner-function.case b/src/class-elements/static-private-setter-access-on-inner-function.case index 176f6118f7..72d984c54e 100644 --- a/src/class-elements/static-private-setter-access-on-inner-function.case +++ b/src/class-elements/static-private-setter-access-on-inner-function.case @@ -8,7 +8,7 @@ info: | 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", a. Return P.[[Value]]. @@ -35,7 +35,6 @@ static access() { innerFunction(); } - //- assertions C.access(); assert.sameValue(C._v, 'Test262'); diff --git a/src/class-elements/static-private-setter.case b/src/class-elements/static-private-setter.case index bf1f387b02..20d0ae4d4b 100644 --- a/src/class-elements/static-private-setter.case +++ b/src/class-elements/static-private-setter.case @@ -4,26 +4,25 @@ /*--- desc: static private setter declaration and usage info: | - MethodDefinition : get ClassElementName () { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } ClassTail : ClassHeritage { ClassBody } - ... - 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, - a. PrivateBrandAdd(F, F). - 34. For each item fieldRecord in order from staticFields, - a. Perform ? DefineField(F, field). + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). PrivateFieldGet (P, O) 1. Assert: P is a Private Name. 2. If O is not an object, throw a TypeError exception. 3. If P.[[Kind]] is "field", - ... + ... 4. Perform ? PrivateBrandCheck(O, P). 5. If P.[[Kind]] is "method", - ... + ... 6. Else, a. Assert: P.[[Kind]] is "accessor". b. If P does not have a [[Get]] field, throw a TypeError exception. @@ -45,7 +44,6 @@ static set #f(v) { static access() { this.#f = 'Test262'; } - //- assertions C.access(); assert.sameValue(C._v, 'Test262'); diff --git a/test/language/expressions/class/elements/static-private-getter-access-on-inner-arrow-function.js b/test/language/expressions/class/elements/static-private-getter-access-on-inner-arrow-function.js new file mode 100644 index 0000000000..15dc2fec35 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-getter-access-on-inner-arrow-function.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-arrow-function.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private getter access inside of an arrow function (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static get #f() { + return 'Test262'; + } + + static access() { + const arrowFunction = () => { + return this.#f; + }; + + return arrowFunction(); + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an object which did not contain it'); diff --git a/test/language/expressions/class/elements/static-private-getter-access-on-inner-class.js b/test/language/expressions/class/elements/static-private-getter-access-on-inner-class.js new file mode 100644 index 0000000000..6234616c14 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-getter-access-on-inner-class.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-class.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private getter access inside of an inner class (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class-static-fields-public, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static get #f() { + return 'Test262'; + } + + static Inner = class { + static access(o) { + return o.#f; + } + } +} + +assert.sameValue(C.Inner.access(C), 'Test262'); +assert.throws(TypeError, function() { + C.Inner.access(C.Inner); +}, 'Accessed static private getter from an object which did not contain it'); diff --git a/test/language/expressions/class/elements/static-private-getter-access-on-inner-function.js b/test/language/expressions/class/elements/static-private-getter-access-on-inner-function.js new file mode 100644 index 0000000000..d30d146643 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-getter-access-on-inner-function.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-function.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private getter access inside of a nested function (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static get #f() { + return 'Test262'; + } + + static access() { + const self = this; + + function innerFunction() { + return self.#f; + } + + return innerFunction(); + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an arbitrary object'); diff --git a/test/language/expressions/class/elements/static-private-getter.js b/test/language/expressions/class/elements/static-private-getter.js new file mode 100644 index 0000000000..977238a2f2 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-getter.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private getter declaration and usage (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + MethodDefinition : + get ClassElementName () { FunctionBody } + set ClassElementName ( PropertySetParameterList ) { FunctionBody } + + ClassTail : ClassHeritage { ClassBody } + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). + + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + ... + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static get #f() { + return 'Test262'; + } + + static access() { + return this.#f; + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an arbitrary object'); diff --git a/test/language/expressions/class/elements/static-private-setter-access-on-inner-arrow-function.js b/test/language/expressions/class/elements/static-private-setter-access-on-inner-arrow-function.js new file mode 100644 index 0000000000..d914486a24 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-setter-access-on-inner-arrow-function.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-arrow-function.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private setter access inside of an arrow function (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static set #f(v) { + this._v = v; + } + + static access() { + const arrowFunction = () => { + this.#f = 'Test262'; + }; + + arrowFunction(); + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an object which did not contain it'); diff --git a/test/language/expressions/class/elements/static-private-setter-access-on-inner-class.js b/test/language/expressions/class/elements/static-private-setter-access-on-inner-class.js new file mode 100644 index 0000000000..da56cac677 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-setter-access-on-inner-class.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-class.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private setter access inside of an inner class (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class-static-fields-public, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static set #f(v) { + return this._v = v; + } + + static Inner = class { + static access(o) { + o.#f = 'Test262'; + } + } + +} + +C.Inner.access(C) +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.Inner.access(C.Inner); +}, 'Accessed static private setter from an object which did not contain it'); diff --git a/test/language/expressions/class/elements/static-private-setter-access-on-inner-function.js b/test/language/expressions/class/elements/static-private-setter-access-on-inner-function.js new file mode 100644 index 0000000000..14c355ab2f --- /dev/null +++ b/test/language/expressions/class/elements/static-private-setter-access-on-inner-function.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-function.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private setter access inside of a nested function (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static set #f(v) { + this._v = v; + } + + static access() { + const self = this; + + function innerFunction() { + self.#f = 'Test262'; + } + + innerFunction(); + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an arbitrary object'); diff --git a/test/language/expressions/class/elements/static-private-setter.js b/test/language/expressions/class/elements/static-private-setter.js new file mode 100644 index 0000000000..250e4243e7 --- /dev/null +++ b/test/language/expressions/class/elements/static-private-setter.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter.case +// - src/class-elements/default/cls-expr.template +/*--- +description: static private setter declaration and usage (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + MethodDefinition : + get ClassElementName () { FunctionBody } + set ClassElementName ( PropertySetParameterList ) { FunctionBody } + + ClassTail : ClassHeritage { ClassBody } + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). + + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + ... + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +var C = class { + static set #f(v) { + this._v = v; + } + + static access() { + this.#f = 'Test262'; + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an arbitrary object'); diff --git a/test/language/statements/class/elements/static-private-getter-access-on-inner-arrow-function.js b/test/language/statements/class/elements/static-private-getter-access-on-inner-arrow-function.js new file mode 100644 index 0000000000..3261f66d4b --- /dev/null +++ b/test/language/statements/class/elements/static-private-getter-access-on-inner-arrow-function.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-arrow-function.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private getter access inside of an arrow function (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static get #f() { + return 'Test262'; + } + + static access() { + const arrowFunction = () => { + return this.#f; + }; + + return arrowFunction(); + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an object which did not contain it'); diff --git a/test/language/statements/class/elements/static-private-getter-access-on-inner-class.js b/test/language/statements/class/elements/static-private-getter-access-on-inner-class.js new file mode 100644 index 0000000000..499178ee71 --- /dev/null +++ b/test/language/statements/class/elements/static-private-getter-access-on-inner-class.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-class.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private getter access inside of an inner class (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class-static-fields-public, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static get #f() { + return 'Test262'; + } + + static Inner = class { + static access(o) { + return o.#f; + } + } +} + +assert.sameValue(C.Inner.access(C), 'Test262'); +assert.throws(TypeError, function() { + C.Inner.access(C.Inner); +}, 'Accessed static private getter from an object which did not contain it'); diff --git a/test/language/statements/class/elements/static-private-getter-access-on-inner-function.js b/test/language/statements/class/elements/static-private-getter-access-on-inner-function.js new file mode 100644 index 0000000000..56dc3224a6 --- /dev/null +++ b/test/language/statements/class/elements/static-private-getter-access-on-inner-function.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter-access-on-inner-function.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private getter access inside of a nested function (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static get #f() { + return 'Test262'; + } + + static access() { + const self = this; + + function innerFunction() { + return self.#f; + } + + return innerFunction(); + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an arbitrary object'); diff --git a/test/language/statements/class/elements/static-private-getter.js b/test/language/statements/class/elements/static-private-getter.js new file mode 100644 index 0000000000..aaf044b420 --- /dev/null +++ b/test/language/statements/class/elements/static-private-getter.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-getter.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private getter declaration and usage (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + MethodDefinition : + get ClassElementName () { FunctionBody } + set ClassElementName ( PropertySetParameterList ) { FunctionBody } + + ClassTail : ClassHeritage { ClassBody } + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). + + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + ... + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static get #f() { + return 'Test262'; + } + + static access() { + return this.#f; + } +} + +assert.sameValue(C.access(), 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private getter from an arbitrary object'); diff --git a/test/language/statements/class/elements/static-private-setter-access-on-inner-arrow-function.js b/test/language/statements/class/elements/static-private-setter-access-on-inner-arrow-function.js new file mode 100644 index 0000000000..b32d5284f4 --- /dev/null +++ b/test/language/statements/class/elements/static-private-setter-access-on-inner-arrow-function.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-arrow-function.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private setter access inside of an arrow function (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static set #f(v) { + this._v = v; + } + + static access() { + const arrowFunction = () => { + this.#f = 'Test262'; + }; + + arrowFunction(); + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an object which did not contain it'); diff --git a/test/language/statements/class/elements/static-private-setter-access-on-inner-class.js b/test/language/statements/class/elements/static-private-setter-access-on-inner-class.js new file mode 100644 index 0000000000..6261ab722e --- /dev/null +++ b/test/language/statements/class/elements/static-private-setter-access-on-inner-class.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-class.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private setter access inside of an inner class (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class-static-fields-public, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static set #f(v) { + return this._v = v; + } + + static Inner = class { + static access(o) { + o.#f = 'Test262'; + } + } + +} + +C.Inner.access(C) +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.Inner.access(C.Inner); +}, 'Accessed static private setter from an object which did not contain it'); diff --git a/test/language/statements/class/elements/static-private-setter-access-on-inner-function.js b/test/language/statements/class/elements/static-private-setter-access-on-inner-function.js new file mode 100644 index 0000000000..486f67dacb --- /dev/null +++ b/test/language/statements/class/elements/static-private-setter-access-on-inner-function.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter-access-on-inner-function.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private setter access inside of a nested function (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + ... + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static set #f(v) { + this._v = v; + } + + static access() { + const self = this; + + function innerFunction() { + self.#f = 'Test262'; + } + + innerFunction(); + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an arbitrary object'); diff --git a/test/language/statements/class/elements/static-private-setter.js b/test/language/statements/class/elements/static-private-setter.js new file mode 100644 index 0000000000..a3d5a2d34a --- /dev/null +++ b/test/language/statements/class/elements/static-private-setter.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/static-private-setter.case +// - src/class-elements/default/cls-decl.template +/*--- +description: static private setter declaration and usage (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-static-methods-private, class] +flags: [generated] +info: | + MethodDefinition : + get ClassElementName () { FunctionBody } + set ClassElementName ( PropertySetParameterList ) { FunctionBody } + + ClassTail : ClassHeritage { ClassBody } + ... + 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, + a. PrivateBrandAdd(F, F). + 34. For each item fieldRecord in order from staticFields, + a. Perform ? DefineField(F, field). + + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + ... + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + ... + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + + PrivateBrandCheck(O, P) + 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, + a. Throw a TypeError exception. + +---*/ + + +class C { + static set #f(v) { + this._v = v; + } + + static access() { + this.#f = 'Test262'; + } +} + +C.access(); +assert.sameValue(C._v, 'Test262'); +assert.throws(TypeError, function() { + C.access.call({}); +}, 'Accessed static private setter from an arbitrary object');