Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-07-28 03:36:03 +0400
committerRyan Dahl <ry@tinyclouds.org>2011-07-28 03:36:05 +0400
commit497fe79f9759ff83161ff0620c47a6bdb7a205fe (patch)
tree183fc4f47286bf9c4608fe5ef085120ce0fa8d1a /src
parent1ca5b6cd0552e2c2b943876e878393d72104a62a (diff)
Speed up startup time
Reverts 2a05fe784d.
Diffstat (limited to 'src')
-rw-r--r--src/node.js86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/node.js b/src/node.js
index 64280e94519..4ed4ba4bce3 100644
--- a/src/node.js
+++ b/src/node.js
@@ -153,9 +153,12 @@
};
startup.globalConsole = function() {
- global.console = NativeModule.require('console');
+ global.__defineGetter__('console', function() {
+ return NativeModule.require('console');
+ });
};
+
startup._lazyConstants = null;
startup.lazyConstants = function() {
@@ -205,32 +208,35 @@
};
startup.processStdio = function() {
- var binding = process.binding('stdio'),
- // FIXME Remove conditional when net is supported again on windows.
- net = (process.platform !== "win32")
- ? NativeModule.require('net_legacy') // fixme!
- : undefined,
- fs = NativeModule.require('fs'),
- tty = NativeModule.require('tty');
-
- // process.stdout
-
- var fd = binding.stdoutFD;
-
- if (binding.isatty(fd)) {
- process.stdout = new tty.WriteStream(fd);
- } else if (binding.isStdoutBlocking()) {
- process.stdout = new fs.WriteStream(null, {fd: fd});
- } else {
- process.stdout = new net.Stream(fd);
- // FIXME Should probably have an option in net.Stream to create a
- // stream from an existing fd which is writable only. But for now
- // we'll just add this hack and set the `readable` member to false.
- // Test: ./node test/fixtures/echo.js < /etc/passwd
- process.stdout.readable = false;
- }
+ var stdout, stdin;
+
+ process.__defineGetter__('stdout', function() {
+ if (stdout) return stdout;
+
+ var binding = process.binding('stdio'),
+ // FIXME Remove conditional when net is supported again on windows.
+ net = (process.platform !== "win32")
+ ? NativeModule.require('net_legacy') // fixme!
+ : undefined,
+ fs = NativeModule.require('fs'),
+ tty = NativeModule.require('tty'),
+ fd = binding.stdoutFD;
+
+ if (binding.isatty(fd)) {
+ stdout = new tty.WriteStream(fd);
+ } else if (binding.isStdoutBlocking()) {
+ stdout = new fs.WriteStream(null, {fd: fd});
+ } else {
+ stdout = new net.Stream(fd);
+ // FIXME Should probably have an option in net.Stream to create a
+ // stream from an existing fd which is writable only. But for now
+ // we'll just add this hack and set the `readable` member to false.
+ // Test: ./node test/fixtures/echo.js < /etc/passwd
+ stdout.readable = false;
+ }
- // process.stderr
+ return stdout;
+ });
var stderr = process.stderr = new EventEmitter();
stderr.writable = true;
@@ -238,18 +244,26 @@
stderr.write = process.binding('stdio').writeError;
stderr.end = stderr.destroy = stderr.destroySoon = function() { };
- // process.stdin
+ process.__defineGetter__('stdin', function() {
+ if (stdin) return stdin;
- var fd = binding.openStdin();
+ var binding = process.binding('stdio'),
+ net = NativeModule.require('net'),
+ fs = NativeModule.require('fs'),
+ tty = NativeModule.require('tty'),
+ fd = binding.openStdin();
- if (binding.isatty(fd)) {
- process.stdin = new tty.ReadStream(fd);
- } else if (binding.isStdinBlocking()) {
- process.stdin = new fs.ReadStream(null, {fd: fd});
- } else {
- process.stdin = new net.Stream(fd);
- process.stdin.readable = true;
- }
+ if (binding.isatty(fd)) {
+ stdin = new tty.ReadStream(fd);
+ } else if (binding.isStdinBlocking()) {
+ stdin = new fs.ReadStream(null, {fd: fd});
+ } else {
+ stdin = new net.Stream(fd);
+ stdin.readable = true;
+ }
+
+ return stdin;
+ });
process.openStdin = function() {
process.stdin.resume();