Skip to content

Commit

Permalink
Inline canUseNextTick and installNextTickImplementation.
Browse files Browse the repository at this point in the history
A savings of 71 bytes uglified.
  • Loading branch information
benjamn committed Apr 22, 2014
1 parent 829cbce commit a50d455
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions setImmediate.js
Expand Up @@ -41,12 +41,6 @@
delete tasksByHandle[handle];
}

function canUseNextTick() {
// Don't get fooled by e.g. browserify environments.
return typeof process === "object" &&
Object.prototype.toString.call(process) === "[object process]";
}

function canUseMessageChannel() {
return !!global.MessageChannel;
}
Expand Down Expand Up @@ -74,18 +68,6 @@
return "document" in global && "onreadystatechange" in global.document.createElement("script");
}

function installNextTickImplementation(attachTo) {
attachTo.setImmediate = function () {
var handle = addFromSetImmediateArguments(arguments);

process.nextTick(function () {
runIfPresent(handle);
});

return handle;
};
}

function installMessageChannelImplementation(attachTo) {
var channel = new global.MessageChannel();
channel.port1.onmessage = function (event) {
Expand Down Expand Up @@ -175,9 +157,15 @@
var attachTo = getProto && getProto(global);
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;

if (canUseNextTick()) {
// Don't get fooled by e.g. browserify environments.
if (Object.prototype.toString.call(global.process) === "[object process]") {
// For Node.js before 0.9
installNextTickImplementation(attachTo);
attachTo.setImmediate = function() {
var handle = addFromSetImmediateArguments(arguments);
process.nextTick(runIfPresent.bind(undefined, handle));
return handle;
};

} else if (canUsePostMessage()) {
// For non-IE10 modern browsers
installPostMessageImplementation(attachTo);
Expand Down

0 comments on commit a50d455

Please sign in to comment.