Browse Source

Module refactor - almost CommonJS compatible now

API change summary:

  * require("/sys.js") becomes require("sys")

  * require("circle.js") becomes require("./circle")

  * process.path.join() becomes require("path").join()
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
7a2e784ad7
  1. 4
      bin/node-repl
  2. 163
      doc/api.txt
  3. 10
      doc/index.html
  4. 2
      lib/file.js
  5. 2
      lib/http.js
  6. 2
      lib/repl.js
  7. 5
      src/file.js
  8. 365
      src/node.js
  9. 53
      src/util.js
  10. 18
      test/mjsunit/common.js
  11. 2
      test/mjsunit/fixtures/a.js
  12. 8
      test/mjsunit/fixtures/b/c.js
  13. 2
      test/mjsunit/fixtures/b/package/index.js
  14. 8
      test/mjsunit/test-buffered-file.js
  15. 4
      test/mjsunit/test-delayed-require.js
  16. 2
      test/mjsunit/test-event-emitter-add-listeners.js
  17. 2
      test/mjsunit/test-exec.js
  18. 4
      test/mjsunit/test-file-cat-noexist.js
  19. 8
      test/mjsunit/test-fs-sendfile.js
  20. 2
      test/mjsunit/test-fs-stat.js
  21. 10
      test/mjsunit/test-fs-write.js
  22. 4
      test/mjsunit/test-http-cat.js
  23. 4
      test/mjsunit/test-http-client-race.js
  24. 4
      test/mjsunit/test-http-client-upload.js
  25. 6
      test/mjsunit/test-http-malformed-request.js
  26. 4
      test/mjsunit/test-http-proxy.js
  27. 6
      test/mjsunit/test-http-server.js
  28. 4
      test/mjsunit/test-http.js
  29. 8
      test/mjsunit/test-mkdir-rmdir.js
  30. 8
      test/mjsunit/test-module-loading.js
  31. 8
      test/mjsunit/test-multipart.js
  32. 2
      test/mjsunit/test-process-buffering.js
  33. 2
      test/mjsunit/test-process-kill.js
  34. 2
      test/mjsunit/test-process-simple.js
  35. 2
      test/mjsunit/test-process-spawn-loop.js
  36. 2
      test/mjsunit/test-promise-timeout.js
  37. 2
      test/mjsunit/test-promise-wait.js
  38. 2
      test/mjsunit/test-readdir.js
  39. 2
      test/mjsunit/test-signal-handler.js
  40. 4
      test/mjsunit/test-tcp-binary.js
  41. 4
      test/mjsunit/test-tcp-many-clients.js
  42. 4
      test/mjsunit/test-tcp-pingpong-delay.js
  43. 4
      test/mjsunit/test-tcp-pingpong.js
  44. 4
      test/mjsunit/test-tcp-reconnect.js
  45. 4
      test/mjsunit/test-tcp-throttle-kernel-buffer.js
  46. 4
      test/mjsunit/test-tcp-throttle.js
  47. 4
      test/mjsunit/test-tcp-timeout.js
  48. 2
      test/mjsunit/test-timers.js
  49. 2
      test/mjsunit/test-utf8-scripts.js
  50. 2
      test/mjsunit/test-wait-ordering.js

4
bin/node-repl

@ -1,11 +1,11 @@
#!/usr/bin/env node #!/usr/bin/env node
process.mixin(require("/utils.js")); process.mixin(require('sys'));
puts("Welcome to the Node.js REPL."); puts("Welcome to the Node.js REPL.");
puts("Enter ECMAScript at the prompt."); puts("Enter ECMAScript at the prompt.");
puts("Tip 1: Use 'rlwrap node-repl' for a better interface"); puts("Tip 1: Use 'rlwrap node-repl' for a better interface");
puts("Tip 2: Type Control-D to exit."); puts("Tip 2: Type Control-D to exit.");
require("/repl.js").start(); require('repl').start();
// vim:ft=javascript // vim:ft=javascript

163
doc/api.txt

