diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-06-24 10:30:31 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-06-24 11:41:37 -0400 |
commit | d2dd36b4558f483682f3c672630fdcb36a96d4d2 (patch) | |
tree | b6f5dd183cbd14df389513a0950e1bb9da79fe47 /lib/async.js | |
parent | 4722bb5703d7c53ed802e6d21c951cee061e9181 (diff) | |
download | async-d2dd36b4558f483682f3c672630fdcb36a96d4d2.tar.gz |
Improve the detection of global/root object
Diffstat (limited to 'lib/async.js')
-rw-r--r-- | lib/async.js | 19 |
1 files changed, 8 insertions, 11 deletions
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; |