summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit/AllowJavascriptParent.sys.mjs
blob: 5631fcdb0907d5342c50a21867141192f84349a3 (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
let loadPromises = new WeakMap();

export class AllowJavascriptParent extends JSWindowActorParent {
  async receiveMessage(msg) {
    switch (msg.name) {
      case "LoadFired":
        let bc = this.browsingContext;
        let deferred = loadPromises.get(bc);
        if (deferred) {
          loadPromises.delete(bc);
          deferred.resolve(this);
        }
        break;
    }
  }

  static promiseLoad(bc) {
    let deferred = loadPromises.get(bc);
    if (!deferred) {
      deferred = {};
      deferred.promise = new Promise(resolve => {
        deferred.resolve = resolve;
      });
      loadPromises.set(bc, deferred);
    }
    return deferred.promise;
  }
}