summaryrefslogtreecommitdiffstats
path: root/dom/base/test/unit/test_chromeutils_defineLazyGetter.js
blob: a3dae487cf2626df9f6b51d1e986ecc654586336 (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
"use strict";

add_task(function test_defineLazyGetter() {
  let accessCount = 0;
  let obj = {
    inScope: false,
  };
  const TEST_VALUE = "test value";
  ChromeUtils.defineLazyGetter(obj, "foo", function () {
    accessCount++;
    this.inScope = true;
    return TEST_VALUE;
  });
  Assert.equal(accessCount, 0);

  // Get the property, making sure the access count has increased.
  Assert.equal(obj.foo, TEST_VALUE);
  Assert.equal(accessCount, 1);
  Assert.ok(obj.inScope);

  // Get the property once more, making sure the access count has not
  // increased.
  Assert.equal(obj.foo, TEST_VALUE);
  Assert.equal(accessCount, 1);
});