Skip to content

Commit 1a9f4ba

Browse files
committed
Fix for getting global context in recent Firefox and Thunderbird
If we can't get the global contest from either `global` or `window` and `Cu.getGlobalForObject` exists, then use that. See https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.getGlobalForObject. Fixes andrewplummer#627.
1 parent 4adba2e commit 1a9f4ba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/core.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ var DefaultChainable = getNewChainableClass('Chainable');
5050
function getGlobal() {
5151
// Get global context by keyword here to avoid issues with libraries
5252
// that can potentially alter this script's context object.
53-
return testGlobal(typeof global !== 'undefined' && global) ||
54-
testGlobal(typeof window !== 'undefined' && window);
53+
var ret = testGlobal(typeof global !== 'undefined' && global) ||
54+
testGlobal(typeof window !== 'undefined' && window);
55+
if (ret) return ret;
56+
// Firefox / Thunderbird specific
57+
if (typeof Cu != 'undefined' && typeof Cu.getGlobalForObject != 'undefined')
58+
ret = testGlobal(Cu.getGlobalForObject(getGlobal));
59+
return ret;
5560
}
5661

5762
function testGlobal(obj) {

0 commit comments

Comments
 (0)