Skip to content

Commit 2a05fe7

Browse files
committed
Do not use defineGetter in src/node.js for better crankshaft perf
See: https://groups.google.com/d/topic/nodejs/xJqpp1_s6is/discussion
1 parent e3925b7 commit 2a05fe7

1 file changed

Lines changed: 33 additions & 47 deletions

File tree

src/node.js

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@
7171
};
7272

7373
startup.globalConsole = function() {
74-
global.__defineGetter__('console', function() {
75-
return NativeModule.require('console');
76-
});
74+
global.console = NativeModule.require('console');
7775
};
7876

79-
8077
startup._lazyConstants = null;
8178

8279
startup.lazyConstants = function() {
@@ -126,32 +123,29 @@
126123
};
127124

128125
startup.processStdio = function() {
129-
var stdout, stdin;
130-
131-
process.__defineGetter__('stdout', function() {
132-
if (stdout) return stdout;
133-
134-
var binding = process.binding('stdio'),
135-
net = NativeModule.require('net'),
136-
fs = NativeModule.require('fs'),
137-
tty = NativeModule.require('tty'),
138-
fd = binding.stdoutFD;
139-
140-
if (binding.isatty(fd)) {
141-
stdout = new tty.WriteStream(fd);
142-
} else if (binding.isStdoutBlocking()) {
143-
stdout = new fs.WriteStream(null, {fd: fd});
144-
} else {
145-
stdout = new net.Stream(fd);
146-
// FIXME Should probably have an option in net.Stream to create a
147-
// stream from an existing fd which is writable only. But for now
148-
// we'll just add this hack and set the `readable` member to false.
149-
// Test: ./node test/fixtures/echo.js < /etc/passwd
150-
stdout.readable = false;
151-
}
126+
var binding = process.binding('stdio'),
127+
net = NativeModule.require('net'),
128+
fs = NativeModule.require('fs'),
129+
tty = NativeModule.require('tty');
130+
131+
// process.stdout
132+
133+
var fd = binding.stdoutFD;
134+
135+
if (binding.isatty(fd)) {
136+
process.stdout = new tty.WriteStream(fd);
137+
} else if (binding.isStdoutBlocking()) {
138+
process.stdout = new fs.WriteStream(null, {fd: fd});
139+
} else {
140+
process.stdout = new net.Stream(fd);
141+
// FIXME Should probably have an option in net.Stream to create a
142+
// stream from an existing fd which is writable only. But for now
143+
// we'll just add this hack and set the `readable` member to false.
144+
// Test: ./node test/fixtures/echo.js < /etc/passwd
145+
process.stdout.readable = false;
146+
}
152147

153-
return stdout;
154-
});
148+
// process.stderr
155149

156150
var events = NativeModule.require('events');
157151
var stderr = process.stderr = new events.EventEmitter();
@@ -160,26 +154,18 @@
160154
stderr.write = process.binding('stdio').writeError;
161155
stderr.end = stderr.destroy = stderr.destroySoon = function() { };
162156

163-
process.__defineGetter__('stdin', function() {
164-
if (stdin) return stdin;
157+
// process.stdin
165158

166-
var binding = process.binding('stdio'),
167-
net = NativeModule.require('net'),
168-
fs = NativeModule.require('fs'),
169-
tty = NativeModule.require('tty'),
170-
fd = binding.openStdin();
159+
var fd = binding.openStdin();
171160

172-
if (binding.isatty(fd)) {
173-
stdin = new tty.ReadStream(fd);
174-
} else if (binding.isStdinBlocking()) {
175-
stdin = new fs.ReadStream(null, {fd: fd});
176-
} else {
177-
stdin = new net.Stream(fd);
178-
stdin.readable = true;
179-
}
180-
181-
return stdin;
182-
});
161+
if (binding.isatty(fd)) {
162+
process.stdin = new tty.ReadStream(fd);
163+
} else if (binding.isStdinBlocking()) {
164+
process.stdin = new fs.ReadStream(null, {fd: fd});
165+
} else {
166+
process.stdin = new net.Stream(fd);
167+
process.stdin.readable = true;
168+
}
183169

184170
process.openStdin = function() {
185171
process.stdin.resume();

0 commit comments

Comments
 (0)