Skip to content

Commit

Permalink
src: don't lazy-load timer globals
Browse files Browse the repository at this point in the history
Don't lazy-load setInterval(), setTimeout(), etc.  Most applications are
going to need them and routing every call through NativeModule.require()
and Function#apply() is not exactly efficient.

PR-URL: #1280
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
bnoordhuis committed Mar 26, 2015
1 parent 5e609e9 commit 2903410
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,13 @@
};

startup.globalTimeouts = function() {
global.setTimeout = function() {
var t = NativeModule.require('timers');
return t.setTimeout.apply(this, arguments);
};

global.setInterval = function() {
var t = NativeModule.require('timers');
return t.setInterval.apply(this, arguments);
};

global.clearTimeout = function() {
var t = NativeModule.require('timers');
return t.clearTimeout.apply(this, arguments);
};

global.clearInterval = function() {
var t = NativeModule.require('timers');
return t.clearInterval.apply(this, arguments);
};

global.setImmediate = function() {
var t = NativeModule.require('timers');
return t.setImmediate.apply(this, arguments);
};

global.clearImmediate = function() {
var t = NativeModule.require('timers');
return t.clearImmediate.apply(this, arguments);
};
const timers = NativeModule.require('timers');
global.clearImmediate = timers.clearImmediate;
global.clearInterval = timers.clearInterval;
global.clearTimeout = timers.clearTimeout;
global.setImmediate = timers.setImmediate;
global.setInterval = timers.setInterval;
global.setTimeout = timers.setTimeout;
};

startup.globalConsole = function() {
Expand Down

0 comments on commit 2903410

Please sign in to comment.