File: windowIsClosed.js

package info (click to toggle)
greasemonkey 2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,820 kB
  • sloc: xml: 171; makefile: 10
file content (32 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (2)
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
Components.utils.import('resource://greasemonkey/util.js');

const EXPORTED_SYMBOLS = ['windowIsClosed'];

var Cu = Components.utils;

/*
Accessing windows that are closed can be dangerous after
http://bugzil.la/695480 .  This routine takes care of being careful to not
trigger any of those broken edge cases.
*/
function windowIsClosed(aWin) {
  try {
    // If isDeadWrapper (Firefox 15+ only) tells us the window is dead.
    if (Cu.isDeadWrapper && Cu.isDeadWrapper(aWin)) {
      return true;
    }

    // If we can access the .closed property and it is true, or there is any
    // problem accessing that property.
    try {
      if (aWin.closed) return true;
    } catch (e) {
      return true;
    }
  } catch (e) {
    Cu.reportError(e);
    // Failsafe.  In case of any failure, destroy the command to avoid leaks.
    return true;
  }
  return false;
}