diff --git a/lib/net.js b/lib/net_legacy.js similarity index 100% rename from lib/net.js rename to lib/net_legacy.js diff --git a/lib/tty_posix.js b/lib/tty_posix.js index a114d7cba2..b745a6a79d 100644 --- a/lib/tty_posix.js +++ b/lib/tty_posix.js @@ -21,7 +21,7 @@ var binding = process.binding('stdio'), - net = require('net'), + net = require('net_legacy'), // FIXME inherits = require('util').inherits, spawn = require('child_process').spawn; diff --git a/src/node.cc b/src/node.cc index 65dcf676ad..9d289dba9b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -123,6 +123,18 @@ static uv_async_t eio_want_poll_notifier; static uv_async_t eio_done_poll_notifier; static uv_idle_t eio_poller; + +// XXX use_uv defaults to false on POSIX platforms and to true on Windows +// platforms. This can be set with "--use-uv" command-line flag. We intend +// to remove the legacy backend once the libuv backend is passing all of the +// tests. +#ifdef __POSIX__ +static bool use_uv = false; +#else +static bool use_uv = true; +#endif + + // Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this // scoped at file-level rather than method-level to avoid excess stack usage. static char getbuf[PATH_MAX + 1]; @@ -2082,6 +2094,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { process->Set(String::NewSymbol("pid"), Integer::New(getpid())); process->Set(String::NewSymbol("cov"), cov ? True() : False()); + process->Set(String::NewSymbol("useUV"), use_uv ? True() : False()); // -e, --eval if (eval_string) { @@ -2225,6 +2238,7 @@ static void PrintHelp() { " --vars print various compiled-in variables\n" " --max-stack-size=val set max v8 stack size (bytes)\n" " --cov code coverage; writes node-cov.json \n" + " --use-uv use the libuv backend\n" "\n" "Enviromental variables:\n" "NODE_PATH ':'-separated list of directories\n" @@ -2250,6 +2264,9 @@ static void ParseArgs(int argc, char **argv) { } else if (!strcmp(arg, "--cov")) { cov = true; argv[i] = const_cast(""); + } else if (!strcmp(arg, "--use-uv")) { + use_uv = true; + argv[i] = const_cast(""); } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) { printf("%s\n", NODE_VERSION); exit(0); diff --git a/src/node.js b/src/node.js index 581bb94b84..dd156eec0c 100644 --- a/src/node.js +++ b/src/node.js @@ -387,7 +387,19 @@ var Script = process.binding('evals').NodeScript; var runInThisContext = Script.runInThisContext; + // A special hook to test the new platform layer. Use the command-line + // flag --use-uv to enable the libuv backend instead of the legacy + // backend. + function translateId(id) { + if (id == 'net') { + return process.useUV ? 'net_uv' : 'net_legacy'; + } else { + return id; + } + } + function NativeModule(id) { + id = translateId(id); this.filename = id + '.js'; this.id = id; this.exports = {}; @@ -398,6 +410,8 @@ NativeModule._cache = {}; NativeModule.require = function(id) { + id = translateId(id); + if (id == 'native_module') { return NativeModule; } @@ -420,14 +434,17 @@ }; NativeModule.getCached = function(id) { + id = translateId(id); return NativeModule._cache[id]; } NativeModule.exists = function(id) { + id = translateId(id); return (id in NativeModule._source); } NativeModule.getSource = function(id) { + id = translateId(id); return NativeModule._source[id]; }