summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/expressions/class/private-static-getter-multiple-evaluations-of-class-direct-eval.js
blob: e849167ad9a39a9f0add912078c138f92de291fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// |reftest| shell-option(--enable-private-methods) skip-if(!xulRuntime.shell) -- requires shell-options
// Copyright (C) 2019 Caio Lima (Igalia SL). 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 Private Name (private static getter)
esid: sec-runtime-semantics-evaluate-name
info: |
  ClassTail : ClassHeritage { ClassBody }
    ...
    19. Let F be constructorInfo.[[Closure]].
    20. If ClassHeritage_opt is present and protoParent is not null, then set F.[[ConstructorKind]] to "derived".
    21. Perform MakeConstructor(F, false, proto).
    22. Perform MakeClassConstructor(F).
    ...
    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).
    ...

  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-static-methods-private]
flags: [noStrict]
---*/

let classStringExpression = `(
class {
  static get #m() {
    return 'Test262';
  };

  static access() {
    return this.#m;
  }
}
)`;

let evalClass = function () {
  return eval(classStringExpression);
};

let C1 = evalClass();
let C2 = evalClass();

assert.sameValue(C1.access(), 'Test262');
assert.sameValue(C2.access(), 'Test262');

assert.throws(TypeError, function() {
  C1.access.call(C2);
}, 'invalid access of C1 private static getter');

assert.throws(TypeError, function() {
  C2.access.call(C1);
}, 'invalid access of C2 private static getter');

reportCompare(0, 0);