Browse Source

Load c++ modules on demand

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
627fb5adbb
  1. 2
      lib/dns.js
  2. 124
      lib/fs.js
  3. 22
      lib/http.js
  4. 6
      lib/tcp.js
  5. 107
      src/node.cc
  6. 5
      src/node.js
  7. 4
      src/node_stat.cc

2
lib/dns.js

@ -1,4 +1,4 @@
var events = require('events'); process.binding('dns');
exports.resolve = function (domain, type_, callback_) { exports.resolve = function (domain, type_, callback_) {
var type, callback; var type, callback;

124
lib/fs.js

@ -1,45 +1,45 @@
var sys = require('sys'), var sys = require('sys'),
events = require('events'); events = require('events');
var fs = exports; var fs = process.binding('fs');
exports.Stats = process.Stats; exports.Stats = fs.Stats;
process.Stats.prototype._checkModeProperty = function (property) { fs.Stats.prototype._checkModeProperty = function (property) {
return ((this.mode & property) === property); return ((this.mode & property) === property);
}; };
process.Stats.prototype.isDirectory = function () { fs.Stats.prototype.isDirectory = function () {
return this._checkModeProperty(process.S_IFDIR); return this._checkModeProperty(process.S_IFDIR);
}; };
process.Stats.prototype.isFile = function () { fs.Stats.prototype.isFile = function () {
return this._checkModeProperty(process.S_IFREG); return this._checkModeProperty(process.S_IFREG);
}; };
process.Stats.prototype.isBlockDevice = function () { fs.Stats.prototype.isBlockDevice = function () {
return this._checkModeProperty(process.S_IFBLK); return this._checkModeProperty(process.S_IFBLK);
}; };
process.Stats.prototype.isCharacterDevice = function () { fs.Stats.prototype.isCharacterDevice = function () {
return this._checkModeProperty(process.S_IFCHR); return this._checkModeProperty(process.S_IFCHR);
}; };
process.Stats.prototype.isSymbolicLink = function () { fs.Stats.prototype.isSymbolicLink = function () {
return this._checkModeProperty(process.S_IFLNK); return this._checkModeProperty(process.S_IFLNK);
}; };
process.Stats.prototype.isFIFO = function () { fs.Stats.prototype.isFIFO = function () {
return this._checkModeProperty(process.S_IFIFO); return this._checkModeProperty(process.S_IFIFO);
}; };
process.Stats.prototype.isSocket = function () { fs.Stats.prototype.isSocket = function () {
return this._checkModeProperty(process.S_IFSOCK); return this._checkModeProperty(process.S_IFSOCK);
}; };
function readAll (fd, pos, content, encoding, callback) { function readAll (fd, pos, content, encoding, callback) {
process.fs.read(fd, 4*1024, pos, encoding, function (err, chunk, bytesRead) { fs.read(fd, 4*1024, pos, encoding, function (err, chunk, bytesRead) {
if (err) { if (err) {
if (callback) callback(err); if (callback) callback(err);
} else if (chunk) { } else if (chunk) {
@ -47,7 +47,7 @@ function readAll (fd, pos, content, encoding, callback) {
pos += bytesRead; pos += bytesRead;
readAll(fd, pos, content, encoding, callback); readAll(fd, pos, content, encoding, callback);
} else { } else {
process.fs.close(fd, function (err) { fs.close(fd, function (err) {
if (callback) callback(err, content); if (callback) callback(err, content);
}); });
} }
@ -58,7 +58,7 @@ exports.readFile = function (path, encoding_, callback) {
var encoding = typeof(encoding_) == 'string' ? encoding_ : 'utf8'; var encoding = typeof(encoding_) == 'string' ? encoding_ : 'utf8';
var callback_ = arguments[arguments.length - 1]; var callback_ = arguments[arguments.length - 1];
var callback = (typeof(callback_) == 'function' ? callback_ : null); var callback = (typeof(callback_) == 'function' ? callback_ : null);
process.fs.open(path, process.O_RDONLY, 0666, function (err, fd) { fs.open(path, process.O_RDONLY, 0666, function (err, fd) {
if (err) { if (err) {
if (callback) callback(err); if (callback) callback(err);
} else { } else {
@ -70,17 +70,17 @@ exports.readFile = function (path, encoding_, callback) {
exports.readFileSync = function (path, encoding) { exports.readFileSync = function (path, encoding) {
encoding = encoding || "utf8"; // default to utf8 encoding = encoding || "utf8"; // default to utf8
var fd = process.fs.open(path, process.O_RDONLY, 0666); var fd = fs.open(path, process.O_RDONLY, 0666);
var content = ''; var content = '';
var pos = 0; var pos = 0;
var r; var r;
while ((r = process.fs.read(fd, 4*1024, pos, encoding)) && r[0]) { while ((r = fs.read(fd, 4*1024, pos, encoding)) && r[0]) {
content += r[0]; content += r[0];
pos += r[1] pos += r[1]
} }
process.fs.close(fd); fs.close(fd);
return content; return content;
}; };
@ -109,145 +109,145 @@ function noop () {}
// list to make the arguments clear. // list to make the arguments clear.
exports.close = function (fd, callback) { exports.close = function (fd, callback) {
process.fs.close(fd, callback || noop); fs.close(fd, callback || noop);
}; };
exports.closeSync = function (fd) { exports.closeSync = function (fd) {
return process.fs.close(fd); return fs.close(fd);
}; };
exports.open = function (path, flags, mode, callback) { exports.open = function (path, flags, mode, callback) {
if (mode === undefined) { mode = 0666; } if (mode === undefined) { mode = 0666; }
process.fs.open(path, stringToFlags(flags), mode, callback || noop); fs.open(path, stringToFlags(flags), mode, callback || noop);
}; };
exports.openSync = function (path, flags, mode) { exports.openSync = function (path, flags, mode) {
if (mode === undefined) { mode = 0666; } if (mode === undefined) { mode = 0666; }
return process.fs.open(path, stringToFlags(flags), mode); return fs.open(path, stringToFlags(flags), mode);
}; };
exports.read = function (fd, length, position, encoding, callback) { exports.read = function (fd, length, position, encoding, callback) {
encoding = encoding || "binary"; encoding = encoding || "binary";
process.fs.read(fd, length, position, encoding, callback || noop); fs.read(fd, length, position, encoding, callback || noop);
}; };
exports.readSync = function (fd, length, position, encoding) { exports.readSync = function (fd, length, position, encoding) {
encoding = encoding || "binary"; encoding = encoding || "binary";
return process.fs.read(fd, length, position, encoding); return fs.read(fd, length, position, encoding);
}; };
exports.write = function (fd, data, position, encoding, callback) { exports.write = function (fd, data, position, encoding, callback) {
encoding = encoding || "binary"; encoding = encoding || "binary";
process.fs.write(fd, data, position, encoding, callback || noop); fs.write(fd, data, position, encoding, callback || noop);
}; };
exports.writeSync = function (fd, data, position, encoding) { exports.writeSync = function (fd, data, position, encoding) {
encoding = encoding || "binary"; encoding = encoding || "binary";
return process.fs.write(fd, data, position, encoding); return fs.write(fd, data, position, encoding);
}; };
exports.rename = function (oldPath, newPath, callback) { exports.rename = function (oldPath, newPath, callback) {
process.fs.rename(oldPath, newPath, callback || noop); fs.rename(oldPath, newPath, callback || noop);
}; };
exports.renameSync = function (oldPath, newPath) { exports.renameSync = function (oldPath, newPath) {
return process.fs.rename(oldPath, newPath); return fs.rename(oldPath, newPath);
}; };
exports.truncate = function (fd, len, callback) { exports.truncate = function (fd, len, callback) {
process.fs.truncate(fd, len, callback || noop); fs.truncate(fd, len, callback || noop);
}; };
exports.truncateSync = function (fd, len) { exports.truncateSync = function (fd, len) {
return process.fs.truncate(fd, len); return fs.truncate(fd, len);
}; };
exports.rmdir = function (path, callback) { exports.rmdir = function (path, callback) {
process.fs.rmdir(path, callback || noop); fs.rmdir(path, callback || noop);
}; };
exports.rmdirSync = function (path) { exports.rmdirSync = function (path) {
return process.fs.rmdir(path); return fs.rmdir(path);
}; };
exports.mkdir = function (path, mode, callback) { exports.mkdir = function (path, mode, callback) {
process.fs.mkdir(path, mode, callback || noop); fs.mkdir(path, mode, callback || noop);
}; };
exports.mkdirSync = function (path, mode) { exports.mkdirSync = function (path, mode) {
return process.fs.mkdir(path, mode); return fs.mkdir(path, mode);
}; };
exports.sendfile = function (outFd, inFd, inOffset, length, callback) { exports.sendfile = function (outFd, inFd, inOffset, length, callback) {
process.fs.sendfile(outFd, inFd, inOffset, length, callback || noop); fs.sendfile(outFd, inFd, inOffset, length, callback || noop);
}; };
exports.sendfileSync = function (outFd, inFd, inOffset, length) { exports.sendfileSync = function (outFd, inFd, inOffset, length) {
return process.fs.sendfile(outFd, inFd, inOffset, length); return fs.sendfile(outFd, inFd, inOffset, length);
}; };
exports.readdir = function (path, callback) { exports.readdir = function (path, callback) {
process.fs.readdir(path, callback || noop); fs.readdir(path, callback || noop);
}; };
exports.readdirSync = function (path) { exports.readdirSync = function (path) {
return process.fs.readdir(path); return fs.readdir(path);
}; };
exports.lstat = function (path, callback) { exports.lstat = function (path, callback) {
process.fs.lstat(path, callback || noop); fs.lstat(path, callback || noop);
}; };
exports.stat = function (path, callback) { exports.stat = function (path, callback) {
process.fs.stat(path, callback || noop); fs.stat(path, callback || noop);
}; };
exports.lstatSync = function (path) { exports.lstatSync = function (path) {
return process.fs.lstat(path); return fs.lstat(path);
}; };
exports.statSync = function (path) { exports.statSync = function (path) {
return process.fs.stat(path); return fs.stat(path);
}; };
exports.readlink = function (path, callback) { exports.readlink = function (path, callback) {
process.fs.readlink(path, callback || noop); fs.readlink(path, callback || noop);
}; };
exports.readlinkSync = function (path) { exports.readlinkSync = function (path) {
return process.fs.readlink(path); return fs.readlink(path);
}; };
exports.symlink = function (destination, path, callback) { exports.symlink = function (destination, path, callback) {
process.fs.symlink(destination, path, callback || noop); fs.symlink(destination, path, callback || noop);
}; };
exports.symlinkSync = function (destination, path) { exports.symlinkSync = function (destination, path) {
return process.fs.symlink(destination, path); return fs.symlink(destination, path);
}; };
exports.link = function (srcpath, dstpath, callback) { exports.link = function (srcpath, dstpath, callback) {
process.fs.link(srcpath, dstpath, callback || noop); fs.link(srcpath, dstpath, callback || noop);
}; };
exports.linkSync = function (srcpath, dstpath) { exports.linkSync = function (srcpath, dstpath) {
return process.fs.link(srcpath, dstpath); return fs.link(srcpath, dstpath);
}; };
exports.unlink = function (path, callback) { exports.unlink = function (path, callback) {
process.fs.unlink(path, callback || noop); fs.unlink(path, callback || noop);
}; };
exports.unlinkSync = function (path) { exports.unlinkSync = function (path) {
return process.fs.unlink(path); return fs.unlink(path);
}; };
exports.chmod = function (path, mode, callback) { exports.chmod = function (path, mode, callback) {
process.fs.chmod(path, mode, callback || noop); fs.chmod(path, mode, callback || noop);
}; };
exports.chmodSync = function (path, mode) { exports.chmodSync = function (path, mode) {
return process.fs.chmod(path, mode); return fs.chmod(path, mode);
}; };
function writeAll (fd, data, encoding, callback) { function writeAll (fd, data, encoding, callback) {
@ -322,7 +322,7 @@ exports.watchFile = function (filename) {
if (filename in statWatchers) { if (filename in statWatchers) {
stat = statWatchers[filename]; stat = statWatchers[filename];
} else { } else {
statWatchers[filename] = new process.Stat(); statWatchers[filename] = new fs.StatWatcher();
stat = statWatchers[filename]; stat = statWatchers[filename];
stat.start(filename, options.persistent, options.interval); stat.start(filename, options.persistent, options.interval);
} }
@ -500,7 +500,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
return; return;
} }
fs.read(self.fd, self.bufferSize, undefined, self.encoding, function(err, data, bytesRead) { exports.read(self.fd, self.bufferSize, undefined, self.encoding, function(err, data, bytesRead) {
if (err) { if (err) {
self.emit('error', err); self.emit('error', err);
self.readable = false; self.readable = false;
@ -529,7 +529,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
}); });
} }
fs.open(this.path, this.flags, this.mode, function(err, fd) { exports.open(this.path, this.flags, this.mode, function(err, fd) {
if (err) { if (err) {
self.emit('error', err); self.emit('error', err);
self.readable = false; self.readable = false;
@ -545,7 +545,7 @@ var FileReadStream = exports.FileReadStream = function(path, options) {
this.readable = false; this.readable = false;
function close() { function close() {
fs.close(self.fd, function(err) { exports.close(self.fd, function(err) {
if (err) { if (err) {
if (cb) { if (cb) {
cb(err); cb(err);
@ -608,7 +608,7 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
queue = [], queue = [],
busy = false; busy = false;
queue.push([fs.open, this.path, this.flags, this.mode, undefined]); queue.push([exports.open, this.path, this.flags, this.mode, undefined]);
function flush() { function flush() {
if (busy) { if (busy) {
@ -639,7 +639,7 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
} }
// stop flushing after close // stop flushing after close
if (method === fs.close) { if (method === exports.close) {
if (cb) { if (cb) {
cb(null); cb(null);
} }
@ -648,7 +648,7 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
} }
// save reference for file pointer // save reference for file pointer
if (method === fs.open) { if (method === exports.open) {
self.fd = arguments[1]; self.fd = arguments[1];
self.emit('open', self.fd); self.emit('open', self.fd);
} else if (cb) { } else if (cb) {
@ -660,11 +660,11 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
}); });
// Inject the file pointer // Inject the file pointer
if (method !== fs.open) { if (method !== exports.open) {
args.unshift(self.fd); args.unshift(self.fd);
} }
method.apply(null, args); method.apply(this, args);
}; };
this.write = function(data, cb) { this.write = function(data, cb) {
@ -672,20 +672,20 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
throw new Error('stream not writeable'); throw new Error('stream not writeable');
} }
queue.push([fs.write, data, undefined, this.encoding, cb]); queue.push([exports.write, data, undefined, this.encoding, cb]);
flush(); flush();
return false; return false;
}; };
this.close = function(cb) { this.close = function(cb) {
this.writeable = false; this.writeable = false;
queue.push([fs.close, cb]); queue.push([exports.close, cb]);
flush(); flush();
}; };
this.forceClose = function(cb) { this.forceClose = function(cb) {
this.writeable = false; this.writeable = false;
fs.close(self.fd, function(err) { exports.close(self.fd, function(err) {
if (err) { if (err) {
if (cb) { if (cb) {
cb(err); cb(err);

22
lib/http.js

@ -1,6 +1,12 @@
var sys = require('sys'); var sys = require('sys');
var events = require('events'); var events = require('events');
// FIXME: The TCP binding isn't actually used here, but it needs to be
// loaded before the http binding.
process.binding('tcp');
var http = process.binding('http');
var CRLF = "\r\n"; var CRLF = "\r\n";
var STATUS_CODES = exports.STATUS_CODES = { var STATUS_CODES = exports.STATUS_CODES = {
100 : 'Continue', 100 : 'Continue',
@ -417,7 +423,7 @@ function flushMessageQueue (connection, queue) {
exports.createServer = function (requestListener, options) { exports.createServer = function (requestListener, options) {
var server = new process.http.Server(); var server = new http.Server();
//server.setOptions(options); //server.setOptions(options);
server.addListener("request", requestListener); server.addListener("request", requestListener);
server.addListener("connection", connectionListener); server.addListener("connection", connectionListener);
@ -459,7 +465,7 @@ function connectionListener (connection) {
exports.createClient = function (port, host) { exports.createClient = function (port, host) {
var client = new process.http.Client(); var client = new http.Client();
var secure_credentials={ secure : false }; var secure_credentials={ secure : false };
var requests = []; var requests = [];
@ -541,27 +547,27 @@ exports.createClient = function (port, host) {
return client; return client;
}; };
process.http.Client.prototype.get = function () { http.Client.prototype.get = function () {
throw new Error("client.get(...) is now client.request('GET', ...)"); throw new Error("client.get(...) is now client.request('GET', ...)");
}; };
process.http.Client.prototype.head = function () { http.Client.prototype.head = function () {
throw new Error("client.head(...) is now client.request('HEAD', ...)"); throw new Error("client.head(...) is now client.request('HEAD', ...)");
}; };
process.http.Client.prototype.post = function () { http.Client.prototype.post = function () {
throw new Error("client.post(...) is now client.request('POST', ...)"); throw new Error("client.post(...) is now client.request('POST', ...)");
}; };
process.http.Client.prototype.del = function () { http.Client.prototype.del = function () {
throw new Error("client.del(...) is now client.request('DELETE', ...)"); throw new Error("client.del(...) is now client.request('DELETE', ...)");
}; };
process.http.Client.prototype.put = function () { http.Client.prototype.put = function () {
throw new Error("client.put(...) is now client.request('PUT', ...)"); throw new Error("client.put(...) is now client.request('PUT', ...)");
}; };
process.http.Client.prototype.request = function (method, url, headers) { http.Client.prototype.request = function (method, url, headers) {
if (typeof(url) != "string") { // assume method was omitted, shift arguments if (typeof(url) != "string") { // assume method was omitted, shift arguments
headers = url; headers = url;
url = method; url = method;

6
lib/tcp.js

@ -1,3 +1,5 @@
var tcp = process.binding('tcp');
var TLS_STATUS_CODES = { var TLS_STATUS_CODES = {
1 : 'JS_GNUTLS_CERT_VALIDATED', 1 : 'JS_GNUTLS_CERT_VALIDATED',
0 : 'JS_GNUTLS_CERT_UNDEFINED', 0 : 'JS_GNUTLS_CERT_UNDEFINED',
@ -11,14 +13,14 @@ TLS_STATUS_CODES[-105] = 'JS_GNUTLS_CERT_REVOKED';
TLS_STATUS_CODES[-106] = 'JS_GNUTLS_CERT_DOES_NOT_MATCH_HOSTNAME'; TLS_STATUS_CODES[-106] = 'JS_GNUTLS_CERT_DOES_NOT_MATCH_HOSTNAME';
exports.createServer = function (on_connection, options) { exports.createServer = function (on_connection, options) {
var server = new process.tcp.Server(); var server = new tcp.Server();
server.addListener("connection", on_connection); server.addListener("connection", on_connection);
//server.setOptions(options); //server.setOptions(options);
return server; return server;
}; };
exports.createConnection = function (port, host) { exports.createConnection = function (port, host) {
var connection = new process.tcp.Connection(); var connection = new tcp.Connection();
connection.connect(port, host); connection.connect(port, host);
return connection; return connection;
}; };

107
src/node.cc

@ -1046,6 +1046,85 @@ static Handle<Value> CheckBreak(const Arguments& args) {
return Undefined(); return Undefined();
} }
Persistent<Object> binding_cache;
static Handle<Value> Binding(const Arguments& args) {
HandleScope scope;
Local<String> module = args[0]->ToString();
String::Utf8Value module_v(module);
if (binding_cache.IsEmpty()) {
binding_cache = Persistent<Object>::New(Object::New());
}
Local<Object> exports;
if (!strcmp(*module_v, "http")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
// Warning: When calling requireBinding('http') from javascript then
// be sure that you call requireBinding('tcp') before it.
assert(binding_cache->Has(String::New("tcp")));
exports = Object::New();
HTTPServer::Initialize(exports);
HTTPConnection::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "tcp")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
Server::Initialize(exports);
Connection::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "dns")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
DNS::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "fs")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
// Initialize the stats object
Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
exports->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction());
Stat::Initialize(exports);
File::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "signal_handler")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
SignalHandler::Initialize(exports);
binding_cache->Set(module, exports);
}
} else {
assert(0);
return ThrowException(Exception::Error(String::New("No such module")));
}
return scope.Close(exports);
}
static void Load(int argc, char *argv[]) { static void Load(int argc, char *argv[]) {
HandleScope scope; HandleScope scope;
@ -1122,44 +1201,20 @@ static void Load(int argc, char *argv[]) {
NODE_SET_METHOD(process, "memoryUsage", MemoryUsage); NODE_SET_METHOD(process, "memoryUsage", MemoryUsage);
NODE_SET_METHOD(process, "checkBreak", CheckBreak); NODE_SET_METHOD(process, "checkBreak", CheckBreak);
NODE_SET_METHOD(process, "binding", Binding);
// Assign the EventEmitter. It was created in main(). // Assign the EventEmitter. It was created in main().
process->Set(String::NewSymbol("EventEmitter"), process->Set(String::NewSymbol("EventEmitter"),
EventEmitter::constructor_template->GetFunction()); EventEmitter::constructor_template->GetFunction());
// Initialize the stats object
Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
process->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction());
// Initialize the C++ modules..................filename of module // Initialize the C++ modules..................filename of module
IdleWatcher::Initialize(process); // idle_watcher.cc IdleWatcher::Initialize(process); // idle_watcher.cc
Stdio::Initialize(process); // stdio.cc Stdio::Initialize(process); // stdio.cc
Timer::Initialize(process); // timer.cc Timer::Initialize(process); // timer.cc
SignalHandler::Initialize(process); // signal_handler.cc
Stat::Initialize(process); // stat.cc
ChildProcess::Initialize(process); // child_process.cc ChildProcess::Initialize(process); // child_process.cc
DefineConstants(process); // constants.cc DefineConstants(process); // constants.cc
// Create node.dns
Local<Object> dns = Object::New();
process->Set(String::NewSymbol("dns"), dns);
DNS::Initialize(dns); // dns.cc
Local<Object> fs = Object::New();
process->Set(String::NewSymbol("fs"), fs);
File::Initialize(fs); // file.cc
// Create node.tcp. Note this separate from lib/tcp.js which is the public
// frontend.
Local<Object> tcp = Object::New();
process->Set(String::New("tcp"), tcp);
Server::Initialize(tcp); // tcp.cc
Connection::Initialize(tcp); // tcp.cc
// Create node.http. Note this separate from lib/http.js which is the
// public frontend.
Local<Object> http = Object::New();
process->Set(String::New("http"), http);
HTTPServer::Initialize(http); // http.cc
HTTPConnection::Initialize(http); // http.cc
Local<Object> natives = Object::New(); Local<Object> natives = Object::New();

5
src/node.js

@ -281,7 +281,8 @@ function isSignal (event) {
process.addListener("newListener", function (event) { process.addListener("newListener", function (event) {
if (isSignal(event) && process.listeners(event).length === 0) { if (isSignal(event) && process.listeners(event).length === 0) {
var handler = new process.SignalHandler(process[event]); var b = process.binding('signal_handler');
var handler = new b.SignalHandler(process[event]);
handler.addListener("signal", function () { handler.addListener("signal", function () {
process.emit(event); process.emit(event);
}); });
@ -407,7 +408,7 @@ var path = pathModule.exports;
function existsSync (path) { function existsSync (path) {
try { try {
process.fs.stat(path); process.binding('fs').stat(path);
return true; return true;
} catch (e) { } catch (e) {
return false; return false;

4
src/node_stat.cc

@ -21,7 +21,7 @@ void Stat::Initialize(Handle<Object> target) {
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->Inherit(EventEmitter::constructor_template); constructor_template->Inherit(EventEmitter::constructor_template);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Stat")); constructor_template->SetClassName(String::NewSymbol("StatWatcher"));
change_symbol = NODE_PSYMBOL("change"); change_symbol = NODE_PSYMBOL("change");
stop_symbol = NODE_PSYMBOL("stop"); stop_symbol = NODE_PSYMBOL("stop");
@ -29,7 +29,7 @@ void Stat::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Stat::Start); NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Stat::Start);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Stat::Stop); NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Stat::Stop);
target->Set(String::NewSymbol("Stat"), constructor_template->GetFunction()); target->Set(String::NewSymbol("StatWatcher"), constructor_template->GetFunction());
} }

Loading…
Cancel
Save