Skip to content

Commit ea359a1

Browse files
caiolimaleobalter
authored andcommitted
Added tests to cover access of private members on inner regular functions and arrow functions. (#2228)
1 parent 19b5a5a commit ea359a1

24 files changed

+978
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private field is visible on inner arrow function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-fields-private]
20+
---*/
21+
22+
//- elements
23+
#f = 'Test262';
24+
25+
method() {
26+
let arrowFunction = () => {
27+
return this.#f;
28+
}
29+
30+
return arrowFunction();
31+
}
32+
//- assertions
33+
let c = new C();
34+
assert.sameValue(c.method(), 'Test262');
35+
let o = {};
36+
assert.throws(TypeError, function() {
37+
c.method.call(o);
38+
}, 'accessed private field from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private field is visible on inner function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-fields-private]
20+
---*/
21+
22+
//- elements
23+
#f = 'Test262';
24+
25+
method() {
26+
let self = this;
27+
function innerFunction() {
28+
return self.#f;
29+
}
30+
31+
return innerFunction();
32+
}
33+
//- assertions
34+
let c = new C();
35+
assert.sameValue(c.method(), 'Test262');
36+
let o = {};
37+
assert.throws(TypeError, function() {
38+
c.method.call(o);
39+
}, 'accessed private field from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private getter is visible on inner arrow function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
get #m() { return 'Test262'; }
24+
25+
method() {
26+
let arrowFunction = () => {
27+
return this.#m;
28+
}
29+
30+
return arrowFunction();
31+
}
32+
//- assertions
33+
let c = new C();
34+
assert.sameValue(c.method(), 'Test262');
35+
let o = {};
36+
assert.throws(TypeError, function() {
37+
c.method.call(o);
38+
}, 'accessed private accessor from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private getter is visible on inner function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
get #m() { return 'Test262'; }
24+
25+
method() {
26+
let self = this;
27+
function innerFunction() {
28+
return self.#m;
29+
}
30+
31+
return innerFunction();
32+
}
33+
//- assertions
34+
let c = new C();
35+
assert.sameValue(c.method(), 'Test262');
36+
let o = {};
37+
assert.throws(TypeError, function() {
38+
c.method.call(o);
39+
}, 'accessed private accessor from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private method is visible on inner arrow function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
#m() { return 'Test262'; }
24+
25+
method() {
26+
let arrowFunction = () => {
27+
return this.#m();
28+
}
29+
30+
return arrowFunction();
31+
}
32+
//- assertions
33+
let c = new C();
34+
assert.sameValue(c.method(), 'Test262');
35+
let o = {};
36+
assert.throws(TypeError, function() {
37+
c.method.call(o);
38+
}, 'accessed private method from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private method is visible on inner function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
#m() { return 'Test262'; }
24+
25+
method() {
26+
let self = this;
27+
function innerFunction() {
28+
return self.#m();
29+
}
30+
31+
return innerFunction();
32+
}
33+
//- assertions
34+
let c = new C();
35+
assert.sameValue(c.method(), 'Test262');
36+
let o = {};
37+
assert.throws(TypeError, function() {
38+
c.method.call(o);
39+
}, 'accessed private method from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private setter is visible on inner arrow function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
set #m(v) { this._v = v; }
24+
25+
method() {
26+
let arrowFunction = () => {
27+
this.#m = 'Test262';
28+
}
29+
30+
arrowFunction();
31+
}
32+
//- assertions
33+
let c = new C();
34+
c.method();
35+
assert.sameValue(c._v, 'Test262');
36+
let o = {};
37+
assert.throws(TypeError, function() {
38+
c.method.call(o);
39+
}, 'accessed private setter from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
desc: PrivateName of private setter is visible on inner function of class scope
6+
info: |
7+
Updated Productions
8+
9+
CallExpression[Yield, Await]:
10+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
11+
SuperCall[?Yield, ?Await]
12+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
13+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
14+
CallExpression[?Yield, ?Await].IdentifierName
15+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await].PrivateName
17+
18+
template: default
19+
features: [class-methods-private]
20+
---*/
21+
22+
//- elements
23+
set #m(v) { this._v = v; }
24+
25+
method() {
26+
let self = this;
27+
function innerFunction() {
28+
self.#m = 'Test262';
29+
}
30+
31+
innerFunction();
32+
}
33+
//- assertions
34+
let c = new C();
35+
c.method();
36+
assert.sameValue(c._v, 'Test262');
37+
let o = {};
38+
assert.throws(TypeError, function() {
39+
c.method.call(o);
40+
}, 'accessed private setter from an ordinary object');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/class-elements/private-field-access-on-inner-arrow-function.case
3+
// - src/class-elements/default/cls-expr.template
4+
/*---
5+
description: PrivateName of private field is visible on inner arrow function of class scope (field definitions in a class expression)
6+
esid: prod-FieldDefinition
7+
features: [class-fields-private, class]
8+
flags: [generated]
9+
info: |
10+
Updated Productions
11+
12+
CallExpression[Yield, Await]:
13+
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
14+
SuperCall[?Yield, ?Await]
15+
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
16+
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
17+
CallExpression[?Yield, ?Await].IdentifierName
18+
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
19+
CallExpression[?Yield, ?Await].PrivateName
20+
21+
---*/
22+
23+
24+
var C = class {
25+
#f = 'Test262';
26+
27+
method() {
28+
let arrowFunction = () => {
29+
return this.#f;
30+
}
31+
32+
return arrowFunction();
33+
}
34+
}
35+
36+
let c = new C();
37+
assert.sameValue(c.method(), 'Test262');
38+
let o = {};
39+
assert.throws(TypeError, function() {
40+
c.method.call(o);
41+
}, 'accessed private field from an ordinary object');

0 commit comments

Comments
 (0)