Add test for multiple evaluations of classes with private (#2176)

This commit is contained in:
Jaideep Bhoosreddy 2019-06-26 15:05:10 -04:00 committed by Leo Balter
parent d7c95efe66
commit 51fc533565
19 changed files with 903 additions and 2 deletions

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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;
};