diff --git a/lib/dgram.js b/lib/dgram.js index 7325b67bb1..d374d1d131 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -4,7 +4,7 @@ var events = require("events"); var dns = require('dns'); var Buffer = require('buffer').Buffer; -var IOWatcher = process.IOWatcher; +var IOWatcher = process.binding('io_watcher').IOWatcher; var binding = process.binding('net'); var socket = binding.socket; var recvfrom = binding.recvfrom; diff --git a/lib/dns.js b/lib/dns.js index 8f9ce768be..2f033bb0a6 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -1,12 +1,13 @@ var dns = process.binding('cares'); var net = process.binding('net'); +var IOWatcher = process.binding('io_watcher').IOWatcher; var watchers = {}; var activeWatchers = {}; +var Timer = process.binding('timer').Timer; - -var timer = new process.Timer(); +var timer = new Timer(); timer.callback = function () { var sockets = Object.keys(activeWatchers); @@ -44,7 +45,7 @@ var channel = new dns.Channel({SOCK_STATE_CB: function (socket, read, write) { if (socket in watchers) { watcher = watchers[socket].watcher; } else { - watcher = new process.IOWatcher(); + watcher = new IOWatcher(); watchers[socket] = { read: read , write: write , watcher: watcher diff --git a/lib/net.js b/lib/net.js index be862dcec9..ced5ca771c 100644 --- a/lib/net.js +++ b/lib/net.js @@ -23,7 +23,8 @@ var binding = process.binding('net'); var Buffer = require('buffer').Buffer; var FreeList = require('freelist').FreeList; -var IOWatcher = process.IOWatcher; +var IOWatcher = process.binding('io_watcher').IOWatcher; +var Timer = process.binding('timer').Timer; var assert = process.assert; var socket = binding.socket; @@ -125,7 +126,7 @@ var timeout = new (function () { if (lists[msecs]) { list = lists[msecs]; } else { - list = new process.Timer(); + list = new Timer(); list._idleNext = list; list._idlePrev = list; diff --git a/src/node.cc b/src/node.cc index 1bbd03e977..8aa33cb0f5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1464,6 +1464,16 @@ static Handle Binding(const Arguments& args) { DefineConstants(exports); binding_cache->Set(module, exports); + } else if (!strcmp(*module_v, "io_watcher")) { + exports = Object::New(); + IOWatcher::Initialize(exports); + binding_cache->Set(module, exports); + + } else if (!strcmp(*module_v, "timer")) { + exports = Object::New(); + Timer::Initialize(exports); + binding_cache->Set(module, exports); + } else if (!strcmp(*module_v, "natives")) { exports = Object::New(); // Explicitly define native sources. @@ -1620,14 +1630,6 @@ static void Load(int argc, char *argv[]) { process->Set(String::NewSymbol("EventEmitter"), EventEmitter::constructor_template->GetFunction()); - - // Initialize the C++ modules..................filename of module - IOWatcher::Initialize(process); // io_watcher.cc - // Not in use at the moment. - //IdleWatcher::Initialize(process); // idle_watcher.cc - Timer::Initialize(process); // timer.cc - // coverity[stack_use_callee] - // Compile, execute the src/node.js file. (Which was included as static C // string in node_natives.h. 'natve_node' is the string containing that // source code.) diff --git a/src/node.js b/src/node.js index d504e10bec..cd5696587a 100644 --- a/src/node.js +++ b/src/node.js @@ -158,28 +158,34 @@ function addTimerListener (callback) { } } +var Timer; // lazy load + global.setTimeout = function (callback, after) { - var timer = new process.Timer(); + if (!Timer) Timer = process.binding("timer").Timer; + var timer = new Timer(); addTimerListener.apply(timer, arguments); timer.start(after, 0); return timer; }; global.setInterval = function (callback, repeat) { - var timer = new process.Timer(); + if (!Timer) Timer = process.binding("timer").Timer; + var timer = new Timer(); addTimerListener.apply(timer, arguments); timer.start(repeat, repeat ? repeat : 1); return timer; }; global.clearTimeout = function (timer) { - if (timer instanceof process.Timer) { + if (!Timer) Timer = process.binding("timer").Timer; + if (timer instanceof Timer) { timer.stop(); } }; global.clearInterval = global.clearTimeout; + var stdout; process.__defineGetter__('stdout', function () { if (stdout) return stdout;