From 2a05fe784d1c7ced3cee11e0d9e066b3bb0f361e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 14 Mar 2011 12:48:35 -0700 Subject: [PATCH] Do not use defineGetter in src/node.js for better crankshaft perf See: https://groups.google.com/d/topic/nodejs/xJqpp1_s6is/discussion --- src/node.js | 80 ++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/src/node.js b/src/node.js index 6b0aa6f53ea..06d94473923 100644 --- a/src/node.js +++ b/src/node.js @@ -71,12 +71,9 @@ }; startup.globalConsole = function() { - global.__defineGetter__('console', function() { - return NativeModule.require('console'); - }); + global.console = NativeModule.require('console'); }; - startup._lazyConstants = null; startup.lazyConstants = function() { @@ -126,32 +123,29 @@ }; startup.processStdio = function() { - var stdout, stdin; - - process.__defineGetter__('stdout', function() { - if (stdout) return stdout; - - var binding = process.binding('stdio'), - net = NativeModule.require('net'), - 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; - } + var binding = process.binding('stdio'), + net = NativeModule.require('net'), + 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; + } - return stdout; - }); + // process.stderr var events = NativeModule.require('events'); var stderr = process.stderr = new events.EventEmitter(); @@ -160,26 +154,18 @@ stderr.write = process.binding('stdio').writeError; stderr.end = stderr.destroy = stderr.destroySoon = function() { }; - process.__defineGetter__('stdin', function() { - if (stdin) return stdin; + // process.stdin - var binding = process.binding('stdio'), - net = NativeModule.require('net'), - fs = NativeModule.require('fs'), - tty = NativeModule.require('tty'), - fd = binding.openStdin(); + var fd = binding.openStdin(); - 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; - }); + 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; + } process.openStdin = function() { process.stdin.resume();