summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxant <xant@xant.net>2013-07-12 00:17:17 (GMT)
committer xant <xant@xant.net>2013-07-12 00:17:17 (GMT)
commit2dc5f0e9c9975b0080d3a5a3f4c3484eefce7c78 (patch)
treeea64d71d5e98efbced5b81d0dbe1be7dbddbec2e
parent52651d92b6c5bf56d09b079540f6d36ce678be24 (diff)
minor changes to node.js to have timeouts and intervals working again properly on jmx
and to allow creating separated global contexts when loading multiple files
-rw-r--r--node.js/src/node.js33
1 files changed, 30 insertions, 3 deletions
diff --git a/node.js/src/node.js b/node.js/src/node.js
index e5833cb..88b68b0 100644
--- a/node.js/src/node.js
+++ b/node.js/src/node.js
@@ -169,26 +169,48 @@
};
startup.globalTimeouts = function() {
+ _timeouts = new Array();
+ _intervals = new Array();
+
global.setTimeout = function() {
var t = NativeModule.require('timers');
- return t.setTimeout.apply(this, arguments);
+ timer = t.setTimeout.apply(this, arguments);
+ _timeouts.push(timer);
+ return timer;
};
global.setInterval = function() {
var t = NativeModule.require('timers');
- return t.setInterval.apply(this, arguments);
+ timer = t.setInterval.apply(this, arguments);
+ _intervals.push(timer);
+ return timer;
};
global.clearTimeout = function() {
var t = NativeModule.require('timers');
+ var i = _timeouts.indexOf(arguments[0]);
+ if(i != -1) {
+ _timeouts.splice(i, 1);
+ }
return t.clearTimeout.apply(this, arguments);
};
global.clearInterval = function() {
var t = NativeModule.require('timers');
+ var i = _intervals.indexOf(arguments[0]);
+ if(i != -1) {
+ _intervals.splice(i, 1);
+ }
return t.clearInterval.apply(this, arguments);
};
+ global.clearAllTimers = function() {
+ for (i in _intervals)
+ global.clearInterval(_intervals[i]);
+ for (i in _timeouts)
+ global.clearTimeout(_timeouts[i]);
+ }
+
global.setImmediate = function() {
var t = NativeModule.require('timers');
return t.setImmediate.apply(this, arguments);
@@ -305,6 +327,8 @@
var config = NativeModule._source.config;
delete NativeModule._source.config;
+ if (!config)
+ return;
// strip the gyp comment line at the beginning
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
@@ -409,7 +433,10 @@
return tickDone(0);
while (infoBox[index] < nextTickLength) {
- callback = nextTickQueue[infoBox[index]++].callback;
+ obj = nextTickQueue[infoBox[index]++];
+ if (!obj)
+ continue;
+ callback = obj.callback;
threw = true;
try {
callback();