Skip to content
Browse files

Merge branch 'master' into multipart-update-wip

  • Loading branch information...
2 parents 1bb3176 + 6d2c5c1 commit 493c1d6366cc0b40a16b5aff84b42ed8eddf12bc @isaacs committed Feb 5, 2010
View
6 deps/http_parser/http_parser.c
@@ -1167,6 +1167,12 @@ size_t http_parser_execute (http_parser *parser,
{
c = lowcase[(int)ch];
+ // FIXME: Problem here.
+ // Header values may wrap to the next line by ending with \r\n\s+,
+ // in which case, the header value doesn't end, but should be
+ // appended with a single whitespace character.
+ // See: http://tools.ietf.org/html/rfc2822#section-2.2.3
+
if (!c) {
if (ch == CR) {
CALLBACK(header_value);
View
59 src/node.js
@@ -41,35 +41,32 @@ node.dns.createConnection = removed("node.dns.createConnection() has moved. Use
// Module
+var internalModuleCache = {};
+
function Module (id, parent) {
this.id = id;
this.exports = {};
this.parent = parent;
+ this.moduleCache = {};
+
+ if (parent) {
+ process.mixin(this.moduleCache, parent.moduleCache);
+ this.moduleCache[parent.id] = parent;
+ }
+
this.filename = null;
this.loaded = false;
this.loadPromise = null;
this.exited = false;
this.children = [];
};
-var moduleCache = {};
-
-function createModule (id, parent) {
- if (id in moduleCache) {
- debug("found " + JSON.stringify(id) + " in cache");
- return moduleCache[id];
- }
- debug("didn't found " + JSON.stringify(id) + " in cache. creating new module");
- var m = new Module(id, parent);
- moduleCache[id] = m;
- return m;
-};
-
function createInternalModule (id, constructor) {
- var m = createModule(id);
+ var m = new Module(id);
constructor(m.exports);
m.loaded = true;
+ internalModuleCache[id] = m;
return m;
};
@@ -803,11 +800,7 @@ function findModulePath (id, dirs, callback) {
searchLocations();
}
-function loadModule (request, parent) {
- // This is the promise which is actually returned from require.async()
- var loadPromise = new events.Promise();
-
- // debug("loadModule REQUEST " + (request) + " parent: " + JSON.stringify(parent));
+function resolveModulePath(request, parent) {
var id, paths;
if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) {
@@ -823,21 +816,33 @@ function loadModule (request, parent) {
paths = process.paths;
}
- if (id in moduleCache) {
+ return [id, paths];
+}
+
+function loadModule (request, parent) {
+ var
+ // The promise returned from require.async()
+ loadPromise = new events.Promise(),
+ resolvedModule = resolveModulePath(request, parent),
+ id = resolvedModule[0],
+ paths = resolvedModule[1];
+
+ // debug("loadModule REQUEST " + (request) + " parent: " + JSON.stringify(parent));
+
+ var cachedModule = internalModuleCache[id] || parent.moduleCache[id];
+ if (cachedModule) {
debug("found " + JSON.stringify(id) + " in cache");
- // In cache
- var module = moduleCache[id];
- process.nextTick(function () {
- loadPromise.emitSuccess(module.exports);
+ process.nextTick(function() {
+ loadPromise.emitSuccess(cachedModule.exports);
});
- } else {
+ } else {
debug("looking for " + JSON.stringify(id) + " in " + JSON.stringify(paths));
// Not in cache
findModulePath(request, paths, function (filename) {
if (!filename) {
loadPromise.emitError(new Error("Cannot find module '" + request + "'"));
} else {
- var module = createModule(id, parent);
+ var module = new Module(id, parent);
module.load(filename, loadPromise);
}
});
@@ -978,7 +983,7 @@ if (process.argv[1].charAt(0) != "/" && !(/^http:\/\//).exec(process.argv[1])) {
}
// Load the main module--the command line argument.
-process.mainModule = createModule(".");
+process.mainModule = new Module(".");
var loadPromise = new events.Promise();
process.mainModule.load(process.argv[1], loadPromise);
View
5 test/mjsunit/fixtures/echo.js
@@ -0,0 +1,5 @@
+process.mixin(require("../common"));
+process.stdio.open();
+process.stdio.addListener("data", function (data) {
+ puts(data);
+});
View
1 test/mjsunit/test-module-loading.js
@@ -41,7 +41,6 @@ assert.notEqual(one.hello, two.hello);
debug("test cycles containing a .. path");
var root = require("./fixtures/cycles/root"),
foo = require("./fixtures/cycles/folder/foo");
-assert.equal(root.foo, foo);
assert.equal(root.sayHello(), root.hello);
var errorThrown = false;
View
15 test/mjsunit/test-readdir.js
@@ -7,9 +7,18 @@ puts("readdir " + fixturesDir);
promise.addCallback(function (files) {
p(files);
- assert.deepEqual(["a.js", "b","cycles", "multipart.js",
- "nested-index","test_ca.pem",
- "test_cert.pem", "test_key.pem", "throws_error.js", "x.txt"], files.sort());
+ assert.deepEqual(['a.js'
+ , 'b'
+ , 'cycles'
+ , 'echo.js'
+ , 'multipart.js'
+ , 'nested-index'
+ , 'test_ca.pem'
+ , 'test_cert.pem'
+ , 'test_key.pem'
+ , 'throws_error.js'
+ , 'x.txt'
+ ], files.sort());
});
promise.addErrback(function () {
View
21 test/mjsunit/test-stdio.js
@@ -0,0 +1,21 @@
+process.mixin(require("./common"));
+
+var sub = path.join(fixturesDir, 'echo.js');
+
+var result = false;
+
+var child = process.createChildProcess(path.join(libDir, "../bin/node"), [sub]);
+child.addListener("error", function (data){
+ puts("parent stderr: " + data);
+});
+child.addListener("output", function (data){
+ if (data && data[0] == 't') {
+ result = true;
+ }
+});
+setTimeout(function () {
+ child.write('t\r\n');
+}, 100);
+setTimeout(function (){
+ assert.ok(result);
+}, 500)

0 comments on commit 493c1d6

Please sign in to comment.
Something went wrong with that request. Please try again.