summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/decorators/decorator-this.js
blob: b545729ca4b9cdba30dc43838d5f28ee19aaef9c (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
// |jit-test| skip-if: !getBuildConfiguration("decorators")

load(libdir + "asserts.js");

let globalDecCalled = false;
function globalDec(value, context) {
  globalDecCalled = true;
  assertEq(this, globalThis);
}

// Forward declare c to be able to check it inside of C when running decorators.
let c;
let classDecCalled = false;
class C {
  classDec(value, context) {
    classDecCalled = true;
    // At this point, `this` is an instance of C
    assertEq(c, this);
    return function(initialValue) {
      // At this point, `this` is an instance of D
      assertEq(this instanceof D, true);
      return initialValue;
    }
  }
}

c = new C();

class D {
  @globalDec x1;
  @c.classDec x2;
}

let d = new D();
assertEq(globalDecCalled, true);
assertEq(classDecCalled, true);