@ -16,8 +16,8 @@ An example of a web server written with Node which responds with "Hello
World": World":
---------------------------------------- ----------------------------------------
var sys = require("/sys.js"), var sys = require("sys"),
http = require("/http.js"); http = require("http");
http.createServer(function (request, response) { http.createServer(function (request, response) {
response.sendHeader(200, {"Content-Type": "text/plain"}); response.sendHeader(200, {"Content-Type": "text/plain"});
response.sendBody("Hello World\n"); response.sendBody("Hello World\n");
@ -80,7 +80,7 @@ more information.
A listener on this event should not try to perform A listener on this event should not try to perform
I/O since the process will forcibly exit in less I/O since the process will forcibly exit in less
than microsecond. However, it is a good hook to than microsecond. However, it is a good hook to
perform constant time checks of the module's perform constant time checks of the module"s
state (like for unit tests). state (like for unit tests).
+ +
The parameter +code+ is the integer exit code The parameter +code+ is the integer exit code
@ -126,11 +126,12 @@ copy, recursively copying any objects it finds. Otherwise, the copy will
share structure with the original object(s). share structure with the original object(s).
+ +
Undefined properties are not copied. However, properties inherited from the Undefined properties are not copied. However, properties inherited from the
object's prototype will be copied over. object"s prototype will be copied over.
=== System module === System module
These function are in +"/sys.js"+. Use +require("/sys.js")+ to access them. These function are in the module +"sys"+. Use +require("sys")+ to access
them.
+puts(string)+:: +puts(string)+::
Outputs the +string+ and a trailing new-line to +stdout+. Outputs the +string+ and a trailing new-line to +stdout+.
@ -150,7 +151,7 @@ Executes the command as a child process, buffers the output and returns it
in a promise callback. in a promise callback.
+ +
---------------------------------------- ----------------------------------------
var sys = require("/sys.js"); var sys = require("sys");
sys.exec("ls /").addCallback(function (stdout, stderr) { sys.exec("ls /").addCallback(function (stdout, stderr) {
puts(stdout); puts(stdout);
}); });
@ -235,7 +236,7 @@ Adds a listener for the +"cancel"+ event. Returns the same promise object.
If you created the promise (by doing +new process.Promise()+) then call If you created the promise (by doing +new process.Promise()+) then call
+emitSuccess+ to emit the +"success"+ event with the given arguments. +emitSuccess+ to emit the +"success"+ event with the given arguments.
+ +
(+promise.emit("success", arg1, arg2, ...)+ should also work, but doesn't at (+promise.emit("success", arg1, arg2, ...)+ should also work, but doesn"t at
the moment due to a bug; use +emitSuccess+ instead.) the moment due to a bug; use +emitSuccess+ instead.)
+promise.emitError(arg1, arg2, ...)+ :: +promise.emitError(arg1, arg2, ...)+ ::
@ -261,7 +262,7 @@ To tell apart a timeout from a regular "error" event, use the following test:
+ +
---------------------------------------- ----------------------------------------
promise.addErrback(function(e) { promise.addErrback(function(e) {
if (e instanceof Error && e.message === 'timeout') { if (e instanceof Error && e.message === "timeout") {
// handle timeout // handle timeout
} else { } else {
// handle regular error // handle regular error
@ -286,7 +287,7 @@ If +"error"+ was emitted instead, +wait()+ throws an error.
+ +
*IMPORTANT* +promise.wait()+ is not a true fiber/coroutine. If any other *IMPORTANT* +promise.wait()+ is not a true fiber/coroutine. If any other
promises are created and made to wait while the first promise waits, the promises are created and made to wait while the first promise waits, the
first promise's wait will not return until all others return. The benefit of first promise"s wait will not return until all others return. The benefit of
this is a simple implementation and the event loop does not get blocked. this is a simple implementation and the event loop does not get blocked.
Disadvantage is the possibility of situations where the promise stack grows Disadvantage is the possibility of situations where the promise stack grows
infinitely large because promises keep getting created and keep being told infinitely large because promises keep getting created and keep being told
@ -328,15 +329,17 @@ Close stdin.
=== Modules === Modules
Node uses the CommonJS module system
Node has a simple module loading system. In Node, files and modules are in Node has a simple module loading system. In Node, files and modules are in
one-to-one correspondence. As an example, +foo.js+ loads the module one-to-one correspondence. As an example, +foo.js+ loads the module
+circle.js+. +circle.js+ in the same directory.
The contents of +foo.js+: The contents of +foo.js+:
---------------------------------------- ----------------------------------------
var circle = require("circle.js"), var circle = require("./circle"),
sys = require("/sys.js"); var sys = require("sys");
sys.puts("The area of a circle of radius 4 is " + circle.area(4)); sys.puts("The area of a circle of radius 4 is " + circle.area(4));
---------------------------------------- ----------------------------------------
@ -358,42 +361,56 @@ The module +circle.js+ has exported the functions +area()+ and
+circumference()+. To export an object, add to the special +exports+ +circumference()+. To export an object, add to the special +exports+
object. (Alternatively, one can use +this+ instead of +exports+.) Variables object. (Alternatively, one can use +this+ instead of +exports+.) Variables
local to the module will be private. In this example the variable +PI+ is 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 private to +circle.js+. The function +puts()+ comes from the module +"sys"+,
+"/sys.js"+. which is a built-in module. Modules which are not prefixed by +"./"+ are
built-in module--more about this later.
The module path is relative to the file calling +require()+. That is, A module prefixed with +"./"+ is relative to the file calling +require()+.
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to That is, +circle.js+ must be in the same directory as +foo.js+ for
find it. +require("./circle")+ to find it.
Use +process.mixin()+ to include modules into the global namespace. Without the leading +"./"+, like +require("mjsunit")+ the module is searched
for in the +require.paths+ array. +require.paths+ on my system looks like
---------------------------------------- this:
process.mixin(process, require("circle.js"), require("/sys.js"));
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------
When an absolute path is given to +require()+, like
+require("/mjsunit.js")+ the module is searched for in the
+require.paths+ array. +require.paths+ on my system looks like this:
---------------------------------------- ----------------------------------------
[ "/home/ryan/.node_libraries" [ "/home/ryan/.node_libraries"
, "/home/ryan/local/node/lib/node_libraries" , "/usr/local/lib/node/libraries"
, "/"
] ]
---------------------------------------- ----------------------------------------
That is, first Node looks for +"/home/ryan/.node_libraries/mjsunit.js"+ and That is, when +require("mjsunit")+ is called Node looks for
then for +"/home/ryan/local/node/lib/node_libraries/mjsunit.js"+. If not
found, it finally looks for +"/mjsunit.js"+ (in the root directory). 1. +"/home/ryan/.node_libraries/mjsunit.js"+
2. +"/home/ryan/.node_libraries/mjsunit.node"+
3. +"/home/ryan/.node_libraries/mjsunit/index.js"+
4. +"/home/ryan/.node_libraries/mjsunit/index.node"+
5. +"/usr/local/lib/node/libraries/mjsunit.js"+
6. +"/usr/local/lib/node/libraries/mjsunit.node"+
7. +"/usr/local/lib/node/libraries/mjsunit/index.js"+
8. +"/usr/local/lib/node/libraries/mjsunit/index.node"+
interrupting once a file is found. Files ending in +".node"+ are binary Addon
Modules; see the section below about addons. +"index.js"+ allows one to
package a module as a directory.
+require.paths+ can be modified at runtime by simply unshifting new +require.paths+ can be modified at runtime by simply unshifting new
paths on to it and at startup with the +NODE_LIBRARY_PATHS+ environmental paths on to it and at startup with the +NODE_PATH+ environmental
variable (which should be a list of paths, colon separated). variable (which should be a list of paths, colon separated).
Node comes with several libraries which are installed when +"make install"+ Use +process.mixin()+ to include modules into the global namespace.
is run. These are currently undocumented, but do look them up in your
system. ----------------------------------------
process.mixin(GLOBAL, require("./circle"), require("sys"));
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------
@ -422,7 +439,7 @@ Stops a interval from triggering.
=== Child Processes === Child Processes
Node provides a tridirectional +popen(3)+ facility through the class Node provides a tridirectional +popen(3)+ facility through the class
+process.ChildProcess+. It is possible to stream data through the child's +stdin+, +process.ChildProcess+. It is possible to stream data through the child"s +stdin+,
+stdout+, and +stderr+ in a fully non-blocking way. +stdout+, and +stderr+ in a fully non-blocking way.
==== +process.ChildProcess+ ==== +process.ChildProcess+
@ -468,13 +485,13 @@ The PID of the child process.
+child.write(data, encoding="ascii")+ :: +child.write(data, encoding="ascii")+ ::
Write data to the child process's +stdin+. The second argument is optional and Write data to the child process"s +stdin+. The second argument is optional and
specifies the encoding: possible values are +"utf8"+, +"ascii"+, and specifies the encoding: possible values are +"utf8"+, +"ascii"+, and
+"binary"+. +"binary"+.
+child.close()+ :: +child.close()+ ::
Closes the process's +stdin+ stream. Closes the process"s +stdin+ stream.
+child.kill(signal="SIGTERM")+ :: +child.kill(signal="SIGTERM")+ ::
@ -486,14 +503,14 @@ will be sent +"SIGTERM"+. See signal(7) for a list of available signals.
=== POSIX module === POSIX module
File I/O is provided by simple wrappers around standard POSIX functions. To File I/O is provided by simple wrappers around standard POSIX functions. To
use this module do +require("/posix.js")+. use this module do +require("posix")+.
All POSIX wrappers have a similar form. They return a promise All POSIX wrappers have a similar form. They return a promise
(+process.Promise+). Example of deleting a file: (+process.Promise+). Example of deleting a file:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
var posix = require("/posix.js"), var posix = require("posix"),
sys = require("/sys.js"); sys = require("sys");
var promise = posix.unlink("/tmp/hello"); var promise = posix.unlink("/tmp/hello");
@ -638,7 +655,7 @@ Objects returned from +posix.stat()+ are of this type.
=== HTTP === HTTP
To use the HTTP server and client one must +require("/http.js")+. To use the HTTP server and client one must +require("http")+.
The HTTP interfaces in Node are designed to support many features The HTTP interfaces in Node are designed to support many features
of the protocol which have been traditionally difficult to use. of the protocol which have been traditionally difficult to use.
@ -656,7 +673,7 @@ HTTP message headers are represented by an object like this
} }
---------------------------------------- ----------------------------------------
In order to support the full spectrum of possible HTTP applications, Node's In order to support the full spectrum of possible HTTP applications, Node"s
HTTP API is very low-level. It deals with connection handling and message HTTP API is very low-level. It deals with connection handling and message
parsing only. It parses a message into headers and body but it does not parsing only. It parses a message into headers and body but it does not
parse the actual headers or the body. parse the actual headers or the body.
@ -819,7 +836,7 @@ higher-level multi-part body encodings that may be used.
+ +
The first time +sendBody+ is called, it will send the buffered header The first time +sendBody+ is called, it will send the buffered header
information and the first body to the client. The second time information and the first body to the client. The second time
+sendBody+ is called, Node assumes you're going to be streaming data, and +sendBody+ is called, Node assumes you"re going to be streaming data, and
sends that seperately. That is, the response is buffered up to the sends that seperately. That is, the response is buffered up to the
first chunk of body. first chunk of body.
@ -1003,13 +1020,13 @@ After emitted no other events will be emitted on the response.
=== Multipart Parsing === Multipart Parsing
A library to parse HTTP requests with +multipart/form-data+ is included with A library to parse HTTP requests with +multipart/form-data+ is included with
Node. To use it, +require("/multipart.js")+. Node. To use it, +require("multipart")+.
+multipart.parse(options)+ :: +multipart.parse(options)+ ::
- on success: Returns an object where each key holds the value of one part of - on success: Returns an object where each key holds the value of one part of
the stream. +options+ can either be an instance of the stream. +options+ can either be an instance of
+http.ServerRequest+ or an object containing a 'boundary' and a +http.ServerRequest+ or an object containing a "boundary" and a
'data' key. "data" key.
- on error: no parameters. - on error: no parameters.
==== +multipart.Stream+ ==== +multipart.Stream+
@ -1017,24 +1034,24 @@ Node. To use it, +require("/multipart.js")+.
Here is an example for parsing a +multipart/form-data+ request: Here is an example for parsing a +multipart/form-data+ request:
---------------------------------------- ----------------------------------------
var multipart = require('/multipart.js'); var multipart = require("multipart");
var stream = new multipart.Stream(options); var stream = new multipart.Stream(options);
var parts = {}; var parts = {};
stream.addListener('part', function (part) { stream.addListener("part", function (part) {
var name = part.headers['Content-Disposition'].name; var name = part.headers["Content-Disposition"].name;
var buffer = ''; var buffer = "";
part.addListener('body', function(chunk) { part.addListener("body", function(chunk) {
buffer = buffer + chunk; buffer = buffer + chunk;
}); });
part.addListener('complete', function() { part.addListener("complete", function() {
parts[name] = buffer; parts[name] = buffer;
}); });
}); });
stream.addListener('complete', function() { stream.addListener("complete", function() {
// The parts object now contains all parts and data // The parts object now contains all parts and data
}); });
---------------------------------------- ----------------------------------------
@ -1060,7 +1077,7 @@ stream.addListener('complete', function() {
=== TCP === TCP
To use the TCP server and client one must +require("/tcp.js")+. To use the TCP server and client one must +require("tcp")+.
==== +tcp.Server+ ==== +tcp.Server+
@ -1068,7 +1085,7 @@ Here is an example of a echo server which listens for connections
on port 7000 on port 7000
---------------------------------------- ----------------------------------------
var tcp = require("/tcp.js"); var tcp = require("tcp");
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
@ -1222,13 +1239,13 @@ immediately fire off data each time +connection.send()+ is called.
=== DNS module === DNS module
Use +require("/dns.js")+ to access this module Use +require("dns")+ to access this module
Here is an example of which resolves +"www.google.com"+ then reverse Here is an example of which resolves +"www.google.com"+ then reverse
resolves the IP addresses which are returned. resolves the IP addresses which are returned.
------------------------------------------------------------------------- -------------------------------------------------------------------------
var dns = require("/dns.js"); var dns = require("dns");
var resolution = dns.resolve4("www.google.com"); var resolution = dns.resolve4("www.google.com");
@ -1298,7 +1315,7 @@ A Read-Eval-Print-Loop is available both as a standalone program and easily
includable in other programs. includable in other programs.
The standalone REPL is called +node-repl+ and is installed at The standalone REPL is called +node-repl+ and is installed at
+$PREFIX/bin/node-repl+. It's recommended to use it with the program +$PREFIX/bin/node-repl+. It"s recommended to use it with the program
+rlwrap+ for a better user interface. I set +rlwrap+ for a better user interface. I set
------------------------------------ ------------------------------------
alias node-repl="rlwrap node-repl" alias node-repl="rlwrap node-repl"
@ -1310,9 +1327,9 @@ result of the last expression.
The library is called +/repl.js+ and it can be used like this: The library is called +/repl.js+ and it can be used like this:
------------------------------------ ------------------------------------
var sys = require("/sys.js"), var sys = require("sys"),
tcp = require("/tcp.js"), tcp = require("tcp"),
repl = require("/repl.js"); repl = require("repl");
nconnections = 0; nconnections = 0;
tcp.createServer(function (c) { tcp.createServer(function (c) {
sys.error("Connection!"); sys.error("Connection!");
@ -1351,10 +1368,10 @@ knowledge of several libraries:
- Others. Look in +deps/+ for what else is available. - Others. Look in +deps/+ for what else is available.
Node statically compiles all its dependencies into the executable. When Node statically compiles all its dependencies into the executable. When
compiling your module, you don't need to worry about linking to any of these compiling your module, you don"t need to worry about linking to any of these
libraries. libraries.
To get started let's make a small Addon which does the following except in To get started let"s make a small Addon which does the following except in
C++: C++:
----------------------------------------------------- -----------------------------------------------------
exports.hello = "world"; exports.hello = "world";
@ -1378,20 +1395,20 @@ This source code needs to be built into +hello.node+, the binary Addon. To
do this we create a file called +wscript+ which is python code and looks do this we create a file called +wscript+ which is python code and looks
like this: like this:
----------------------------------------------------- -----------------------------------------------------
srcdir = '.' srcdir = "."
blddir = 'build' blddir = "build"
VERSION = '0.0.1' VERSION = "0.0.1"
def set_options(opt): def set_options(opt):
opt.tool_options('compiler_cxx') opt.tool_options("compiler_cxx")
def configure(conf): def configure(conf):
conf.check_tool('compiler_cxx') conf.check_tool("compiler_cxx")
conf.check_tool('node_addon') conf.check_tool("node_addon")
def build(bld): def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon') obj = bld.new_task_gen("cxx", "shlib", "node_addon")
obj.target = 'hello' obj.target = "hello"
obj.source = "hello.cc" obj.source = "hello.cc"
----------------------------------------------------- -----------------------------------------------------
Running +node-waf configure build+ will create a file Running +node-waf configure build+ will create a file

10
doc/index.html

@ -42,16 +42,16 @@
</p> </p>
<pre> <pre>
var sys = require("/sys.js"), var sys = require('sys'),
http = require("/http.js"); http = require('http');
http.createServer(function (req, res) { http.createServer(function (req, res) {
setTimeout(function () { setTimeout(function () {
res.sendHeader(200, {"Content-Type": "text/plain"}); res.sendHeader(200, {'Content-Type': 'text/plain'});
res.sendBody("Hello World"); res.sendBody('Hello World');
res.finish(); res.finish();
}, 2000); }, 2000);
}).listen(8000); }).listen(8000);
sys.puts("Server running at http://127.0.0.1:8000/");</pre> sys.puts('Server running at http://127.0.0.1:8000/');</pre>
</pre> </pre>
<p> <p>

2
lib/file.js

@ -1,4 +1,4 @@
var posix = require("/posix.js"); var posix = require("./posix");
/*jslint onevar: true, undef: true, eqeqeq: true, plusplus: true, regexp: true, newcap: true, immed: true */ /*jslint onevar: true, undef: true, eqeqeq: true, plusplus: true, regexp: true, newcap: true, immed: true */
/*globals exports, node, __filename */ /*globals exports, node, __filename */

2
lib/http.js

@ -1,4 +1,4 @@
var sys = require("/sys.js"); var sys = require('sys');
var CRLF = "\r\n"; var CRLF = "\r\n";
var STATUS_CODES = { var STATUS_CODES = {

2
lib/repl.js

@ -1,7 +1,7 @@
// A repl library that you can include in your own code to get a runtime // A repl library that you can include in your own code to get a runtime
// interface to your program. Just require("/repl.js"). // interface to your program. Just require("/repl.js").
var sys = require("/sys.js"); var sys = require('sys');
sys.puts("Type '.help' for options."); sys.puts("Type '.help' for options.");

5
src/file.js

@ -1,8 +1,3 @@
process.fs.exists = function (path, callback) {
var p = process.fs.stat(path);
p.addCallback(function () { callback(true); });
p.addErrback(function () { callback(false); });
};
process.fs.cat = function (path, encoding) { process.fs.cat = function (path, encoding) {
var promise = new process.Promise(); var promise = new process.Promise();

365
src/node.js

@ -1,26 +1,37 @@
process.tcp.createServer = function () { (function () { // annonymous namespace
throw new Error("process.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
};
process.createProcess = function () { // deprecation errors
throw "process.createProcess() has been changed to process.createChildProcess() update your code";
GLOBAL.include = function () {
throw new Error("include() has been removed. Use process.mixin(process, require(file)) to get the same effect.");
}; };
process.createChildProcess = function (file, args, env) { GLOBAL.puts = function () {
var child = new process.ChildProcess(); throw new Error("puts() has moved. Use require('/sys.js') to bring it back.");
args = args || [];
env = env || process.ENV;
var envPairs = [];
for (var key in env) {
if (env.hasOwnProperty(key)) {
envPairs.push(key + "=" + env[key]);
} }
GLOBAL.print = function () {
throw new Error("print() has moved. Use require('/sys.js') to bring it back.");
} }
// TODO Note envPairs is not currently used in child_process.cc. The PATH
// needs to be searched for the 'file' command if 'file' does not contain GLOBAL.p = function () {
// a '/' character. throw new Error("p() has moved. Use require('/sys.js') to bring it back.");
child.spawn(file, args, envPairs); }
return child;
process.debug = function () {
throw new Error("process.debug() has moved. Use require('/sys.js') to bring it back.");
}
process.error = function () {
throw new Error("process.error() has moved. Use require('/sys.js') to bring it back.");
}
process.tcp.createServer = function () {
throw new Error("process.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
};
process.createProcess = function () {
throw new Error("process.createProcess() has been changed to process.createChildProcess() update your code");
}; };
process.exec = function () { process.exec = function () {
@ -39,15 +50,30 @@ process.tcp.createConnection = function (port, host) {
throw new Error("process.tcp.createConnection() has moved. Use require('/tcp.js') to access it."); throw new Error("process.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
}; };
include = function () {
throw new Error("include() has been removed. Use process.mixin(process, require(file)) to get the same effect.");
process.createChildProcess = function (file, args, env) {
var child = new process.ChildProcess();
args = args || [];
env = env || process.ENV;
var envPairs = [];
for (var key in env) {
if (env.hasOwnProperty(key)) {
envPairs.push(key + "=" + env[key]);
}
} }
// TODO Note envPairs is not currently used in child_process.cc. The PATH
// needs to be searched for the 'file' command if 'file' does not contain
// a '/' character.
child.spawn(file, args, envPairs);
return child;
};
/* From jQuery.extend in the jQuery JavaScript Library v1.3.2 // From jQuery.extend in the jQuery JavaScript Library v1.3.2
* Copyright (c) 2009 John Resig // Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses. // Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License // http://docs.jquery.com/License
*/
process.mixin = function() { process.mixin = function() {
// copy reference to target object // copy reference to target object
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
@ -98,9 +124,9 @@ process.mixin = function() {
return target; return target;
}; };
// Signal Handlers
(function () { // anonymous namespace
// Signal Handlers
function isSignal (event) { function isSignal (event) {
return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event); return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
@ -115,171 +141,261 @@ process.mixin = function() {
} }
}); });
})(); // anonymous namespace
// Timers // Timers
function setTimeout (callback, after) { GLOBAL.setTimeout = function (callback, after) {
var timer = new process.Timer(); var timer = new process.Timer();
timer.addListener("timeout", callback); timer.addListener("timeout", callback);
timer.start(after, 0); timer.start(after, 0);
return timer; return timer;
} }
function setInterval (callback, repeat) { GLOBAL.setInterval = function (callback, repeat) {
var timer = new process.Timer(); var timer = new process.Timer();
timer.addListener("timeout", callback); timer.addListener("timeout", callback);
timer.start(repeat, repeat); timer.start(repeat, repeat);
return timer; return timer;
} }
function clearTimeout (timer) { GLOBAL.clearTimeout = function (timer) {
timer.stop(); timer.stop();
} }
clearInterval = clearTimeout; GLOBAL.clearInterval = GLOBAL.clearTimeout;
// Module
process.libraryPaths = [ process.path.join(process.ENV["HOME"], ".node_libraries")
, process.path.join(process.installPrefix, "lib/node/libraries")
, "/"
];
if (process.ENV["NODE_LIBRARY_PATHS"]) {
process.libraryPaths = // Modules
process.ENV["NODE_LIBRARY_PATHS"].split(":").concat(process.libraryPaths);
var debugLevel = 0;
if ("NODE_DEBUG" in process.ENV) debugLevel = 1;
function debug (x) {
if (debugLevel > 0) {
process.stdio.writeError(x + "\n");
}
} }
process.Module = function (filename, parent) {
process.assert(filename.charAt(0) == "/"); // private constructor
this.filename = filename; function Module (name, parent) {
this.name = name;
this.exports = {}; this.exports = {};
this.parent = parent; this.parent = parent;
this.filename = null;
this.loaded = false; this.loaded = false;
this.loadPromise = null; this.loadPromise = null;
this.exited = false; this.exited = false;
this.children = []; this.children = [];
}; };
process.Module.cache = {}; var moduleCache = {};
(function () { function createModule (name, parent) {
function retrieveFromCache (loadPromise, fullPath, parent) { if (name in moduleCache) {
var module; debug("found " + JSON.stringify(name) + " in cache");
if (fullPath in process.Module.cache) { return moduleCache[name];
module = process.Module.cache[fullPath]; }
setTimeout(function () { debug("didn't found " + JSON.stringify(name) + " in cache. creating new module");
loadPromise.emitSuccess(module.exports); var m = new Module(name, parent);
}, 0); moduleCache[name] = m;
return m;
};
function createInternalModule (name, constructor) {
var m = createModule(name);
constructor(m.exports);
m.loaded = true;
return m;
};
var pathModule = createInternalModule("path", function (exports) {
exports.join = function () {
var joined = "";
for (var i = 0; i < arguments.length; i++) {
var part = arguments[i].toString();
/* Some logic to shorten paths */
if (part === ".") continue;
while (/^\.\//.exec(part)) part = part.replace(/^\.\//, "");
if (i === 0) {
part = part.replace(/\/*$/, "/");
} else if (i === arguments.length - 1) {
part = part.replace(/^\/*/, "");
} else { } else {
module = new process.Module(fullPath, parent); part = part.replace(/^\/*/, "").replace(/\/*$/, "/");
process.Module.cache[fullPath] = module; }
module.load(loadPromise); joined += part;
}
return joined;
};
exports.dirname = function (path) {
if (path.charAt(0) !== "/") path = "./" + path;
var parts = path.split("/");
return parts.slice(0, parts.length-1).join("/");
};
exports.filename = function (path) {
if (path.charAt(0) !== "/") path = "./" + path;
var parts = path.split("/");
return parts[parts.length-1];
};
exports.exists = function (path, callback) {
var p = process.fs.stat(path);
p.addCallback(function () { callback(true); });
p.addErrback(function () { callback(false); });
};
});
var path = pathModule.exports;
var modulePaths = [ path.join(process.installPrefix, "lib/node/libraries")
];
if (process.ENV["HOME"]) {
modulePaths.unshift(path.join(process.ENV["HOME"], ".node_libraries"));
} }
if (process.ENV["NODE_PATH"]) {
modulePaths = process.ENV["NODE_PATH"].split(":").concat(modulePaths);
} }
function findPath (path, dirs, callback) {
process.assert(path.charAt(0) == "/"); function findModulePath (name, dirs, callback) {
process.assert(dirs.constructor == Array); process.assert(dirs.constructor == Array);
if (/.(js|node)$/.exec(name)) {
throw new Error("No longer accepting filename extension in module names");
}
if (dirs.length == 0) { if (dirs.length == 0) {
callback(); callback();
} else { return;
}
var dir = dirs[0]; var dir = dirs[0];
var rest = dirs.slice(1, dirs.length); var rest = dirs.slice(1, dirs.length);
var fullPath = process.path.join(dir, path); var js = path.join(dir, name + ".js");
process.fs.exists(fullPath, function (doesExist) { var addon = path.join(dir, name + ".node");
if (doesExist) { var indexJs = path.join(dir, name, "index.js");
callback(fullPath); var indexAddon = path.join(dir, name, "index.addon");
} else {
findPath(path, rest, callback); // TODO clean up the following atrocity!
path.exists(js, function (found) {
if (found) {
callback(js);
return;
} }
}); path.exists(addon, function (found) {
if (found) {
callback(addon);
return;
} }
path.exists(indexJs, function (found) {
if (found) {
callback(indexJs);
return;
} }
path.exists(indexAddon, function (found) {
process.loadModule = function (requestedPath, exports, parent) { if (found) {
var loadPromise = new process.Promise(); callback(indexAddon);
return;
// On success copy the loaded properties into the exports
loadPromise.addCallback(function (t) {
for (var prop in t) {
if (t.hasOwnProperty(prop)) exports[prop] = t[prop];
} }
findModulePath(name, rest, callback);
});
});
});
}); });
}
function loadModule (request, parent) {
// This is the promise which is actually returned from require.async()
var loadPromise = new process.Promise();
loadPromise.addErrback(function (e) { loadPromise.addErrback(function (e) {
process.stdio.writeError(e.message + "\n"); process.stdio.writeError(e.message + "\n");
process.exit(1); process.exit(1);
}); });
if (!parent) { debug("loadModule REQUEST " + JSON.stringify(request) + " parent: " + JSON.stringify(parent));
// root module
process.assert(requestedPath.charAt(0) == "/");
retrieveFromCache(loadPromise, requestedPath);
var name, paths;
if (request.charAt(0) == "." && request.charAt(1) == "/") {
// Relative request
name = path.join(path.dirname(parent.name), request);
paths = [path.dirname(parent.filename)];
} else { } else {
if (requestedPath.charAt(0) == "/") { name = request;
// Need to find the module in process.libraryPaths paths = modulePaths;
findPath(requestedPath, process.libraryPaths, function (fullPath) {
if (fullPath) {
retrieveFromCache(loadPromise, fullPath, parent);
} else {
loadPromise.emitError(new Error("Cannot find module '" + requestedPath + "'"));
} }
});
if (name in moduleCache) {
debug("found " + JSON.stringify(name) + " in cache");
// In cache
var module = moduleCache[name];
setTimeout(function () {
loadPromise.emitSuccess(module.exports);
}, 0);
} else { } else {
// Relative file load debug("looking for " + JSON.stringify(name) + " in " + JSON.stringify(paths));
var fullPath = process.path.join(process.path.dirname(parent.filename), // Not in cache
requestedPath); findModulePath(request, paths, function (filename) {
retrieveFromCache(loadPromise, fullPath, parent); if (!filename) {
loadPromise.emitError(new Error("Cannot find module '" + request + "'"));
} else {
var module = createModule(name, parent);
module.load(filename, loadPromise);
} }
});
} }
return loadPromise; return loadPromise;
}; };
}());
process.Module.prototype.load = function (loadPromise) { Module.prototype.load = function (filename, loadPromise) {
if (this.loaded) { debug("load " + JSON.stringify(filename) + " for module " + JSON.stringify(this.name));
loadPromise.emitError(new Error("Module '" + self.filename + "' is already loaded."));
return; process.assert(!this.loaded);
} process.assert(!this.loadPromise);
process.assert(!process.loadPromise);
this.loadPromise = loadPromise; this.loadPromise = loadPromise;
this.filename = filename;
if (this.filename.match(/\.node$/)) { if (filename.match(/\.node$/)) {
this.loadObject(loadPromise); this.loadObject(filename, loadPromise);
} else { } else {
this.loadScript(loadPromise); this.loadScript(filename, loadPromise);
} }
}; };
process.Module.prototype.loadObject = function (loadPromise) { Module.prototype.loadObject = function (filename, loadPromise) {
var self = this; var self = this;
// XXX Not yet supporting loading from HTTP. would need to download the // XXX Not yet supporting loading from HTTP. would need to download the
// file, store it to tmp then run dlopen on it. // file, store it to tmp then run dlopen on it.
process.fs.exists(self.filename, function (does_exist) { setTimeout(function () {
if (does_exist) {
self.loaded = true; self.loaded = true;
process.dlopen(self.filename, self.exports); // FIXME synchronus process.dlopen(filename, self.exports); // FIXME synchronus
loadPromise.emitSuccess(self.exports); loadPromise.emitSuccess(self.exports);
} else { }, 0);
loadPromise.emitError(new Error("Error reading " + self.filename));
}
});
}; };
process.Module.prototype.loadScript = function (loadPromise) { Module.prototype.loadScript = function (filename, loadPromise) {
var self = this; var self = this;
var catPromise = process.cat(self.filename); var catPromise = process.cat(filename);
catPromise.addErrback(function () { catPromise.addErrback(function () {
loadPromise.emitError(new Error("Error reading " + self.filename)); loadPromise.emitError(new Error("Error reading " + filename));
}); });
catPromise.addCallback(function (content) { catPromise.addCallback(function (content) {
@ -287,23 +403,23 @@ process.Module.prototype.loadScript = function (loadPromise) {
content = content.replace(/^\#\!.*/, ''); content = content.replace(/^\#\!.*/, '');
function requireAsync (url) { function requireAsync (url) {
return self.newChild(url); return loadModule(url, self); // new child
} }
function require (url) { function require (url) {
return requireAsync(url).wait(); return requireAsync(url).wait();
} }
require.paths = process.libraryPaths; require.paths = modulePaths;
require.async = requireAsync; require.async = requireAsync;
// create wrapper function // create wrapper function
var wrapper = "var __wrap__ = function (__module, __filename, exports, require) { " var wrapper = "var __wrap__ = function (exports, require, module, __filename) { "
+ content + content
+ "\n}; __wrap__;"; + "\n}; __wrap__;";
var compiled_wrapper = process.compile(wrapper, self.filename); var compiledWrapper = process.compile(wrapper, filename);
compiled_wrapper.apply(self.exports, [self, self.filename, self.exports, require]); compiledWrapper.apply(self.exports, [self.exports, require, self, filename]);
self.waitChildrenLoad(function () { self.waitChildrenLoad(function () {
self.loaded = true; self.loaded = true;
@ -312,11 +428,7 @@ process.Module.prototype.loadScript = function (loadPromise) {
}); });
}; };
process.Module.prototype.newChild = function (path) { Module.prototype.waitChildrenLoad = function (callback) {
return process.loadModule(path, {}, this);
};
process.Module.prototype.waitChildrenLoad = function (callback) {
var nloaded = 0; var nloaded = 0;
var children = this.children; var children = this.children;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
@ -339,18 +451,21 @@ process.exit = function (code) {
process.reallyExit(code); process.reallyExit(code);
}; };
(function () {
var cwd = process.cwd(); var cwd = process.cwd();
// Make process.ARGV[0] and process.ARGV[1] into full paths. // Make process.ARGV[0] and process.ARGV[1] into full paths.
if (process.ARGV[0].charAt(0) != "/") { if (process.ARGV[0].charAt(0) != "/") {
process.ARGV[0] = process.path.join(cwd, process.ARGV[0]); process.ARGV[0] = path.join(cwd, process.ARGV[0]);
} }
if (process.ARGV[1].charAt(0) != "/") { if (process.ARGV[1].charAt(0) != "/") {
process.ARGV[1] = process.path.join(cwd, process.ARGV[1]); process.ARGV[1] = path.join(cwd, process.ARGV[1]);
} }
// Load the root module--the command line argument. // Load the root module--the command line argument.
process.loadModule(process.ARGV[1], process); var m = createModule(".");
}()); var loadPromise = new process.Promise();
m.load(process.ARGV[1], loadPromise);
loadPromise.wait();
}()); // end annonymous namespace

53
src/util.js

@ -33,58 +33,5 @@ process.cat = function(location, encoding) {
return process.fs.cat(location, encoding); return process.fs.cat(location, encoding);
}; };
process.path = new function () {
this.join = function () {
var joined = "";
for (var i = 0; i < arguments.length; i++) {
var part = arguments[i].toString();
/* Some logic to shorten paths */
if (part === ".") continue;
while (/^\.\//.exec(part)) part = part.replace(/^\.\//, "");
if (i === 0) {
part = part.replace(/\/*$/, "/");
} else if (i === arguments.length - 1) {
part = part.replace(/^\/*/, "");
} else {
part = part.replace(/^\/*/, "").replace(/\/*$/, "/");
}
joined += part;
}
return joined;
};
this.dirname = function (path) {
if (path.charAt(0) !== "/") path = "./" + path;
var parts = path.split("/");
return parts.slice(0, parts.length-1).join("/");
};
this.filename = function (path) {
if (path.charAt(0) !== "/") path = "./" + path;
var parts = path.split("/");
return parts[parts.length-1];
};
};
puts = function () {
throw new Error("puts() has moved. Use require('/sys.js') to bring it back.");
}
print = function () {
throw new Error("print() has moved. Use require('/sys.js') to bring it back.");
}
p = function () {
throw new Error("p() has moved. Use require('/sys.js') to bring it back.");
}
process.debug = function () {
throw new Error("process.debug() has moved. Use require('/sys.js') to bring it back.");
}
process.error = function () {
throw new Error("process.error() has moved. Use require('/sys.js') to bring it back.");
}

18
test/mjsunit/common.js

@ -1,11 +1,15 @@
exports.testDir = process.path.dirname(__filename); var path = require("path");
exports.fixturesDir = process.path.join(exports.testDir, "fixtures");
exports.libDir = process.path.join(exports.testDir, "../../lib"); exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, "fixtures");
exports.libDir = path.join(exports.testDir, "../../lib");
require.paths.unshift(exports.libDir); require.paths.unshift(exports.libDir);
var mjsunit = require("/mjsunit.js"); var mjsunit = require("mjsunit");
var utils = require("/utils.js"); var sys = require("sys");
process.mixin(exports, mjsunit, utils);
exports.posix = require("/posix.js"); process.mixin(exports, mjsunit, sys);
exports.posix = require("posix");
exports.path = path;

2
test/mjsunit/fixtures/a.js

@ -1,4 +1,4 @@
var c = require("b/c.js"); var c = require("./b/c");
debug("load fixtures/a.js"); debug("load fixtures/a.js");

8
test/mjsunit/fixtures/b/c.js

@ -1,4 +1,10 @@
var d = require("d.js"); var d = require("./d");
var mjsunit = require("mjsunit");
var package = require("./package");
mjsunit.assertEquals("world", package.hello);
debug("load fixtures/b/c.js"); debug("load fixtures/b/c.js");

2
test/mjsunit/fixtures/b/package/index.js

@ -0,0 +1,2 @@
exports.hello = "world";
debug("load package/index.js");

8
test/mjsunit/test-buffered-file.js

@ -1,10 +1,10 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var testTxt = process.path.join(fixturesDir, "test.txt"); var testTxt = path.join(fixturesDir, "test.txt");
var libDir = process.path.join(testDir, "../../lib"); var libDir = path.join(testDir, "../../lib");
require.paths.unshift(libDir); require.paths.unshift(libDir);
process.mixin(require("/file.js")); process.mixin(require("file"));
var fileUnlinked = false; var fileUnlinked = false;

4
test/mjsunit/test-delayed-require.js

@ -1,7 +1,7 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
setTimeout(function () { setTimeout(function () {
a = require("fixtures/a.js"); a = require("./fixtures/a");
}, 50); }, 50);
process.addListener("exit", function () { process.addListener("exit", function () {

2
test/mjsunit/test-event-emitter-add-listeners.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var e = new process.EventEmitter(); var e = new process.EventEmitter();

2
test/mjsunit/test-exec.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
success_count = 0; success_count = 0;
error_count = 0; error_count = 0;

4
test/mjsunit/test-file-cat-noexist.js

@ -1,7 +1,7 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var got_error = false; var got_error = false;
var filename = process.path.join(fixturesDir, "does_not_exist.txt"); var filename = path.join(fixturesDir, "does_not_exist.txt");
var promise = posix.cat(filename, "raw"); var promise = posix.cat(filename, "raw");
promise.addCallback(function (content) { promise.addCallback(function (content) {

8
test/mjsunit/test-fs-sendfile.js

@ -1,9 +1,9 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
sys = require("/sys.js"); sys = require("sys");
PORT = 23123; PORT = 23123;
var x = process.path.join(fixturesDir, "x.txt"); var x = path.join(fixturesDir, "x.txt");
var expected = "xyz"; var expected = "xyz";
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {

2
test/mjsunit/test-fs-stat.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var got_error = false; var got_error = false;
var success_count = 0; var success_count = 0;

10
test/mjsunit/test-fs-write.js

@ -1,15 +1,15 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var path = process.path.join(fixturesDir, "write.txt"); var fn = path.join(fixturesDir, "write.txt");
var expected = "hello"; var expected = "hello";
var found; var found;
posix.open(path, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).addCallback(function (file) { posix.open(fn, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).addCallback(function (file) {
posix.write(file, expected, 0, "utf8").addCallback(function() { posix.write(file, expected, 0, "utf8").addCallback(function() {
posix.close(file).addCallback(function() { posix.close(file).addCallback(function() {
posix.cat(path, process.UTF8).addCallback(function(contents) { posix.cat(fn, process.UTF8).addCallback(function(contents) {
found = contents; found = contents;
posix.unlink(path).wait(); posix.unlink(fn).wait();
}); });
}); });
}); });

4
test/mjsunit/test-http-cat.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
PORT = 8888; PORT = 8888;
var body = "exports.A = function() { return 'A';}"; var body = "exports.A = function() { return 'A';}";

4
test/mjsunit/test-http-client-race.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
PORT = 8888; PORT = 8888;
var body1_s = "1111111111111111"; var body1_s = "1111111111111111";

4
test/mjsunit/test-http-client-upload.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
var PORT = 18032; var PORT = 18032;
var sent_body = ""; var sent_body = "";

6
test/mjsunit/test-http-malformed-request.js

@ -1,6 +1,6 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
http = require("/http.js"); http = require("http");
// Make sure no exceptions are thrown when receiving malformed HTTP // Make sure no exceptions are thrown when receiving malformed HTTP
// requests. // requests.

4
test/mjsunit/test-http-proxy.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
var PROXY_PORT = 8869; var PROXY_PORT = 8869;
var BACKEND_PORT = 8870; var BACKEND_PORT = 8870;

6
test/mjsunit/test-http-server.js

@ -1,6 +1,6 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
http = require("/http.js"); http = require("http");
var port = 8222; var port = 8222;

4
test/mjsunit/test-http.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
PORT = 8888; PORT = 8888;
var responses_sent = 0; var responses_sent = 0;

8
test/mjsunit/test-mkdir-rmdir.js

@ -1,8 +1,8 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var dirname = process.path.dirname(__filename); var dirname = path.dirname(__filename);
var fixtures = process.path.join(dirname, "fixtures"); var fixtures = path.join(dirname, "fixtures");
var d = process.path.join(fixtures, "dir"); var d = path.join(fixtures, "dir");
var mkdir_error = false; var mkdir_error = false;
var rmdir_error = false; var rmdir_error = false;

8
test/mjsunit/test-module-loading.js

@ -1,10 +1,10 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
debug("load test-module-loading.js"); debug("load test-module-loading.js");
var a = require("fixtures/a.js"); var a = require("./fixtures/a");
var d = require("fixtures/b/d.js"); var d = require("./fixtures/b/d");
var d2 = require("fixtures/b/d.js"); var d2 = require("./fixtures/b/d");
assertFalse(false, "testing the test program."); assertFalse(false, "testing the test program.");

8
test/mjsunit/test-multipart.js

@ -1,8 +1,8 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
http = require("/http.js"); http = require("http");
var multipart = require('/multipart.js'); var multipart = require('multipart');
var fixture = require('fixtures/multipart.js'); var fixture = require('./fixtures/multipart');
var port = 8222; var port = 8222;
var parts_reveived = 0; var parts_reveived = 0;

2
test/mjsunit/test-process-buffering.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var pwd_called = false; var pwd_called = false;

2
test/mjsunit/test-process-kill.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var exit_status = -1; var exit_status = -1;

2
test/mjsunit/test-process-simple.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var cat = process.createChildProcess("cat"); var cat = process.createChildProcess("cat");

2
test/mjsunit/test-process-spawn-loop.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var N = 40; var N = 40;
var finished = false; var finished = false;

2
test/mjsunit/test-promise-timeout.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var timeouts = 0; var timeouts = 0;

2
test/mjsunit/test-promise-wait.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var p1_done = false; var p1_done = false;
var p1 = new process.Promise(); var p1 = new process.Promise();

2
test/mjsunit/test-readdir.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var got_error = false; var got_error = false;

2
test/mjsunit/test-signal-handler.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
puts("process.pid: " + process.pid); puts("process.pid: " + process.pid);

4
test/mjsunit/test-tcp-binary.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
PORT = 23123; PORT = 23123;
binaryString = ""; binaryString = "";

4
test/mjsunit/test-tcp-many-clients.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
// settings // settings
var port = 20743; var port = 20743;
var bytes = 1024*40; var bytes = 1024*40;

4
test/mjsunit/test-tcp-pingpong-delay.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
var tests_run = 0; var tests_run = 0;

4
test/mjsunit/test-tcp-pingpong.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
var tests_run = 0; var tests_run = 0;

4
test/mjsunit/test-tcp-reconnect.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
var N = 50; var N = 50;
var port = 8921; var port = 8921;

4
test/mjsunit/test-tcp-throttle-kernel-buffer.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
PORT = 20444; PORT = 20444;
N = 30*1024; // 500kb N = 30*1024; // 500kb

4
test/mjsunit/test-tcp-throttle.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
PORT = 20443; PORT = 20443;
N = 200; N = 200;

4
test/mjsunit/test-tcp-timeout.js

@ -1,5 +1,5 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
tcp = require("/tcp.js"); tcp = require("tcp");
port = 9992; port = 9992;
exchanges = 0; exchanges = 0;
starttime = null; starttime = null;

2
test/mjsunit/test-timers.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
var WINDOW = 200; // why is does this need to be so big? var WINDOW = 200; // why is does this need to be so big?

2
test/mjsunit/test-utf8-scripts.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
// üäö // üäö

2
test/mjsunit/test-wait-ordering.js

@ -1,4 +1,4 @@
process.mixin(require("common.js")); process.mixin(require("./common"));
function timer (t) { function timer (t) {
var promise = new process.Promise(); var promise = new process.Promise();

Loading…
Cancel
Save