Debian Codegraph @

js/src/jit-test/tests/decorators/addInitializer.js

raw
1 // |jit-test| skip-if: !getBuildConfiguration("decorators")
2 load(libdir + "asserts.js");
3
4 let extraInitializerCalled = {};
5
6 function checkDecoratorContext(kind, isPrivate, isStatic, name) {
7 return function (value, context) {
8 if (kind == "field") {
9 assertEq(value, undefined);
10 } else if (kind == "accessor") {
11 assertEq(typeof value, "object");
12 assertEq(typeof value.get, "function");
13 assertEq(typeof value.set, "function");
14 }
15 assertEq(context.kind, kind);
16 assertEq(typeof context.access, "object");
17 assertEq(context.private, isPrivate);
18 assertEq(context.static, isStatic);
19 assertEq(context.name, name);
20 assertEq(typeof context.addInitializer, "function");
21 context.addInitializer(() => {extraInitializerCalled[context.name] = true;});
22 // return undefined
23 }
24 }
25
26 class C {
27 @checkDecoratorContext("field", false, false, "x") x;
28 @checkDecoratorContext("accessor", true, false, "y accessor storage") accessor y;
29 @checkDecoratorContext("method", false, false, "f") f() {};
30 @checkDecoratorContext("method", false, false, 1) 1() {};
31 @checkDecoratorContext("method", false, false, 2) 2n() {};
32 }
33
34 let c = new C();
35 assertEq(extraInitializerCalled["x"], true);
36 assertEq(extraInitializerCalled["y accessor storage"], true);
37 assertEq(extraInitializerCalled["f"], true);
38 assertEq(extraInitializerCalled["1"], true);
39 assertEq(extraInitializerCalled["2"], true);