diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval-indirect.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval-indirect.js new file mode 100644 index 0000000000..e3cc5a6d4f --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval-indirect.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class { + get #m() { return 'test262'; } + + access(o) { + return o.#m; + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval); +let c2 = createAndInstantiateClass(eval); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval.js new file mode 100644 index 0000000000..e695ea2106 --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class { + get #m() { return 'test262'; } + + access(o) { + return o.#m; + } +} +)`; + +let createAndInstantiateClass = function () { + return new (eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-factory.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-factory.js new file mode 100644 index 0000000000..732cb1904f --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-factory.js @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let createAndInstantiateClass = function () { + const C = class { + get #m() { return 'test262'; } + + access(o) { + return o.#m; + } + } + + let c = new C(); + return c; +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-function-ctor.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-function-ctor.js new file mode 100644 index 0000000000..55f7406ca4 --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-function-ctor.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class { + get m() { return 'test262'; } + + access(o) { + return o.m; + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new Function(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js new file mode 100644 index 0000000000..5dcf1e31ef --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class { + get #m() { return 'test262'; } + + access(o) { + return o.#m; + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new ($262.createRealm().global.Function)(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm.js b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm.js new file mode 100644 index 0000000000..a28754571f --- /dev/null +++ b/test/language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-realm.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private getter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let eval1 = $262.createRealm().global.eval; +let eval2 = $262.createRealm().global.eval; + +let classStringExpression = `( +class { + get #m() { return 'test262'; } + + access(o) { + return o.#m; + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval1); +let c2 = createAndInstantiateClass(eval2); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval-indirect.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval-indirect.js new file mode 100644 index 0000000000..eac02682f2 --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval-indirect.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class C { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval); +let c2 = createAndInstantiateClass(eval); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval.js new file mode 100644 index 0000000000..4cc49d8cb1 --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class C { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } +} +)`; + +let createAndInstantiateClass = function () { + return new (eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-factory.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-factory.js new file mode 100644 index 0000000000..094165ed68 --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-factory.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let createAndInstantiateClass = function () { + const C = class { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } + } + + return new C(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-function-ctor.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-function-ctor.js new file mode 100644 index 0000000000..6e23740916 --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-function-ctor.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class C { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new Function(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm-function-ctor.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm-function-ctor.js new file mode 100644 index 0000000000..094df6a6c6 --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm-function-ctor.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class C { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new ($262.createRealm().global.Function)(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm.js b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm.js new file mode 100644 index 0000000000..49657c84af --- /dev/null +++ b/test/language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-realm.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private method) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let eval1 = $262.createRealm().global.eval; +let eval2 = $262.createRealm().global.eval; + +let classStringExpression = `( +class { + #m() { return 'test262'; } + + access(o) { + return o.#m(); + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval1); +let c2 = createAndInstantiateClass(eval2); + +assert.sameValue(c1.access(c1), 'test262'); +assert.sameValue(c2.access(c2), 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval-indirect.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval-indirect.js new file mode 100644 index 0000000000..18e5558e5a --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval-indirect.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval); +let c2 = createAndInstantiateClass(eval); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval.js new file mode 100644 index 0000000000..091cff4af9 --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let classStringExpression = `( +class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } +} +)`; + +let createAndInstantiateClass = function () { + return new (eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-factory.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-factory.js new file mode 100644 index 0000000000..58771e30f6 --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-factory.js @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let createAndInstantiateClass = function () { + const C = class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } + } + + return new C(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-function-ctor.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-function-ctor.js new file mode 100644 index 0000000000..86722d023d --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-function-ctor.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new Function(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js new file mode 100644 index 0000000000..0c5eff4b1b --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm-function-ctor.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +---*/ + +let classStringExpression = ` +return class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } +} +`; + +let createAndInstantiateClass = function () { + let classFactoryFunction = new ($262.createRealm().global.Function)(classStringExpression); + let Class = classFactoryFunction(); + return new Class(); +}; + +let c1 = createAndInstantiateClass(); +let c2 = createAndInstantiateClass(); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm.js b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm.js new file mode 100644 index 0000000000..35a42d3643 --- /dev/null +++ b/test/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm.js @@ -0,0 +1,54 @@ +// Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Every new evaluation of a class creates a different brand (private setter) +esid: sec-privatefieldget +info: | + ClassTail : ClassHeritage { ClassBody } + ... + 11. Let proto be ObjectCreate(protoParent). + ... + 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor", + a. Set F.[[PrivateBrand]] to proto. + ... + + 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. +features: [class, class-methods-private] +flags: [noStrict] +---*/ + +let eval1 = $262.createRealm().global.eval; +let eval2 = $262.createRealm().global.eval; + +let classStringExpression = `( +class { + set #m(v) { this._v = v; } + + access(o, v) { + o.#m = v; + } +} +)`; + +let createAndInstantiateClass = function (_eval) { + return new (_eval(classStringExpression)); +}; + +let c1 = createAndInstantiateClass(eval1); +let c2 = createAndInstantiateClass(eval2); + +c1.access(c1, 'test262'); +assert.sameValue(c1._v, 'test262'); +c2.access(c2, 'test262'); +assert.sameValue(c2._v, 'test262'); + +assert.throws(TypeError, function() { + c1.access(c2, 'foo'); +}, 'invalid access of c1 private method'); + +assert.throws(TypeError, function() { + c2.access(c1, 'foo'); +}, 'invalid access of c2 private method'); diff --git a/test/language/statements/class/elements/private-getter-brand-check-multiple-evaluations-of-class.js b/test/language/statements/class/elements/private-getter-brand-check-multiple-evaluations-of-class.js index b20ba45630..2774984b19 100644 --- a/test/language/statements/class/elements/private-getter-brand-check-multiple-evaluations-of-class.js +++ b/test/language/statements/class/elements/private-getter-brand-check-multiple-evaluations-of-class.js @@ -22,12 +22,12 @@ features: [class, class-methods-private] let createAndInstantiateClass = function () { class C { get #m() { return 'test262'; } - + access(o) { return o.#m; } } - + let c = new C(); return c; };