Merge branch 'master' into net2
This commit is contained in:
commit
d9e3b466a7
56
doc/api.txt
56
doc/api.txt
@ -153,30 +153,6 @@ Send a signal to a process. +pid+ is the process id and +signal+ is the
|
|||||||
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
|
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
+process.watchFile(filename, [options,] listener)+::
|
|
||||||
Watch for changes on +filename+. The callback +listener+ will be called each
|
|
||||||
time the file changes.
|
|
||||||
+
|
|
||||||
The second argument is optional. The +options+ if provided should be an
|
|
||||||
object containing two members a boolean, +persistent+, and +interval+, a
|
|
||||||
polling value in milliseconds. The default is +{persistent: true, interval:
|
|
||||||
0}+.
|
|
||||||
+
|
|
||||||
The +listener+ gets two arguments the current stat object and the previous
|
|
||||||
stat object:
|
|
||||||
+
|
|
||||||
-------------------------
|
|
||||||
process.watchFile(f, function (curr, prev) {
|
|
||||||
sys.puts("the current mtime is: " + curr.mtime);
|
|
||||||
sys.puts("the previous mtime was: " + prev.mtime);
|
|
||||||
});
|
|
||||||
-------------------------
|
|
||||||
+
|
|
||||||
These stat objects are instances of +fs.Stat+.
|
|
||||||
|
|
||||||
+process.unwatchFile(filename)+::
|
|
||||||
Stop watching for changes on +filename+.
|
|
||||||
|
|
||||||
+process.compile(source, scriptOrigin)+::
|
+process.compile(source, scriptOrigin)+::
|
||||||
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
|
Just like +eval()+ except that you can specify a +scriptOrigin+ for better
|
||||||
error reporting.
|
error reporting.
|
||||||
@ -646,6 +622,14 @@ The callback gets two arguments +(err, resolvedPath)+.
|
|||||||
Synchronous readlink(2). Returns the resolved path.
|
Synchronous readlink(2). Returns the resolved path.
|
||||||
|
|
||||||
|
|
||||||
|
+fs.realpath(path, callback)+ ::
|
||||||
|
Asynchronous realpath(2).
|
||||||
|
The callback gets two arguments +(err, resolvedPath)+.
|
||||||
|
|
||||||
|
+fs.realpathSync(path)+ ::
|
||||||
|
Synchronous realpath(2). Returns the resolved path.
|
||||||
|
|
||||||
|
|
||||||
+fs.unlink(path, callback)+ ::
|
+fs.unlink(path, callback)+ ::
|
||||||
Asynchronous unlink(2).
|
Asynchronous unlink(2).
|
||||||
No arguments other than a possible exception are given to the completion callback.
|
No arguments other than a possible exception are given to the completion callback.
|
||||||
@ -755,6 +739,30 @@ fs.writeFile("message.txt", "Hello Node", function (err) {
|
|||||||
+fs.writeFileSync(filename, data, encoding="utf8")+::
|
+fs.writeFileSync(filename, data, encoding="utf8")+::
|
||||||
The synchronous version of +fs.writeFile+.
|
The synchronous version of +fs.writeFile+.
|
||||||
|
|
||||||
|
+fs.watchFile(filename, [options,] listener)+::
|
||||||
|
Watch for changes on +filename+. The callback +listener+ will be called each
|
||||||
|
time the file changes.
|
||||||
|
+
|
||||||
|
The second argument is optional. The +options+ if provided should be an
|
||||||
|
object containing two members a boolean, +persistent+, and +interval+, a
|
||||||
|
polling value in milliseconds. The default is +{persistent: true, interval:
|
||||||
|
0}+.
|
||||||
|
+
|
||||||
|
The +listener+ gets two arguments the current stat object and the previous
|
||||||
|
stat object:
|
||||||
|
+
|
||||||
|
-------------------------
|
||||||
|
fs.watchFile(f, function (curr, prev) {
|
||||||
|
sys.puts("the current mtime is: " + curr.mtime);
|
||||||
|
sys.puts("the previous mtime was: " + prev.mtime);
|
||||||
|
});
|
||||||
|
-------------------------
|
||||||
|
+
|
||||||
|
These stat objects are instances of +fs.Stat+.
|
||||||
|
|
||||||
|
+fs.unwatchFile(filename)+::
|
||||||
|
Stop watching for changes on +filename+.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== +fs.Stats+
|
=== +fs.Stats+
|
||||||
|
@ -239,7 +239,9 @@ make install</pre>
|
|||||||
<pre class="sh_none">
|
<pre class="sh_none">
|
||||||
git clone git://github.com/ry/node.git
|
git clone git://github.com/ry/node.git
|
||||||
cd node
|
cd node
|
||||||
# edit/compile/test
|
(make your changes)
|
||||||
|
./configure --debug
|
||||||
|
make test-all # Check your patch with both debug and release builds
|
||||||
git commit -m "Good description of what your patch does"
|
git commit -m "Good description of what your patch does"
|
||||||
git format-patch HEAD^
|
git format-patch HEAD^
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// UTILITY
|
// UTILITY
|
||||||
|
var inherits = require('./sys').inherits;
|
||||||
var pSlice = Array.prototype.slice;
|
var pSlice = Array.prototype.slice;
|
||||||
|
|
||||||
// 1. The assert module provides functions that throw
|
// 1. The assert module provides functions that throw
|
||||||
@ -47,7 +47,7 @@ assert.AssertionError = function AssertionError (options) {
|
|||||||
Error.captureStackTrace(this, stackStartFunction);
|
Error.captureStackTrace(this, stackStartFunction);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
process.inherits(assert.AssertionError, Error);
|
inherits(assert.AssertionError, Error);
|
||||||
|
|
||||||
assert.AssertionError.prototype.toString = function() {
|
assert.AssertionError.prototype.toString = function() {
|
||||||
if (this.message) {
|
if (this.message) {
|
||||||
|
377
lib/fs.js
Normal file
377
lib/fs.js
Normal file
@ -0,0 +1,377 @@
|
|||||||
|
exports.Stats = process.Stats;
|
||||||
|
|
||||||
|
process.Stats.prototype._checkModeProperty = function (property) {
|
||||||
|
return ((this.mode & property) === property);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isDirectory = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFDIR);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isFile = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFREG);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isBlockDevice = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFBLK);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isCharacterDevice = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFCHR);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isSymbolicLink = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFLNK);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isFIFO = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFIFO);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Stats.prototype.isSocket = function () {
|
||||||
|
return this._checkModeProperty(process.S_IFSOCK);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exports.readFile = process.fs.readFile;
|
||||||
|
exports.readFileSync = process.fs.readFileSync;
|
||||||
|
|
||||||
|
// Used by fs.open and friends
|
||||||
|
function stringToFlags(flag) {
|
||||||
|
// Only mess with strings
|
||||||
|
if (typeof flag !== 'string') {
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
switch (flag) {
|
||||||
|
case "r": return process.O_RDONLY;
|
||||||
|
case "r+": return process.O_RDWR;
|
||||||
|
case "w": return process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
|
||||||
|
case "w+": return process.O_CREAT | process.O_TRUNC | process.O_RDWR;
|
||||||
|
case "a": return process.O_APPEND | process.O_CREAT | process.O_WRONLY;
|
||||||
|
case "a+": return process.O_APPEND | process.O_CREAT | process.O_RDWR;
|
||||||
|
default: throw new Error("Unknown file open flag: " + flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function noop () {}
|
||||||
|
|
||||||
|
// Yes, the follow could be easily DRYed up but I provide the explicit
|
||||||
|
// list to make the arguments clear.
|
||||||
|
|
||||||
|
exports.close = function (fd, callback) {
|
||||||
|
process.fs.close(fd, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.closeSync = function (fd) {
|
||||||
|
return process.fs.close(fd);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.open = function (path, flags, mode, callback) {
|
||||||
|
if (mode === undefined) { mode = 0666; }
|
||||||
|
process.fs.open(path, stringToFlags(flags), mode, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.openSync = function (path, flags, mode) {
|
||||||
|
if (mode === undefined) { mode = 0666; }
|
||||||
|
return process.fs.open(path, stringToFlags(flags), mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.read = function (fd, length, position, encoding, callback) {
|
||||||
|
encoding = encoding || "binary";
|
||||||
|
process.fs.read(fd, length, position, encoding, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.readSync = function (fd, length, position, encoding) {
|
||||||
|
encoding = encoding || "binary";
|
||||||
|
return process.fs.read(fd, length, position, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.write = function (fd, data, position, encoding, callback) {
|
||||||
|
encoding = encoding || "binary";
|
||||||
|
process.fs.write(fd, data, position, encoding, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.writeSync = function (fd, data, position, encoding) {
|
||||||
|
encoding = encoding || "binary";
|
||||||
|
return process.fs.write(fd, data, position, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.rename = function (oldPath, newPath, callback) {
|
||||||
|
process.fs.rename(oldPath, newPath, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.renameSync = function (oldPath, newPath) {
|
||||||
|
return process.fs.rename(oldPath, newPath);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.truncate = function (fd, len, callback) {
|
||||||
|
process.fs.truncate(fd, len, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.truncateSync = function (fd, len) {
|
||||||
|
return process.fs.truncate(fd, len);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.rmdir = function (path, callback) {
|
||||||
|
process.fs.rmdir(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.rmdirSync = function (path) {
|
||||||
|
return process.fs.rmdir(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.mkdir = function (path, mode, callback) {
|
||||||
|
process.fs.mkdir(path, mode, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.mkdirSync = function (path, mode) {
|
||||||
|
return process.fs.mkdir(path, mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.sendfile = function (outFd, inFd, inOffset, length, callback) {
|
||||||
|
process.fs.sendfile(outFd, inFd, inOffset, length, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.sendfileSync = function (outFd, inFd, inOffset, length) {
|
||||||
|
return process.fs.sendfile(outFd, inFd, inOffset, length);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.readdir = function (path, callback) {
|
||||||
|
process.fs.readdir(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.readdirSync = function (path) {
|
||||||
|
return process.fs.readdir(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.lstat = function (path, callback) {
|
||||||
|
process.fs.lstat(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.stat = function (path, callback) {
|
||||||
|
process.fs.stat(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.lstatSync = function (path) {
|
||||||
|
return process.fs.lstat(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.statSync = function (path) {
|
||||||
|
return process.fs.stat(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.readlink = function (path, callback) {
|
||||||
|
process.fs.readlink(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.readlinkSync = function (path) {
|
||||||
|
return process.fs.readlink(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.symlink = function (destination, path, callback) {
|
||||||
|
process.fs.symlink(destination, path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.symlinkSync = function (destination, path) {
|
||||||
|
return process.fs.symlink(destination, path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.link = function (srcpath, dstpath, callback) {
|
||||||
|
process.fs.link(srcpath, dstpath, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.linkSync = function (srcpath, dstpath) {
|
||||||
|
return process.fs.link(srcpath, dstpath);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.unlink = function (path, callback) {
|
||||||
|
process.fs.unlink(path, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.unlinkSync = function (path) {
|
||||||
|
return process.fs.unlink(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.chmod = function (path, mode, callback) {
|
||||||
|
process.fs.chmod(path, mode, callback || noop);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.chmodSync = function (path, mode) {
|
||||||
|
return process.fs.chmod(path, mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
function writeAll (fd, data, encoding, callback) {
|
||||||
|
exports.write(fd, data, 0, encoding, function (writeErr, written) {
|
||||||
|
if (writeErr) {
|
||||||
|
exports.close(fd, function () {
|
||||||
|
if (callback) callback(writeErr);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (written === data.length) {
|
||||||
|
exports.close(fd, callback);
|
||||||
|
} else {
|
||||||
|
writeAll(fd, data.slice(written), encoding, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.writeFile = function (path, data, encoding_, callback) {
|
||||||
|
var encoding = (typeof(encoding_) == 'string' ? encoding_ : 'utf8');
|
||||||
|
var callback_ = arguments[arguments.length - 1];
|
||||||
|
var callback = (typeof(callback_) == 'function' ? callback_ : null);
|
||||||
|
exports.open(path, 'w', 0666, function (openErr, fd) {
|
||||||
|
if (openErr) {
|
||||||
|
if (callback) callback(openErr);
|
||||||
|
} else {
|
||||||
|
writeAll(fd, data, encoding, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.writeFileSync = function (path, data, encoding) {
|
||||||
|
encoding = encoding || "utf8"; // default to utf8
|
||||||
|
var fd = exports.openSync(path, "w");
|
||||||
|
var written = 0;
|
||||||
|
while (written < data.length) {
|
||||||
|
written += exports.writeSync(fd, data, 0, encoding);
|
||||||
|
data = data.slice(written);
|
||||||
|
}
|
||||||
|
exports.closeSync(fd);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.cat = function () {
|
||||||
|
throw new Error("fs.cat is deprecated. Please use fs.readFile instead.");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.catSync = function () {
|
||||||
|
throw new Error("fs.catSync is deprecated. Please use fs.readFileSync instead.");
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stat Change Watchers
|
||||||
|
|
||||||
|
var statWatchers = {};
|
||||||
|
|
||||||
|
exports.watchFile = function (filename) {
|
||||||
|
var stat;
|
||||||
|
var options;
|
||||||
|
var listener;
|
||||||
|
|
||||||
|
if ("object" == typeof arguments[1]) {
|
||||||
|
options = arguments[1];
|
||||||
|
listener = arguments[2];
|
||||||
|
} else {
|
||||||
|
options = {};
|
||||||
|
listener = arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.persistent === undefined) options.persistent = true;
|
||||||
|
if (options.interval === undefined) options.interval = 0;
|
||||||
|
|
||||||
|
if (filename in statWatchers) {
|
||||||
|
stat = statWatchers[filename];
|
||||||
|
} else {
|
||||||
|
statWatchers[filename] = new process.Stat();
|
||||||
|
stat = statWatchers[filename];
|
||||||
|
stat.start(filename, options.persistent, options.interval);
|
||||||
|
}
|
||||||
|
stat.addListener("change", listener);
|
||||||
|
return stat;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.unwatchFile = function (filename) {
|
||||||
|
if (filename in statWatchers) {
|
||||||
|
stat = statWatchers[filename];
|
||||||
|
stat.stop();
|
||||||
|
statWatchers[filename] = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Realpath
|
||||||
|
|
||||||
|
var path = require('path');
|
||||||
|
var dirname = path.dirname,
|
||||||
|
basename = path.basename,
|
||||||
|
normalize = path.normalize;
|
||||||
|
|
||||||
|
function readlinkDeepSync(path, stats) {
|
||||||
|
var seen_links = {}, resolved_link, stats, file_id;
|
||||||
|
while (true) {
|
||||||
|
stats = stats || exports.lstatSync(path);
|
||||||
|
file_id = stats.dev.toString(32)+":"+stats.ino.toString(32);
|
||||||
|
if (file_id in seen_links) {
|
||||||
|
throw new Error("cyclic symbolic link at "+path);
|
||||||
|
} else {
|
||||||
|
seen_links[file_id] = 1;
|
||||||
|
if (stats.isSymbolicLink()) {
|
||||||
|
var newpath = exports.readlinkSync(path);
|
||||||
|
if (newpath.charAt(0) === '/') {
|
||||||
|
path = newpath;
|
||||||
|
} else {
|
||||||
|
var dir = dirname(path);
|
||||||
|
path = (dir !== '') ? dir + '/' + newpath : newpath;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return normalize(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stats = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readlinkDeep(path, stats, callback) {
|
||||||
|
var seen_links = {}, resolved_link, file_id;
|
||||||
|
function next(stats) {
|
||||||
|
file_id = stats.dev.toString(32)+":"+stats.ino.toString(32);
|
||||||
|
if (file_id in seen_links) {
|
||||||
|
callback(new Error("cyclic symbolic link at "+path));
|
||||||
|
} else {
|
||||||
|
seen_links[file_id] = 1;
|
||||||
|
if (stats.isSymbolicLink()) {
|
||||||
|
exports.readlink(path, function(err, newpath) {
|
||||||
|
if (err) callback(err);
|
||||||
|
if (newpath.charAt(0) === '/') {
|
||||||
|
path = newpath;
|
||||||
|
} else {
|
||||||
|
var dir = dirname(path);
|
||||||
|
path = (dir !== '') ? dir + '/' + newpath : newpath;
|
||||||
|
}
|
||||||
|
_next();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null, normalize(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _next() {
|
||||||
|
exports.lstat(path, function(err, stats){
|
||||||
|
if (err) callback(err);
|
||||||
|
else next(stats);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (stats) next(stats);
|
||||||
|
else _next();
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.realpathSync = function(path) {
|
||||||
|
var stats = exports.lstatSync(path);
|
||||||
|
if (stats.isSymbolicLink())
|
||||||
|
return readlinkDeepSync(path, stats);
|
||||||
|
else
|
||||||
|
return normalize(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.realpath = function(path, callback) {
|
||||||
|
var resolved_path = path;
|
||||||
|
if (!callback) return;
|
||||||
|
exports.lstat(path, function(err, stats){
|
||||||
|
if (err)
|
||||||
|
callback(err);
|
||||||
|
else if (stats.isSymbolicLink())
|
||||||
|
readlinkDeep(path, stats, callback);
|
||||||
|
else
|
||||||
|
callback(null, normalize(path));
|
||||||
|
});
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
var sys = require('sys');
|
var sys = require('./sys');
|
||||||
var events = require('events');
|
var events = require('events');
|
||||||
|
|
||||||
var CRLF = "\r\n";
|
var CRLF = "\r\n";
|
||||||
|
36
lib/sys.js
36
lib/sys.js
@ -95,11 +95,11 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
return braces[0] + base + braces[1];
|
return braces[0] + base + braces[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if( recurseTimes < 0 ) {
|
if (recurseTimes < 0) {
|
||||||
if (value instanceof RegExp) {
|
if (value instanceof RegExp) {
|
||||||
return '' + value;
|
return '' + value;
|
||||||
} else {
|
} else {
|
||||||
return "[object Object]";
|
return "[Object]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,10 +129,17 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
else {
|
else {
|
||||||
str = format(value[key], recurseTimes - 1);
|
str = format(value[key], recurseTimes - 1);
|
||||||
}
|
}
|
||||||
if( str.indexOf('\n') > -1 ) {
|
if (str.indexOf('\n') > -1) {
|
||||||
str = '\n' + str.split('\n').map(function(line) {
|
if (value instanceof Array) {
|
||||||
|
str = str.split('\n').map(function(line) {
|
||||||
|
return ' ' + line;
|
||||||
|
}).join('\n').substr(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str = '\n' + str.split('\n').map(function(line) {
|
||||||
return ' ' + line;
|
return ' ' + line;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str = '[Circular]';
|
str = '[Circular]';
|
||||||
@ -143,7 +150,7 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
name = JSON.stringify('' + key);
|
name = JSON.stringify('' + key);
|
||||||
if( name.match(/^"([a-zA-Z_0-9]+)"$/) ) {
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
||||||
name = name.substr(1, name.length-2);
|
name = name.substr(1, name.length-2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -154,13 +161,17 @@ exports.inspect = function (obj, showHidden, depth) {
|
|||||||
return name + ": " + str;
|
return name + ": " + str;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var numLinesEst = 0;
|
||||||
var length = output.reduce(function(prev, cur) {
|
var length = output.reduce(function(prev, cur) {
|
||||||
|
numLinesEst++;
|
||||||
|
if( cur.indexOf('\n') >= 0 ) {
|
||||||
|
numLinesEst++;
|
||||||
|
}
|
||||||
return prev + cur.length + 1;
|
return prev + cur.length + 1;
|
||||||
},0);
|
},0);
|
||||||
|
|
||||||
if( length > 50 ) {
|
if (length > 50) {
|
||||||
output = braces[0] + (base === '' ? '' : base + '\n,') + ' ' + output.join('\n, ') + '\n' +braces[1];
|
output = braces[0] + (base === '' ? '' : base + '\n,') + ' ' + output.join('\n, ') + (numLinesEst > 1 ? '\n' : ' ') + braces[1];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||||
@ -214,5 +225,12 @@ exports.exec = function (command, callback) {
|
|||||||
* prototype
|
* prototype
|
||||||
* @param {function} superCtor Constructor function to inherit prototype from
|
* @param {function} superCtor Constructor function to inherit prototype from
|
||||||
*/
|
*/
|
||||||
exports.inherits = process.inherits;
|
exports.inherits = function (ctor, superCtor) {
|
||||||
|
var tempCtor = function(){};
|
||||||
|
tempCtor.prototype = superCtor.prototype;
|
||||||
|
ctor.super_ = superCtor;
|
||||||
|
ctor.prototype = new tempCtor();
|
||||||
|
ctor.prototype.constructor = ctor;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1250,7 +1250,13 @@ int main(int argc, char *argv[]) {
|
|||||||
evcom_ignore_sigpipe();
|
evcom_ignore_sigpipe();
|
||||||
|
|
||||||
// Initialize the default ev loop.
|
// Initialize the default ev loop.
|
||||||
|
#ifdef __sun
|
||||||
|
// TODO(Ryan) I'm experiencing abnormally high load using Solaris's
|
||||||
|
// EVBACKEND_PORT. Temporarally forcing select() until I debug.
|
||||||
|
ev_default_loop(EVBACKEND_SELECT);
|
||||||
|
#else
|
||||||
ev_default_loop(EVFLAG_AUTO);
|
ev_default_loop(EVFLAG_AUTO);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
ev_timer_init(&node::gc_timer, node::GCTimeout, GC_INTERVAL, GC_INTERVAL);
|
ev_timer_init(&node::gc_timer, node::GCTimeout, GC_INTERVAL, GC_INTERVAL);
|
||||||
|
407
src/node.js
407
src/node.js
@ -19,12 +19,15 @@ GLOBAL.print = removed("print() has moved. Use require('sys') to bring it back."
|
|||||||
GLOBAL.p = removed("p() has moved. Use require('sys') to bring it back.");
|
GLOBAL.p = removed("p() has moved. Use require('sys') to bring it back.");
|
||||||
process.debug = removed("process.debug() has moved. Use require('sys') to bring it back.");
|
process.debug = removed("process.debug() has moved. Use require('sys') to bring it back.");
|
||||||
process.error = removed("process.error() has moved. Use require('sys') to bring it back.");
|
process.error = removed("process.error() has moved. Use require('sys') to bring it back.");
|
||||||
|
process.watchFile = removed("process.watchFile() has moved to fs.watchFile()");
|
||||||
|
process.unwatchFile = removed("process.unwatchFile() has moved to fs.unwatchFile()");
|
||||||
|
|
||||||
GLOBAL.node = {};
|
GLOBAL.node = {};
|
||||||
|
|
||||||
node.createProcess = removed("node.createProcess() has been changed to process.createChildProcess() update your code");
|
node.createProcess = removed("node.createProcess() has been changed to process.createChildProcess() update your code");
|
||||||
node.exec = removed("process.exec() has moved. Use require('sys') to bring it back.");
|
node.exec = removed("process.exec() has moved. Use require('sys') to bring it back.");
|
||||||
node.inherits = removed("node.inherits() has moved. Use require('sys') to access it.");
|
node.inherits = removed("node.inherits() has moved. Use require('sys') to access it.");
|
||||||
|
process.inherits = removed("process.inherits() has moved to sys.inherits.");
|
||||||
|
|
||||||
node.http = {};
|
node.http = {};
|
||||||
node.http.createServer = removed("node.http.createServer() has moved. Use require('http') to access it.");
|
node.http.createServer = removed("node.http.createServer() has moved. Use require('http') to access it.");
|
||||||
@ -70,15 +73,6 @@ function createInternalModule (id, constructor) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
process.inherits = function (ctor, superCtor) {
|
|
||||||
var tempCtor = function(){};
|
|
||||||
tempCtor.prototype = superCtor.prototype;
|
|
||||||
ctor.super_ = superCtor;
|
|
||||||
ctor.prototype = new tempCtor();
|
|
||||||
ctor.prototype.constructor = ctor;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
process.createChildProcess = function (file, args, env) {
|
process.createChildProcess = function (file, args, env) {
|
||||||
var child = new process.ChildProcess();
|
var child = new process.ChildProcess();
|
||||||
args = args || [];
|
args = args || [];
|
||||||
@ -132,7 +126,7 @@ process.mixin = function() {
|
|||||||
if ( (source = arguments[i]) != null ) {
|
if ( (source = arguments[i]) != null ) {
|
||||||
// Extend the base object
|
// Extend the base object
|
||||||
Object.getOwnPropertyNames(source).forEach(function(k){
|
Object.getOwnPropertyNames(source).forEach(function(k){
|
||||||
var d = Object.getOwnPropertyDescriptor(source, k);
|
var d = Object.getOwnPropertyDescriptor(source, k) || {value: source[k]};
|
||||||
if (d.get) {
|
if (d.get) {
|
||||||
target.__defineGetter__(k, d.get);
|
target.__defineGetter__(k, d.get);
|
||||||
if (d.set) {
|
if (d.set) {
|
||||||
@ -246,79 +240,6 @@ process.addListener("newListener", function (event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Stat Change Watchers
|
|
||||||
|
|
||||||
var statWatchers = {};
|
|
||||||
|
|
||||||
process.watchFile = function (filename) {
|
|
||||||
var stat;
|
|
||||||
var options;
|
|
||||||
var listener;
|
|
||||||
|
|
||||||
if ("object" == typeof arguments[1]) {
|
|
||||||
options = arguments[1];
|
|
||||||
listener = arguments[2];
|
|
||||||
} else {
|
|
||||||
options = {};
|
|
||||||
listener = arguments[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.persistent === undefined) options.persistent = true;
|
|
||||||
if (options.interval === undefined) options.interval = 0;
|
|
||||||
|
|
||||||
if (filename in statWatchers) {
|
|
||||||
stat = statWatchers[filename];
|
|
||||||
} else {
|
|
||||||
statWatchers[filename] = new process.Stat();
|
|
||||||
stat = statWatchers[filename];
|
|
||||||
stat.start(filename, options.persistent, options.interval);
|
|
||||||
}
|
|
||||||
stat.addListener("change", listener);
|
|
||||||
return stat;
|
|
||||||
};
|
|
||||||
|
|
||||||
process.unwatchFile = function (filename) {
|
|
||||||
if (filename in statWatchers) {
|
|
||||||
stat = statWatchers[filename];
|
|
||||||
stat.stop();
|
|
||||||
statWatchers[filename] = undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype._checkModeProperty = function (property) {
|
|
||||||
return ((this.mode & property) === property);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isDirectory = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFDIR);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isFile = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFREG);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isBlockDevice = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFBLK);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isCharacterDevice = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFCHR);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isSymbolicLink = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFLNK);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isFIFO = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFIFO);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Stats.prototype.isSocket = function () {
|
|
||||||
return this._checkModeProperty(process.S_IFSOCK);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
function addTimerListener (callback) {
|
function addTimerListener (callback) {
|
||||||
var timer = this;
|
var timer = this;
|
||||||
@ -371,278 +292,60 @@ function debug (x) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var fsModule = createInternalModule("fs", function (exports) {
|
|
||||||
exports.Stats = process.Stats;
|
function readAll (fd, pos, content, encoding, callback) {
|
||||||
|
process.fs.read(fd, 4*1024, pos, encoding, function (err, chunk, bytesRead) {
|
||||||
// Used by fs.open and friends
|
if (err) {
|
||||||
function stringToFlags(flag) {
|
if (callback) callback(err);
|
||||||
// Only mess with strings
|
} else if (chunk) {
|
||||||
if (typeof flag !== 'string') {
|
content += chunk;
|
||||||
return flag;
|
pos += bytesRead;
|
||||||
|
readAll(fd, pos, content, encoding, callback);
|
||||||
|
} else {
|
||||||
|
process.fs.close(fd, function (err) {
|
||||||
|
if (callback) callback(err, content);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
switch (flag) {
|
});
|
||||||
case "r": return process.O_RDONLY;
|
}
|
||||||
case "r+": return process.O_RDWR;
|
|
||||||
case "w": return process.O_CREAT | process.O_TRUNC | process.O_WRONLY;
|
process.fs.readFile = function (path, encoding_, callback) {
|
||||||
case "w+": return process.O_CREAT | process.O_TRUNC | process.O_RDWR;
|
var encoding = typeof(encoding_) == 'string' ? encoding : 'utf8';
|
||||||
case "a": return process.O_APPEND | process.O_CREAT | process.O_WRONLY;
|
var callback_ = arguments[arguments.length - 1];
|
||||||
case "a+": return process.O_APPEND | process.O_CREAT | process.O_RDWR;
|
var callback = (typeof(callback_) == 'function' ? callback_ : null);
|
||||||
default: throw new Error("Unknown file open flag: " + flag);
|
process.fs.open(path, process.O_RDONLY, 0666, function (err, fd) {
|
||||||
|
if (err) {
|
||||||
|
if (callback) callback(err);
|
||||||
|
} else {
|
||||||
|
readAll(fd, 0, "", encoding, callback);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
process.fs.readFileSync = function (path, encoding) {
|
||||||
|
encoding = encoding || "utf8"; // default to utf8
|
||||||
|
|
||||||
|
debug('readFileSync open');
|
||||||
|
|
||||||
|
var fd = process.fs.open(path, process.O_RDONLY, 0666);
|
||||||
|
var content = '';
|
||||||
|
var pos = 0;
|
||||||
|
var r;
|
||||||
|
|
||||||
|
while ((r = process.fs.read(fd, 4*1024, pos, encoding)) && r[0]) {
|
||||||
|
debug('readFileSync read ' + r[1]);
|
||||||
|
content += r[0];
|
||||||
|
pos += r[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop () {}
|
debug('readFileSync close');
|
||||||
|
|
||||||
// Yes, the follow could be easily DRYed up but I provide the explicit
|
process.fs.close(fd);
|
||||||
// list to make the arguments clear.
|
|
||||||
|
|
||||||
exports.close = function (fd, callback) {
|
debug('readFileSync done');
|
||||||
process.fs.close(fd, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.closeSync = function (fd) {
|
|
||||||
return process.fs.close(fd);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.open = function (path, flags, mode, callback) {
|
|
||||||
if (mode === undefined) { mode = 0666; }
|
|
||||||
process.fs.open(path, stringToFlags(flags), mode, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.openSync = function (path, flags, mode) {
|
|
||||||
if (mode === undefined) { mode = 0666; }
|
|
||||||
return process.fs.open(path, stringToFlags(flags), mode);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.read = function (fd, length, position, encoding, callback) {
|
|
||||||
encoding = encoding || "binary";
|
|
||||||
process.fs.read(fd, length, position, encoding, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readSync = function (fd, length, position, encoding) {
|
|
||||||
encoding = encoding || "binary";
|
|
||||||
return process.fs.read(fd, length, position, encoding);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.write = function (fd, data, position, encoding, callback) {
|
|
||||||
encoding = encoding || "binary";
|
|
||||||
process.fs.write(fd, data, position, encoding, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.writeSync = function (fd, data, position, encoding) {
|
|
||||||
encoding = encoding || "binary";
|
|
||||||
return process.fs.write(fd, data, position, encoding);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.rename = function (oldPath, newPath, callback) {
|
|
||||||
process.fs.rename(oldPath, newPath, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.renameSync = function (oldPath, newPath) {
|
|
||||||
return process.fs.rename(oldPath, newPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.truncate = function (fd, len, callback) {
|
|
||||||
process.fs.truncate(fd, len, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.truncateSync = function (fd, len) {
|
|
||||||
return process.fs.truncate(fd, len);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.rmdir = function (path, callback) {
|
|
||||||
process.fs.rmdir(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.rmdirSync = function (path) {
|
|
||||||
return process.fs.rmdir(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.mkdir = function (path, mode, callback) {
|
|
||||||
process.fs.mkdir(path, mode, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.mkdirSync = function (path, mode) {
|
|
||||||
return process.fs.mkdir(path, mode);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.sendfile = function (outFd, inFd, inOffset, length, callback) {
|
|
||||||
process.fs.sendfile(outFd, inFd, inOffset, length, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.sendfileSync = function (outFd, inFd, inOffset, length) {
|
|
||||||
return process.fs.sendfile(outFd, inFd, inOffset, length);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readdir = function (path, callback) {
|
|
||||||
process.fs.readdir(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readdirSync = function (path) {
|
|
||||||
return process.fs.readdir(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.lstat = function (path, callback) {
|
|
||||||
process.fs.lstat(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.stat = function (path, callback) {
|
|
||||||
process.fs.stat(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.lstatSync = function (path) {
|
|
||||||
return process.fs.lstat(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.statSync = function (path) {
|
|
||||||
return process.fs.stat(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readlink = function (path, callback) {
|
|
||||||
process.fs.readlink(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readlinkSync = function (path) {
|
|
||||||
return process.fs.readlink(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.symlink = function (destination, path, callback) {
|
|
||||||
process.fs.symlink(destination, path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.symlinkSync = function (destination, path) {
|
|
||||||
return process.fs.symlink(destination, path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.link = function (srcpath, dstpath, callback) {
|
|
||||||
process.fs.link(srcpath, dstpath, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.linkSync = function (srcpath, dstpath) {
|
|
||||||
return process.fs.link(srcpath, dstpath);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.unlink = function (path, callback) {
|
|
||||||
process.fs.unlink(path, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.unlinkSync = function (path) {
|
|
||||||
return process.fs.unlink(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.chmod = function (path, mode, callback) {
|
|
||||||
process.fs.chmod(path, mode, callback || noop);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.chmodSync = function (path, mode) {
|
|
||||||
return process.fs.chmod(path, mode);
|
|
||||||
};
|
|
||||||
|
|
||||||
function writeAll (fd, data, encoding, callback) {
|
|
||||||
exports.write(fd, data, 0, encoding, function (writeErr, written) {
|
|
||||||
if (writeErr) {
|
|
||||||
exports.close(fd, function () {
|
|
||||||
if (callback) callback(writeErr);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (written === data.length) {
|
|
||||||
exports.close(fd, callback);
|
|
||||||
} else {
|
|
||||||
writeAll(fd, data.slice(written), encoding, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.writeFile = function (path, data, encoding_, callback) {
|
|
||||||
var encoding = (typeof(encoding_) == 'string' ? encoding_ : 'utf8');
|
|
||||||
var callback_ = arguments[arguments.length - 1];
|
|
||||||
var callback = (typeof(callback_) == 'function' ? callback_ : null);
|
|
||||||
exports.open(path, 'w', 0666, function (openErr, fd) {
|
|
||||||
if (openErr) {
|
|
||||||
if (callback) callback(openErr);
|
|
||||||
} else {
|
|
||||||
writeAll(fd, data, encoding, callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.writeFileSync = function (path, data, encoding) {
|
|
||||||
encoding = encoding || "utf8"; // default to utf8
|
|
||||||
var fd = exports.openSync(path, "w");
|
|
||||||
var written = 0;
|
|
||||||
while (written < data.length) {
|
|
||||||
written += exports.writeSync(fd, data, 0, encoding);
|
|
||||||
data = data.slice(written);
|
|
||||||
}
|
|
||||||
exports.closeSync(fd);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.cat = function () {
|
|
||||||
throw new Error("fs.cat is deprecated. Please use fs.readFile instead.");
|
|
||||||
};
|
|
||||||
|
|
||||||
function readAll (fd, pos, content, encoding, callback) {
|
|
||||||
exports.read(fd, 4*1024, pos, encoding, function (err, chunk, bytesRead) {
|
|
||||||
if (err) {
|
|
||||||
if (callback) callback(err);
|
|
||||||
} else if (chunk) {
|
|
||||||
content += chunk;
|
|
||||||
pos += bytesRead;
|
|
||||||
readAll(fd, pos, content, encoding, callback);
|
|
||||||
} else {
|
|
||||||
process.fs.close(fd, function (err) {
|
|
||||||
if (callback) callback(err, content);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.readFile = function (path, encoding_, callback) {
|
|
||||||
var encoding = typeof(encoding_) == 'string' ? encoding : 'utf8';
|
|
||||||
var callback_ = arguments[arguments.length - 1];
|
|
||||||
var callback = (typeof(callback_) == 'function' ? callback_ : null);
|
|
||||||
exports.open(path, 'r', 0666, function (err, fd) {
|
|
||||||
if (err) {
|
|
||||||
if (callback) callback(err);
|
|
||||||
} else {
|
|
||||||
readAll(fd, 0, "", encoding, callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.catSync = function () {
|
|
||||||
throw new Error("fs.catSync is deprecated. Please use fs.readFileSync instead.");
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.readFileSync = function (path, encoding) {
|
|
||||||
encoding = encoding || "utf8"; // default to utf8
|
|
||||||
|
|
||||||
debug('readFileSync open');
|
|
||||||
|
|
||||||
var fd = exports.openSync(path, "r");
|
|
||||||
var content = '';
|
|
||||||
var pos = 0;
|
|
||||||
var r;
|
|
||||||
|
|
||||||
while ((r = exports.readSync(fd, 4*1024, pos, encoding)) && r[0]) {
|
|
||||||
debug('readFileSync read ' + r[1]);
|
|
||||||
content += r[0];
|
|
||||||
pos += r[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
debug('readFileSync close');
|
|
||||||
|
|
||||||
exports.closeSync(fd);
|
|
||||||
|
|
||||||
debug('readFileSync done');
|
|
||||||
|
|
||||||
return content;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
var fs = fsModule.exports;
|
|
||||||
|
|
||||||
|
return content;
|
||||||
|
};
|
||||||
|
|
||||||
var pathModule = createInternalModule("path", function (exports) {
|
var pathModule = createInternalModule("path", function (exports) {
|
||||||
exports.join = function () {
|
exports.join = function () {
|
||||||
@ -703,7 +406,7 @@ var pathModule = createInternalModule("path", function (exports) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.exists = function (path, callback) {
|
exports.exists = function (path, callback) {
|
||||||
fs.stat(path, function (err, stats) {
|
process.fs.stat(path, function (err, stats) {
|
||||||
if (callback) callback(err ? false : true);
|
if (callback) callback(err ? false : true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -713,7 +416,7 @@ var path = pathModule.exports;
|
|||||||
|
|
||||||
function existsSync (path) {
|
function existsSync (path) {
|
||||||
try {
|
try {
|
||||||
fs.statSync(path);
|
process.fs.stat(path);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@ -932,7 +635,7 @@ function cat (id, callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fs.readFile(id, callback);
|
process.fs.readFile(id, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,7 +674,7 @@ Module.prototype._loadContent = function (content, filename) {
|
|||||||
|
|
||||||
|
|
||||||
Module.prototype._loadScriptSync = function (filename) {
|
Module.prototype._loadScriptSync = function (filename) {
|
||||||
var content = fs.readFileSync(filename);
|
var content = process.fs.readFileSync(filename);
|
||||||
// remove shebang
|
// remove shebang
|
||||||
content = content.replace(/^\#\!.*/, '');
|
content = content.replace(/^\#\!.*/, '');
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ static Handle<Value> ReadLink(const Arguments& args) {
|
|||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
ssize_t bz = readlink(*path, buf, PATH_MAX);
|
ssize_t bz = readlink(*path, buf, PATH_MAX);
|
||||||
if (bz == -1) return ThrowException(errno_exception(errno));
|
if (bz == -1) return ThrowException(errno_exception(errno));
|
||||||
return scope.Close(String::New(buf));
|
return scope.Close(String::New(buf, bz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ var path = require("path");
|
|||||||
exports.testDir = path.dirname(__filename);
|
exports.testDir = path.dirname(__filename);
|
||||||
exports.fixturesDir = path.join(exports.testDir, "fixtures");
|
exports.fixturesDir = path.join(exports.testDir, "fixtures");
|
||||||
exports.libDir = path.join(exports.testDir, "../lib");
|
exports.libDir = path.join(exports.testDir, "../lib");
|
||||||
|
exports.PORT = 12346;
|
||||||
|
|
||||||
require.paths.unshift(exports.libDir);
|
require.paths.unshift(exports.libDir);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common.js"));
|
process.mixin(require("../common.js"));
|
||||||
http = require("/http.js");
|
http = require("/http.js");
|
||||||
PORT = 8888;
|
|
||||||
|
|
||||||
puts("hello world");
|
puts("hello world");
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
process.mixin(require("./common"));
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
var dns = require("dns"),
|
var dns = require("dns"),
|
||||||
sys = require("sys");
|
sys = require("sys");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* XXX Can this test be modified to not call the now-removed wait()? */
|
/* XXX Can this test be modified to not call the now-removed wait()? */
|
||||||
|
|
||||||
process.mixin(require("./common"));
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
|
|
||||||
puts('first stat ...');
|
puts('first stat ...');
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
process.mixin(require("./common"));
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
sys = require("sys");
|
sys = require("sys");
|
||||||
PORT = 23123;
|
|
||||||
var x = path.join(fixturesDir, "x.txt");
|
var x = path.join(fixturesDir, "x.txt");
|
||||||
var expected = "xyz";
|
var expected = "xyz";
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require('../common.js'));
|
process.mixin(require('../common.js'));
|
||||||
|
|
||||||
var PORT = 8003;
|
|
||||||
var request_count = 1000;
|
var request_count = 1000;
|
||||||
var response_body = '{"ok": true}';
|
var response_body = '{"ok": true}';
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ var tcp = require("tcp"),
|
|||||||
sys = require("sys"),
|
sys = require("sys"),
|
||||||
http = require("http");
|
http = require("http");
|
||||||
|
|
||||||
var PORT = 2143;
|
|
||||||
|
|
||||||
var errorCount = 0;
|
var errorCount = 0;
|
||||||
var eofCount = 0;
|
var eofCount = 0;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
sys = require("sys");
|
sys = require("sys");
|
||||||
PORT = 8891;
|
|
||||||
|
|
||||||
body = "hello world\n";
|
body = "hello world\n";
|
||||||
server = http.createServer(function (req, res) {
|
server = http.createServer(function (req, res) {
|
||||||
|
@ -3,7 +3,6 @@ process.mixin(require("../common"));
|
|||||||
var http = require("http"),
|
var http = require("http"),
|
||||||
multipart = require("multipart"),
|
multipart = require("multipart"),
|
||||||
sys = require("sys"),
|
sys = require("sys"),
|
||||||
PORT = 8222,
|
|
||||||
fixture = require("../fixtures/multipart"),
|
fixture = require("../fixtures/multipart"),
|
||||||
events = require("events"),
|
events = require("events"),
|
||||||
testPart = function (expect, part) {
|
testPart = function (expect, part) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
// settings
|
// settings
|
||||||
var port = 20743;
|
|
||||||
var bytes = 1024*40;
|
var bytes = 1024*40;
|
||||||
var concurrency = 100;
|
var concurrency = 100;
|
||||||
var connections_per_client = 5;
|
var connections_per_client = 5;
|
||||||
@ -22,10 +21,10 @@ var server = tcp.createServer(function (c) {
|
|||||||
c.close();
|
c.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(port);
|
server.listen(PORT);
|
||||||
|
|
||||||
function runClient (callback) {
|
function runClient (callback) {
|
||||||
var client = tcp.createConnection(port);
|
var client = tcp.createConnection(PORT);
|
||||||
client.connections = 0;
|
client.connections = 0;
|
||||||
client.setEncoding("utf8");
|
client.setEncoding("utf8");
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ function runClient (callback) {
|
|||||||
assert.equal(false, had_error);
|
assert.equal(false, had_error);
|
||||||
assert.equal(bytes, client.recved.length);
|
assert.equal(bytes, client.recved.length);
|
||||||
if (this.connections < connections_per_client) {
|
if (this.connections < connections_per_client) {
|
||||||
this.connect(port);
|
this.connect(PORT);
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pingPongTest(21988);
|
pingPongTest(PORT);
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal(1, tests_run);
|
assert.equal(1, tests_run);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
|
|
||||||
|
|
||||||
var tests_run = 0;
|
var tests_run = 0;
|
||||||
|
|
||||||
function pingPongTest (port, host, on_complete) {
|
function pingPongTest (port, host, on_complete) {
|
||||||
@ -81,9 +80,9 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* All are run at once, so run on different ports */
|
/* All are run at once, so run on different ports */
|
||||||
pingPongTest(20989, "localhost");
|
pingPongTest(PORT, "localhost");
|
||||||
pingPongTest(20988, null);
|
pingPongTest(PORT+1, null);
|
||||||
pingPongTest(20997, "::1");
|
pingPongTest(PORT+2, "::1");
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal(3, tests_run);
|
assert.equal(3, tests_run);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
PORT = 20444;
|
|
||||||
N = 30*1024; // 500kb
|
N = 30*1024; // 500kb
|
||||||
|
|
||||||
puts("build big string");
|
puts("build big string");
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
PORT = 20443;
|
|
||||||
N = 200;
|
N = 200;
|
||||||
|
|
||||||
server = tcp.createServer(function (connection) {
|
server = tcp.createServer(function (connection) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
port = 9992;
|
|
||||||
exchanges = 0;
|
exchanges = 0;
|
||||||
starttime = null;
|
starttime = null;
|
||||||
timeouttime = null;
|
timeouttime = null;
|
||||||
@ -25,10 +24,10 @@ var echo_server = tcp.createServer(function (socket) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
echo_server.listen(port);
|
echo_server.listen(PORT);
|
||||||
puts("server listening at " + port);
|
puts("server listening at " + PORT);
|
||||||
|
|
||||||
var client = tcp.createConnection(port);
|
var client = tcp.createConnection(PORT);
|
||||||
client.setEncoding("UTF8");
|
client.setEncoding("UTF8");
|
||||||
client.setTimeout(0); // disable the timeout for client
|
client.setTimeout(0); // disable the timeout for client
|
||||||
client.addListener("connect", function () {
|
client.addListener("connect", function () {
|
||||||
|
@ -110,8 +110,8 @@ if (have_tls) {
|
|||||||
var keyPem = fs.readFileSync(fixturesDir+"/test_key.pem");
|
var keyPem = fs.readFileSync(fixturesDir+"/test_key.pem");
|
||||||
|
|
||||||
/* All are run at once, so run on different ports */
|
/* All are run at once, so run on different ports */
|
||||||
tlsTest(20443, "localhost", caPem, keyPem, certPem);
|
tlsTest(PORT, "localhost", caPem, keyPem, certPem);
|
||||||
tlsTest(21443, null, caPem, keyPem, certPem);
|
tlsTest(PORT+1, null, caPem, keyPem, certPem);
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal(2, tests_run);
|
assert.equal(2, tests_run);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var f = path.join(fixturesDir, "x.txt");
|
var f = path.join(fixturesDir, "x.txt");
|
||||||
@ -8,16 +9,14 @@ var f2 = path.join(fixturesDir, "x2.txt");
|
|||||||
puts("watching for changes of " + f);
|
puts("watching for changes of " + f);
|
||||||
|
|
||||||
var changes = 0;
|
var changes = 0;
|
||||||
process.watchFile(f, function (curr, prev) {
|
fs.watchFile(f, function (curr, prev) {
|
||||||
puts(f + " change");
|
puts(f + " change");
|
||||||
changes++;
|
changes++;
|
||||||
assert.ok(curr.mtime != prev.mtime);
|
assert.ok(curr.mtime != prev.mtime);
|
||||||
process.unwatchFile(f);
|
fs.unwatchFile(f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var fs = require("fs");
|
|
||||||
|
|
||||||
var fd = fs.openSync(f, "w+");
|
var fd = fs.openSync(f, "w+");
|
||||||
fs.writeSync(fd, 'xyz\n');
|
fs.writeSync(fd, 'xyz\n');
|
||||||
fs.closeSync(fd);
|
fs.closeSync(fd);
|
||||||
|
56
test/simple/test-fs-realpath.js
Normal file
56
test/simple/test-fs-realpath.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
|
var async_completed = 0, async_expected = 0;
|
||||||
|
|
||||||
|
// a. deep relative file symlink
|
||||||
|
var dstPath = path.join(fixturesDir, 'cycles', 'root.js');
|
||||||
|
var linkData1 = "../../cycles/root.js";
|
||||||
|
var linkPath1 = path.join(fixturesDir, "nested-index", 'one', 'symlink1.js');
|
||||||
|
try {fs.unlinkSync(linkPath1);}catch(e){}
|
||||||
|
fs.symlinkSync(linkData1, linkPath1);
|
||||||
|
|
||||||
|
var linkData2 = "../one/symlink1.js";
|
||||||
|
var linkPath2 = path.join(fixturesDir, "nested-index", 'two', 'symlink1-b.js');
|
||||||
|
try {fs.unlinkSync(linkPath2);}catch(e){}
|
||||||
|
fs.symlinkSync(linkData2, linkPath2);
|
||||||
|
|
||||||
|
// b. deep relative directory symlink
|
||||||
|
var dstPath_b = path.join(fixturesDir, 'cycles', 'folder');
|
||||||
|
var linkData1b = "../../cycles/folder";
|
||||||
|
var linkPath1b = path.join(fixturesDir, "nested-index", 'one', 'symlink1-dir');
|
||||||
|
try {fs.unlinkSync(linkPath1b);}catch(e){}
|
||||||
|
fs.symlinkSync(linkData1b, linkPath1b);
|
||||||
|
|
||||||
|
var linkData2b = "../one/symlink1-dir";
|
||||||
|
var linkPath2b = path.join(fixturesDir, "nested-index", 'two', 'symlink12-dir');
|
||||||
|
try {fs.unlinkSync(linkPath2b);}catch(e){}
|
||||||
|
fs.symlinkSync(linkData2b, linkPath2b);
|
||||||
|
|
||||||
|
assert.equal(fs.realpathSync(linkPath2), dstPath);
|
||||||
|
assert.equal(fs.realpathSync(linkPath2b), dstPath_b);
|
||||||
|
|
||||||
|
async_expected++;
|
||||||
|
fs.realpath(linkPath2, function(err, rpath) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.equal(rpath, dstPath);
|
||||||
|
async_completed++;
|
||||||
|
});
|
||||||
|
|
||||||
|
async_expected++;
|
||||||
|
fs.realpath(linkPath2b, function(err, rpath) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.equal(rpath, dstPath_b);
|
||||||
|
async_completed++;
|
||||||
|
});
|
||||||
|
|
||||||
|
// todo: test shallow symlinks (file & dir)
|
||||||
|
// todo: test non-symlinks (file & dir)
|
||||||
|
// todo: test error on cyclic symlinks
|
||||||
|
|
||||||
|
process.addListener("exit", function () {
|
||||||
|
try {fs.unlinkSync(linkPath1);}catch(e){}
|
||||||
|
try {fs.unlinkSync(linkPath2);}catch(e){}
|
||||||
|
try {fs.unlinkSync(linkPath1b);}catch(e){}
|
||||||
|
try {fs.unlinkSync(linkPath2b);}catch(e){}
|
||||||
|
assert.equal(async_completed, async_expected);
|
||||||
|
});
|
@ -2,8 +2,6 @@ process.mixin(require("../common"));
|
|||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
http = require("http");
|
http = require("http");
|
||||||
|
|
||||||
var port = 7333;
|
|
||||||
|
|
||||||
var body = "hello world\n";
|
var body = "hello world\n";
|
||||||
var server_response = "";
|
var server_response = "";
|
||||||
var client_got_eof = false;
|
var client_got_eof = false;
|
||||||
@ -13,9 +11,9 @@ var server = http.createServer(function (req, res) {
|
|||||||
res.write(body);
|
res.write(body);
|
||||||
res.close();
|
res.close();
|
||||||
})
|
})
|
||||||
server.listen(port);
|
server.listen(PORT);
|
||||||
|
|
||||||
var c = tcp.createConnection(port);
|
var c = tcp.createConnection(PORT);
|
||||||
|
|
||||||
c.setEncoding("utf8");
|
c.setEncoding("utf8");
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
PORT = 8888;
|
|
||||||
|
|
||||||
var body = "exports.A = function() { return 'A';}";
|
var body = "exports.A = function() { return 'A';}";
|
||||||
var server = http.createServer(function (req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var PORT = 8888;
|
|
||||||
|
|
||||||
var UTF8_STRING = "Il était tué";
|
var UTF8_STRING = "Il était tué";
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
url = require("url");
|
url = require("url");
|
||||||
PORT = 8888;
|
|
||||||
|
|
||||||
var body1_s = "1111111111111111";
|
var body1_s = "1111111111111111";
|
||||||
var body2_s = "22222";
|
var body2_s = "22222";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
var PORT = 18032;
|
|
||||||
|
|
||||||
var sent_body = "";
|
var sent_body = "";
|
||||||
var server_req_complete = false;
|
var server_req_complete = false;
|
||||||
|
@ -5,12 +5,11 @@ http = require("http");
|
|||||||
// This is a regression test for http://github.com/ry/node/issues/#issue/44
|
// This is a regression test for http://github.com/ry/node/issues/#issue/44
|
||||||
// It is separate from test-http-malformed-request.js because it is only
|
// It is separate from test-http-malformed-request.js because it is only
|
||||||
// reproduceable on the first packet on the first connection to a server.
|
// reproduceable on the first packet on the first connection to a server.
|
||||||
port = 9999;
|
|
||||||
|
|
||||||
server = http.createServer(function (req, res) {});
|
server = http.createServer(function (req, res) {});
|
||||||
server.listen(port);
|
server.listen(PORT);
|
||||||
|
|
||||||
tcp.createConnection(port).addListener("connect", function () {
|
tcp.createConnection(PORT).addListener("connect", function () {
|
||||||
this.close();
|
this.close();
|
||||||
}).addListener("close", function () {
|
}).addListener("close", function () {
|
||||||
server.close();
|
server.close();
|
||||||
|
@ -5,7 +5,6 @@ url = require("url");
|
|||||||
|
|
||||||
// Make sure no exceptions are thrown when receiving malformed HTTP
|
// Make sure no exceptions are thrown when receiving malformed HTTP
|
||||||
// requests.
|
// requests.
|
||||||
port = 9999;
|
|
||||||
|
|
||||||
nrequests_completed = 0;
|
nrequests_completed = 0;
|
||||||
nrequests_expected = 1;
|
nrequests_expected = 1;
|
||||||
@ -19,9 +18,9 @@ var s = http.createServer(function (req, res) {
|
|||||||
|
|
||||||
if (++nrequests_completed == nrequests_expected) s.close();
|
if (++nrequests_completed == nrequests_expected) s.close();
|
||||||
});
|
});
|
||||||
s.listen(port);
|
s.listen(PORT);
|
||||||
|
|
||||||
var c = tcp.createConnection(port);
|
var c = tcp.createConnection(PORT);
|
||||||
c.addListener("connect", function () {
|
c.addListener("connect", function () {
|
||||||
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
||||||
c.close();
|
c.close();
|
||||||
|
@ -2,8 +2,8 @@ process.mixin(require("../common"));
|
|||||||
http = require("http");
|
http = require("http");
|
||||||
url = require("url");
|
url = require("url");
|
||||||
|
|
||||||
var PROXY_PORT = 8869;
|
var PROXY_PORT = PORT;
|
||||||
var BACKEND_PORT = 8870;
|
var BACKEND_PORT = PORT+1;
|
||||||
|
|
||||||
var backend = http.createServer(function (req, res) {
|
var backend = http.createServer(function (req, res) {
|
||||||
// debug("backend");
|
// debug("backend");
|
||||||
|
@ -4,8 +4,6 @@ http = require("http");
|
|||||||
url = require("url");
|
url = require("url");
|
||||||
qs = require("querystring");
|
qs = require("querystring");
|
||||||
|
|
||||||
var port = 8222;
|
|
||||||
|
|
||||||
var request_number = 0;
|
var request_number = 0;
|
||||||
var requests_sent = 0;
|
var requests_sent = 0;
|
||||||
var server_response = "";
|
var server_response = "";
|
||||||
@ -43,9 +41,9 @@ http.createServer(function (req, res) {
|
|||||||
res.close();
|
res.close();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
}).listen(port);
|
}).listen(PORT);
|
||||||
|
|
||||||
var c = tcp.createConnection(port);
|
var c = tcp.createConnection(PORT);
|
||||||
|
|
||||||
c.setEncoding("utf8");
|
c.setEncoding("utf8");
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
url = require("url");
|
url = require("url");
|
||||||
PORT = 8888;
|
|
||||||
|
|
||||||
HOST = "localhost";
|
HOST = "localhost";
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@ http = require("http");
|
|||||||
// content-length is not provided, that the connection is in fact
|
// content-length is not provided, that the connection is in fact
|
||||||
// closed.
|
// closed.
|
||||||
|
|
||||||
var port = 7333;
|
|
||||||
|
|
||||||
var server_response = "";
|
var server_response = "";
|
||||||
var client_got_eof = false;
|
var client_got_eof = false;
|
||||||
var connection_was_closed = false;
|
var connection_was_closed = false;
|
||||||
@ -29,9 +27,9 @@ var server = http.createServer(function (req, res) {
|
|||||||
res.write("world\n");
|
res.write("world\n");
|
||||||
res.close();
|
res.close();
|
||||||
})
|
})
|
||||||
server.listen(port);
|
server.listen(PORT);
|
||||||
|
|
||||||
var c = tcp.createConnection(port);
|
var c = tcp.createConnection(PORT);
|
||||||
|
|
||||||
c.setEncoding("utf8");
|
c.setEncoding("utf8");
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
http = require("http");
|
http = require("http");
|
||||||
url = require("url");
|
url = require("url");
|
||||||
PORT = 8888;
|
|
||||||
|
|
||||||
var responses_sent = 0;
|
var responses_sent = 0;
|
||||||
var responses_recvd = 0;
|
var responses_recvd = 0;
|
||||||
|
@ -28,10 +28,19 @@ var source = {
|
|||||||
get foo(){ return this._foo; },
|
get foo(){ return this._foo; },
|
||||||
set foo(value){ this._foo = "did set to "+value; }
|
set foo(value){ this._foo = "did set to "+value; }
|
||||||
};
|
};
|
||||||
var target = {};
|
target = {};
|
||||||
process.mixin(target, source);
|
process.mixin(target, source);
|
||||||
target._foo = 'b';
|
target._foo = 'b';
|
||||||
assert.equal(source.foo, 'a');
|
assert.equal(source.foo, 'a');
|
||||||
assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function');
|
assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function');
|
||||||
source.foo = 'c';
|
source.foo = 'c';
|
||||||
assert.equal('did set to c', source.foo, 'source.foo != "c" -- value was set instead of calling setter function');
|
assert.equal('did set to c', source.foo, 'source.foo != "c" -- value was set instead of calling setter function');
|
||||||
|
|
||||||
|
// Test that nested arrays are handled properly
|
||||||
|
target = {};
|
||||||
|
process.mixin(true, target, {
|
||||||
|
foo: ['bar'],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.notStrictEqual(['bar'], target.foo);
|
||||||
|
assert.deepEqual(['bar'], target.foo);
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
|
|
||||||
var PORT = 8889;
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var sys = require('sys');
|
var sys = require('sys');
|
||||||
var url = require("url");
|
var url = require("url");
|
||||||
|
@ -26,11 +26,11 @@ assert.equal('{ a: [Function] }', inspect({a: function() {}}));
|
|||||||
assert.equal('{ a: 1, b: 2 }', inspect({a: 1, b: 2}));
|
assert.equal('{ a: 1, b: 2 }', inspect({a: 1, b: 2}));
|
||||||
assert.equal('{ a: {} }', inspect({'a': {}}));
|
assert.equal('{ a: {} }', inspect({'a': {}}));
|
||||||
assert.equal('{ a: { b: 2 } }', inspect({'a': {'b': 2}}));
|
assert.equal('{ a: { b: 2 } }', inspect({'a': {'b': 2}}));
|
||||||
assert.equal('{ a: { b: { c: [object Object] } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
|
assert.equal('{ a: { b: { c: [Object] } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
|
||||||
assert.equal('{ a: { b: { c: { d: 2 } } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
|
assert.equal('{ a: { b: { c: { d: 2 } } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
|
||||||
assert.equal('[ 1, 2, 3, [length]: 3 ]', inspect([1,2,3], true));
|
assert.equal('[ 1, 2, 3, [length]: 3 ]', inspect([1,2,3], true));
|
||||||
assert.equal('{ a: [object Object] }', inspect({'a': {'b': { 'c': 2}}},false,0));
|
assert.equal('{ a: [Object] }', inspect({'a': {'b': { 'c': 2}}},false,0));
|
||||||
assert.equal('{ a: { b: [object Object] } }', inspect({'a': {'b': { 'c': 2}}},false,1));
|
assert.equal('{ a: { b: [Object] } }', inspect({'a': {'b': { 'c': 2}}},false,1));
|
||||||
assert.equal("{ visible: 1 }",
|
assert.equal("{ visible: 1 }",
|
||||||
inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}}))
|
inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}}))
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
PORT = 23123;
|
|
||||||
|
|
||||||
binaryString = "";
|
binaryString = "";
|
||||||
for (var i = 255; i >= 0; i--) {
|
for (var i = 255; i >= 0; i--) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
process.mixin(require("../common"));
|
process.mixin(require("../common"));
|
||||||
tcp = require("tcp");
|
tcp = require("tcp");
|
||||||
var N = 50;
|
var N = 50;
|
||||||
var port = 8921;
|
|
||||||
|
|
||||||
var c = 0;
|
var c = 0;
|
||||||
var client_recv_count = 0;
|
var client_recv_count = 0;
|
||||||
@ -21,9 +20,9 @@ var server = tcp.createServer(function (socket) {
|
|||||||
assert.equal(false, had_error);
|
assert.equal(false, had_error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(port);
|
server.listen(PORT);
|
||||||
|
|
||||||
var client = tcp.createConnection(port);
|
var client = tcp.createConnection(PORT);
|
||||||
|
|
||||||
client.setEncoding("UTF8");
|
client.setEncoding("UTF8");
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ client.addListener("close", function (had_error) {
|
|||||||
puts("disconnect");
|
puts("disconnect");
|
||||||
assert.equal(false, had_error);
|
assert.equal(false, had_error);
|
||||||
if (disconnect_count++ < N)
|
if (disconnect_count++ < N)
|
||||||
client.connect(port); // reconnect
|
client.connect(PORT); // reconnect
|
||||||
else
|
else
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user