Skip to content

Commit 2903410

Browse files
committed
src: don't lazy-load timer globals
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]>
1 parent 5e609e9 commit 2903410

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

src/node.js

+7-29
Original file line numberDiff line numberDiff line change
@@ -173,35 +173,13 @@
173173
};
174174

175175
startup.globalTimeouts = function() {
176-
global.setTimeout = function() {
177-
var t = NativeModule.require('timers');
178-
return t.setTimeout.apply(this, arguments);
179-
};
180-
181-
global.setInterval = function() {
182-
var t = NativeModule.require('timers');
183-
return t.setInterval.apply(this, arguments);
184-
};
185-
186-
global.clearTimeout = function() {
187-
var t = NativeModule.require('timers');
188-
return t.clearTimeout.apply(this, arguments);
189-
};
190-
191-
global.clearInterval = function() {
192-
var t = NativeModule.require('timers');
193-
return t.clearInterval.apply(this, arguments);
194-
};
195-
196-
global.setImmediate = function() {
197-
var t = NativeModule.require('timers');
198-
return t.setImmediate.apply(this, arguments);
199-
};
200-
201-
global.clearImmediate = function() {
202-
var t = NativeModule.require('timers');
203-
return t.clearImmediate.apply(this, arguments);
204-
};
176+
const timers = NativeModule.require('timers');
177+
global.clearImmediate = timers.clearImmediate;
178+
global.clearInterval = timers.clearInterval;
179+
global.clearTimeout = timers.clearTimeout;
180+
global.setImmediate = timers.setImmediate;
181+
global.setInterval = timers.setInterval;
182+
global.setTimeout = timers.setTimeout;
205183
};
206184

207185
startup.globalConsole = function() {

0 commit comments

Comments
 (0)