summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2015-06-24 15:19:00 -0700
committerAlexander Early <alexander.early@gmail.com>2015-06-24 15:19:00 -0700
commitc5e71efd7c3e43c36454192f6f2518de74a8ed78 (patch)
tree78f46cac73f934b617ca2ebbaa257c7b14ba641b
parenta9fe85dee3470f9f4513e4c9a38c4cb25c657952 (diff)
parentd2dd36b4558f483682f3c672630fdcb36a96d4d2 (diff)
downloadasync-c5e71efd7c3e43c36454192f6f2518de74a8ed78.tar.gz
Merge pull request #804 from megawac/root-detection
Improve the detection of global/root object
-rw-r--r--.jshintrc1
-rw-r--r--lib/async.js19
2 files changed, 9 insertions, 11 deletions
diff --git a/.jshintrc b/.jshintrc
index 7427dce..c66d74c 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -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;