diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-06-24 15:19:00 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-06-24 15:19:00 -0700 |
commit | c5e71efd7c3e43c36454192f6f2518de74a8ed78 (patch) | |
tree | 78f46cac73f934b617ca2ebbaa257c7b14ba641b | |
parent | a9fe85dee3470f9f4513e4c9a38c4cb25c657952 (diff) | |
parent | d2dd36b4558f483682f3c672630fdcb36a96d4d2 (diff) | |
download | async-c5e71efd7c3e43c36454192f6f2518de74a8ed78.tar.gz |
Merge pull request #804 from megawac/root-detection
Improve the detection of global/root object
-rw-r--r-- | .jshintrc | 1 | ||||
-rw-r--r-- | lib/async.js | 19 |
2 files changed, 9 insertions, 11 deletions
@@ -20,6 +20,7 @@ "browser": true, "node": true, "globals": { + "self": true, "define": true } } diff --git a/lib/async.js b/lib/async.js index 59ff57b..41d33cb 100644 --- a/lib/async.js +++ b/lib/async.js @@ -11,17 +11,14 @@ function noop() {} // global on the server, window in the browser - var root, previous_async; - - if (typeof window == 'object' && this === window) { - root = window; - } - else if (typeof global == 'object' && this === global) { - root = global; - } - else { - root = this; - } + var previous_async; + + // Establish the root object, `window` (`self`) in the browser, `global` + // on the server, or `this` in some virtual machines. We use `self` + // instead of `window` for `WebWorker` support. + var root = typeof self === 'object' && self.self === self && self || + typeof global === 'object' && global.global === global && global || + this; if (root != null) { previous_async = root.async; |