libDir = node.path.join(node.path.dirname(__filename), "../lib");
node.libraryPaths.unshift(libDir);
-include("/utils.js");
+node.mixin(require("/utils.js"));
http = require("/http.js");
fixed = ""
var arg = commands[2];
var status = 200;
- //p(req.headers);
+ p(req.uri.params);
if (command == "bytes") {
var n = parseInt(arg, 10)
libDir = node.path.join(node.path.dirname(__filename), "../lib");
node.libraryPaths.unshift(libDir);
-include("/utils.js");
+node.mixin(require("/utils.js"));
function next (i) {
if (i <= 0) return;
libDir = node.path.join(node.path.dirname(__filename), "../lib");
node.libraryPaths.unshift(libDir);
-include("/utils.js");
+node.mixin(require("/utils.js"));
var benchmarks = [ "static_http_server.js"
, "timers.js"
, "process_loop.js"
#!/usr/bin/env node
-include("/utils.js");
+node.mixin(require("/utils.js"));
puts("Welcome to the Node.js REPL.");
puts("Enter ECMAScript at the prompt.");
puts("Tip 1: Use 'rlwrap node-repl' for a better interface");
World":
----------------------------------------
-include("/utils.js");
-include("/http.js");
+node.mixin(require("/utils.js"));
+node.mixin(require("/http.js"));
createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n");
The filename of the script being executed.
+require(path)+ ::
-+include(path)+ ::
See the modules section.
+node.libraryPaths+ ::
-The search path for absolute path arguments to +require()+ and +include()+.
+The search path for absolute path arguments to +require()+.
+
++node.mixin([deep], target, object1, [objectN])+ ::
+Extend one object with one or more others, returning the modified object.
+If no target is specified, the +process+ namespace itself is extended.
+Keep in mind that the target object will be modified, and will be returned
+from +node.mixin()+.
++
+If a boolean true is specified as the first argument, Node performs a deep
+copy, recursively copying any objects it finds. Otherwise, the copy will
+share structure with the original object(s).
++
+Undefined properties are not copied. However, properties inherited from the
+object's prototype will be copied over.
=== The +process+ Object
in a promise callback.
+
----------------------------------------
-include("/utils.js");
+node.mixin(require("/utils.js"));
exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout);
});
----------------------------------------
var circle = require("circle.js");
-include("/utils.js");
+node.mixin(require("/utils.js"));
puts("The area of a circle of radius 4 is " + circle.area(4));
----------------------------------------
object. (Alternatively, one can use +this+ instead of +exports+.) Variables
local to the module will be private. In this example the variable +PI+ is
private to +circle.js+. The function +puts()+ comes from the module
-+"/utils.js"+. Because +include("/utils.js")+ was called, +puts()+ is in the
-global namespace.
++"/utils.js"+.
The module path is relative to the file calling +require()+. That is,
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to
find it.
-Like +require()+ the function +include()+ also loads a module. Instead of
-returning a namespace object, +include()+ will add the module's exports into
-the global namespace. For example:
+Use +node.mixin()+ to include modules into the global namespace.
----------------------------------------
-include("circle.js");
-include("/utils.js");
+node.mixin(process, require("circle.js"), require("/utils.js"));
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------
-When an absolute path is given to +require()+ or +include()+, like
+When an absolute path is given to +require()+, like
+require("/mjsunit.js")+ the module is searched for in the
+node.libraryPaths+ array. +node.libraryPaths+ on my system looks like this:
=== HTTP
-To use the HTTP server and client one must +require("/http.js")+ or
-+include("/http.js")+.
+To use the HTTP server and client one must +require("/http.js")+.
The HTTP interfaces in Node are designed to support many features
of the protocol which have been traditionally difficult to use.
=== TCP
-To use the TCP server and client one must +require("/tcp.js")+ or
-+include("/tcp.js")+.
+To use the TCP server and client one must +require("/tcp.js")+.
==== +tcp.Server+
on port 7000
----------------------------------------
-include("/tcp.js");
+node.mixin(require("/tcp.js"));
var server = createServer(function (socket) {
socket.setEncoding("utf8");
socket.addListener("connect", function () {
The library is called +/repl.js+ and it can be used like this:
------------------------------------
-include("/utils.js");
-include("/tcp.js");
+node.mixin(require("/utils.js"));
+node.mixin(require("/tcp.js"));
nconnections = 0;
createServer(function (c) {
error("Connection!");
};
node.exec = function () {
- throw new Error("node.exec() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("node.exec() has moved. Use require('/utils.js') to bring it back.");
}
node.http.createServer = function () {
throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
};
+/* From jQuery.extend in the jQuery JavaScript Library v1.3.2
+ * Copyright (c) 2009 John Resig
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ */
+node.mixin = function() {
+ // copy reference to target object
+ var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
+
+ // Handle a deep copy situation
+ if ( typeof target === "boolean" ) {
+ deep = target;
+ target = arguments[1] || {};
+ // skip the boolean and the target
+ i = 2;
+ }
+
+ // Handle case when target is a string or something (possible in deep copy)
+ if ( typeof target !== "object" && !node.isFunction(target) )
+ target = {};
+
+ // mixin process itself if only one argument is passed
+ if ( length == i ) {
+ target = process;
+ --i;
+ }
+
+ for ( ; i < length; i++ )
+ // Only deal with non-null/undefined values
+ if ( (options = arguments[ i ]) != null )
+ // Extend the base object
+ for ( var name in options ) {
+ var src = target[ name ], copy = options[ name ];
+
+ // Prevent never-ending loop
+ if ( target === copy )
+ continue;
+
+ // Recurse if we're merging object values
+ if ( deep && copy && typeof copy === "object" && !copy.nodeType )
+ target[ name ] = node.mixin( deep,
+ // Never move original objects, clone them
+ src || ( copy.length != null ? [ ] : { } )
+ , copy );
+
+ // Don't bring in undefined values
+ else if ( copy !== undefined )
+ target[ name ] = copy;
+
+ }
+
+ // Return the modified object
+ return target;
+};
+
// Timers
function setTimeout (callback, after) {
return requireAsync(url).wait();
}
- function includeAsync (url) {
- var promise = requireAsync(url)
- promise.addCallback(function (t) {
- // copy properties into global namespace.
- for (var prop in t) {
- if (t.hasOwnProperty(prop)) process[prop] = t[prop];
- }
- });
- return promise;
- }
-
- function include (url) {
- includeAsync(url).wait();
- }
-
// create wrapper function
- var wrapper = "function (__filename, exports, require, include) { " + content + "\n};";
+ var wrapper = "function (__filename, exports, require) { " + content + "\n};";
var compiled_wrapper = node.compile(wrapper, self.filename);
node.loadingModules.unshift(self);
- compiled_wrapper.apply(self.target, [self.filename, self.target, require, include]);
+ compiled_wrapper.apply(self.target, [self.filename, self.target, require]);
node.loadingModules.shift();
self.waitChildrenLoad(function () {
puts = function () {
- throw new Error("puts() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("puts() has moved. Use require('/utils.js') to bring it back.");
}
print = function () {
- throw new Error("print() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("print() has moved. Use require('/utils.js') to bring it back.");
}
p = function () {
- throw new Error("p() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("p() has moved. Use require('/utils.js') to bring it back.");
}
node.debug = function () {
- throw new Error("node.debug() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("node.debug() has moved. Use require('/utils.js') to bring it back.");
}
node.error = function () {
- throw new Error("node.error() has moved. Use include('/utils.js') to bring it back.");
+ throw new Error("node.error() has moved. Use require('/utils.js') to bring it back.");
}
node.libraryPaths.unshift(exports.libDir);
var mjsunit = require("/mjsunit.js");
-include("/utils.js");
-// Copy mjsunit namespace out
-for (var prop in mjsunit) {
- if (mjsunit.hasOwnProperty(prop)) exports[prop] = mjsunit[prop];
-}
-
+var utils = require("/utils.js");
+node.mixin(exports, mjsunit, utils);
-include("common.js");
+node.mixin(require("../common.js"));
http = require("/http.js");
PORT = 8888;
-include('../mjsunit.js');
+node.mixin(require('../common.js'));
var PORT = 8003;
var request_count = 1000;
});
s.listen(8000);
-include("mjsunit.js");
+node.mixin(require("../common.js"));
var a = require("http://localhost:8000/")
assertInstanceof(a.A, Function);
+node.mixin(require("../common.js"));
for (var i = 2; i < ARGV.length; i++) {
var name = ARGV[i]
puts("looking up " + name);
-include("common.js");
+node.mixin(require("common.js"));
var testTxt = node.path.join(fixturesDir, "test.txt");
var libDir = node.path.join(testDir, "../../lib");
node.libraryPaths.unshift(libDir);
-include("/file.js");
+node.mixin(require("/file.js"));
var fileUnlinked = false;
-include("common.js");
+node.mixin(require("common.js"));
setTimeout(function () {
a = require("fixtures/a.js");
-include("common.js");
+node.mixin(require("common.js"));
var e = new node.EventEmitter();
-include("common.js");
+node.mixin(require("common.js"));
success_count = 0;
error_count = 0;
-include("common.js");
+node.mixin(require("common.js"));
var got_error = false;
var filename = node.path.join(fixturesDir, "does_not_exist.txt");
-include("common.js");
+node.mixin(require("common.js"));
var got_error = false;
var success_count = 0;
-include("common.js");
+node.mixin(require("common.js"));
var path = node.path.join(fixturesDir, "write.txt");
var expected = "hello";
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
PORT = 8888;
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
PORT = 8888;
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
var PORT = 18032;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
http = require("/http.js");
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
var PROXY_PORT = 8869;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
http = require("/http.js");
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
PORT = 8888;
-include("common.js");
+node.mixin(require("common.js"));
var dirname = node.path.dirname(__filename);
var fixtures = node.path.join(dirname, "fixtures");
-include("common.js");
+node.mixin(require("common.js"));
debug("load test-module-loading.js");
-include("common.js");
+node.mixin(require("common.js"));
http = require("/http.js");
var multipart = require('/multipart.js');
-include("common.js");
+node.mixin(require("common.js"));
var pwd_called = false;
-include("common.js");
+node.mixin(require("common.js"));
var exit_status = -1;
-include("common.js");
+node.mixin(require("common.js"));
var cat = node.createChildProcess("cat");
-include("common.js");
+node.mixin(require("common.js"));
var N = 40;
var finished = false;
-include("common.js");
+node.mixin(require("common.js"));
var p1_done = false;
var p1 = new node.Promise();
-include("common.js");
+node.mixin(require("common.js"));
var got_error = false;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
PORT = 23123;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
// settings
var port = 20743;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
var N = 50;
var port = 8921;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
PORT = 20444;
N = 30*1024; // 500kb
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
PORT = 20443;
N = 200;
-include("common.js");
+node.mixin(require("common.js"));
tcp = require("/tcp.js");
port = 9992;
exchanges = 0;
-include("common.js");
+node.mixin(require("common.js"));
var WINDOW = 200; // why is does this need to be so big?
-include("common.js");
+node.mixin(require("common.js"));
// üäö
-include("common.js");
+node.mixin(require("common.js"));
function timer (t) {
var promise = new node.Promise();