summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/node.js26
-rw-r--r--test/mjsunit/disabled/test-remote-module-loading.js17
-rw-r--r--test/mjsunit/test-remote-module-loading.js38
3 files changed, 62 insertions, 19 deletions
diff --git a/src/node.js b/src/node.js
index 90f03f81d4..79866b0fc2 100644
--- a/src/node.js
+++ b/src/node.js
@@ -288,6 +288,11 @@ if (process.ENV["NODE_PATH"]) {
function findModulePath (id, dirs, callback) {
process.assert(dirs.constructor == Array);
+ if (/^https?:\/\//.exec(id)) {
+ callback(id);
+ return;
+ }
+
if (/.(js|node)$/.exec(id)) {
throw new Error("No longer accepting filename extension in module names");
}
@@ -402,7 +407,24 @@ Module.prototype.loadObject = function (filename, loadPromise) {
Module.prototype.loadScript = function (filename, loadPromise) {
var self = this;
- var catPromise = process.cat(filename);
+ if (filename.match(/^http:\/\//)) {
+ var catPromise = new process.Promise();
+ loadModule('http', this)
+ .addCallback(function(http) {
+ http.cat(filename)
+ .addCallback(function(content) {
+ catPromise.emitSuccess(content);
+ })
+ .addErrback(function() {
+ catPromise.emitError.apply(null, arguments);
+ });
+ })
+ .addErrback(function() {
+ loadPromise.emitError(new Error("could not load core module \"http\""));
+ });
+ } else {
+ var catPromise = process.cat(filename);
+ }
catPromise.addErrback(function () {
loadPromise.emitError(new Error("Error reading " + filename));
@@ -468,7 +490,7 @@ if (process.ARGV[0].charAt(0) != "/") {
process.ARGV[0] = path.join(cwd, process.ARGV[0]);
}
-if (process.ARGV[1].charAt(0) != "/") {
+if (process.ARGV[1].charAt(0) != "/" && !/^http:\/\//.exec(process.ARGV[1])) {
process.ARGV[1] = path.join(cwd, process.ARGV[1]);
}
diff --git a/test/mjsunit/disabled/test-remote-module-loading.js b/test/mjsunit/disabled/test-remote-module-loading.js
deleted file mode 100644
index 752ec8b27e..0000000000
--- a/test/mjsunit/disabled/test-remote-module-loading.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var s = process.http.createServer(function (req, res) {
- var body = "exports.A = function() { return 'A';}";
- res.sendHeader(200, [
- ["Content-Length", body.length],
- ["Content-Type", "text/plain"]
- ]);
- res.sendBody(body);
- res.finish();
-});
-s.listen(8000);
-
-process.mixin(require("../common.js"));
-var a = require("http://localhost:8000/")
-
-assertInstanceof(a.A, Function);
-assertEquals("A", a.A());
-s.close();
diff --git a/test/mjsunit/test-remote-module-loading.js b/test/mjsunit/test-remote-module-loading.js
new file mode 100644
index 0000000000..7baecffe96
--- /dev/null
+++ b/test/mjsunit/test-remote-module-loading.js
@@ -0,0 +1,38 @@
+process.mixin(require("./common"));
+
+var PORT = 8889;
+var http = require('http');
+var sys = require('sys');
+var modulesLoaded = 0;
+
+var server = http.createServer(function(req, res) {
+ var body = 'exports.httpPath = function() {'+
+ 'return '+JSON.stringify(req.uri.path)+';'+
+ '};';
+
+ res.sendHeader(200, {'Content-Type': 'text/javascript'});
+ res.sendBody(body);
+ res.finish();
+});
+server.listen(PORT);
+
+var httpModule = require('http://localhost:'+PORT+'/moduleA.js');
+assertEquals('/moduleA.js', httpModule.httpPath());
+modulesLoaded++;
+
+var nodeBinary = process.ARGV[0];
+var cmd = nodeBinary+' http://localhost:'+PORT+'/moduleB.js';
+
+sys
+ .exec(cmd)
+ .addCallback(function() {
+ modulesLoaded++;
+ server.close();
+ })
+ .addErrback(function() {
+ assertUnreachable('node binary could not load module from url');
+ });
+
+process.addListener('exit', function() {
+ assertEquals(2, modulesLoaded);
+}); \ No newline at end of file