Debian Codegraph @

js/src/jit-test/tests/decorators/decorator-this.js

raw
1 // |jit-test| skip-if: !getBuildConfiguration("decorators")
2
3 load(libdir + "asserts.js");
4
5 let globalDecCalled = false;
6 function globalDec(value, context) {
7 globalDecCalled = true;
8 assertEq(this, globalThis);
9 }
10
11 // Forward declare c to be able to check it inside of C when running decorators.
12 let c;
13 let classDecCalled = false;
14 class C {
15 classDec(value, context) {
16 classDecCalled = true;
17 // At this point, `this` is an instance of C
18 assertEq(c, this);
19 return function(initialValue) {
20 // At this point, `this` is an instance of D
21 assertEq(this instanceof D, true);
22 return initialValue;
23 }
24 }
25 }
26
27 c = new C();
28
29 class D {
30 @globalDec x1;
31 @c.classDec x2;
32 }
33
34 let d = new D();
35 assertEq(globalDecCalled, true);
36 assertEq(classDecCalled, true);