summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/decorators/addInitializer.js
blob: 334de8f721af485ad8279546f9fa091a480a745d (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
// |jit-test| skip-if: !getBuildConfiguration("decorators")
load(libdir + "asserts.js");

let extraInitializerCalled = {};

function checkDecoratorContext(kind, isPrivate, isStatic, name) {
  return function (value, context) {
    if (kind == "field") {
      assertEq(value, undefined);
    } else if (kind == "accessor") {
      assertEq(typeof value, "object");
      assertEq(typeof value.get, "function");
      assertEq(typeof value.set, "function");
    }
    assertEq(context.kind, kind);
    assertEq(typeof context.access, "object");
    assertEq(context.private, isPrivate);
    assertEq(context.static, isStatic);
    assertEq(context.name, name);
    assertEq(typeof context.addInitializer, "function");
    context.addInitializer(() => {extraInitializerCalled[context.name] = true;});
    // return undefined
  }
}

class C {
  @checkDecoratorContext("field", false, false, "x") x;
  @checkDecoratorContext("accessor", true, false, "y accessor storage") accessor y;
  @checkDecoratorContext("method", false, false, "f") f() {};
  @checkDecoratorContext("method", false, false, 1) 1() {};
  @checkDecoratorContext("method", false, false, 2) 2n() {};
}

let c = new C();
assertEq(extraInitializerCalled["x"], true);
assertEq(extraInitializerCalled["y accessor storage"], true);
assertEq(extraInitializerCalled["f"], true);
assertEq(extraInitializerCalled["1"], true);
assertEq(extraInitializerCalled["2"], true);