Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the detection of global/root object #804

Merged
merged 1 commit into from
Jun 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"browser": true,
"node": true,
"globals": {
"self": true,
"define": true
}
}
19 changes: 8 additions & 11 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down