-
Notifications
You must be signed in to change notification settings - Fork 7.3k
(Finally) Fix for "Natives' Syntax-Issues & Implementation Laziness." (Issue #1774) #1804
Changes from all commits
7ae5e24
57b396d
d5fce20
fe5ded7
ace23fd
9ef879b
d5bfd18
4d96596
efebcc9
8eec082
0948051
1689b79
c8cbf3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,29 +37,23 @@ exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) { | |
eBias = eMax >> 1, | ||
nBits = -7, | ||
i = isBE ? 0 : (nBytes - 1), | ||
d = isBE ? 1 : -1, | ||
s = buffer[offset + i]; | ||
|
||
i += d; | ||
i += d = isBE ? 1 : -1; | ||
|
||
e = s & ((1 << (-nBits)) - 1); | ||
s >>= (-nBits); | ||
e = s & (1 << -nBits) - 1; | ||
s >>= -nBits; | ||
nBits += eLen; | ||
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); | ||
|
||
m = e & ((1 << (-nBits)) - 1); | ||
e >>= (-nBits); | ||
m = e & (1 << -nBits) - 1; | ||
e >>= -nBits; | ||
nBits += mLen; | ||
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); | ||
|
||
if (e === 0) { | ||
e = 1 - eBias; | ||
} else if (e === eMax) { | ||
return m ? NaN : ((s ? -1 : 1) * Infinity); | ||
} else { | ||
m = m + Math.pow(2, mLen); | ||
e = e - eBias; | ||
} | ||
if (e === 0) e = 1 - eBias; | ||
else if (e === eMax) return m ? NaN : (s ? -1 : 1) * Infinity; | ||
else m = m + Math.pow(2, mLen), e = e - eBias; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad -- do not compact into single bracketless if/else statements. If / else should always have brackets even if 1 line. |
||
return (s ? -1 : 1) * m * Math.pow(2, e - mLen); | ||
}; | ||
|
||
|
@@ -75,42 +69,17 @@ exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) { | |
|
||
value = Math.abs(value); | ||
|
||
if (isNaN(value) || value === Infinity) { | ||
m = isNaN(value) ? 1 : 0; | ||
e = eMax; | ||
} else { | ||
if (isNaN(value) || value === Infinity) m = isNaN(value) ? 1 : 0, e = eMax; | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, another style violation for no gain. |
||
e = Math.floor(Math.log(value) / Math.LN2); | ||
if (value * (c = Math.pow(2, -e)) < 1) { | ||
e--; | ||
c *= 2; | ||
} | ||
if (e+eBias >= 1) { | ||
value += rt / c; | ||
} else { | ||
value += rt * Math.pow(2, 1 - eBias); | ||
} | ||
if (value * c >= 2) { | ||
e++; | ||
c /= 2; | ||
} | ||
|
||
if (e + eBias >= eMax) { | ||
m = 0; | ||
e = eMax; | ||
} else if (e + eBias >= 1) { | ||
m = (value * c - 1) * Math.pow(2, mLen); | ||
e = e + eBias; | ||
} else { | ||
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); | ||
e = 0; | ||
} | ||
if (value * (c = Math.pow(2, -e)) < 1) e--, c *= 2; | ||
value += e + eBias >= 1 ? rt / c : rt * Math.pow(2, 1 - eBias); | ||
value * c >= 2 && ( e++, c /= 2 ); | ||
e + eBias >= eMax ? ( m = 0, e = eMax ) : e + eBias >= 1 ? ( m = (value * c - 1) * Math.pow(2, mLen), e = e + eBias) : (m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen), e = 0 ); | ||
} | ||
|
||
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); | ||
|
||
for (; mLen >= 8; buffer[offset + i] = m & 256, i += d, m /= 256, mLen -= 8); | ||
e = (e << mLen) | m; | ||
eLen += mLen; | ||
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); | ||
|
||
for (eLen += mLen; eLen > 0; buffer[offset + i] = e & 256, i += d, e /= 256, eLen -= 8); | ||
buffer[offset + i - d] |= s * 128; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,18 +181,12 @@ exports.execFile = function(file /* args, options, callback */) { | |
|
||
child.stdout.addListener('data', function(chunk) { | ||
stdout += chunk; | ||
if (stdout.length > options.maxBuffer) { | ||
err = new Error('maxBuffer exceeded.'); | ||
kill(); | ||
} | ||
( stdout.length > options.maxBuffer ) && (err = new Error('maxBuffer exceeded.'), kill()); | ||
}); | ||
|
||
child.stderr.addListener('data', function(chunk) { | ||
stderr += chunk; | ||
if (stderr.length > options.maxBuffer) { | ||
err = new Error('maxBuffer exceeded.'); | ||
kill(); | ||
} | ||
( stderr.length > options.maxBuffer ) && ( err = new Error('maxBuffer exceeded.'), kill() ); | ||
}); | ||
|
||
child.addListener('exit', exithandler); | ||
|
@@ -266,27 +260,9 @@ ChildProcess.prototype.spawn = function(path, args, options, customFds) { | |
args = args || []; | ||
|
||
var cwd, env, setsid, uid, gid; | ||
if (!options || options.cwd === undefined && | ||
options.env === undefined && | ||
options.customFds === undefined && | ||
options.gid === undefined && | ||
options.uid === undefined) { | ||
// Deprecated API: (path, args, options, env, customFds) | ||
cwd = ''; | ||
env = options || process.env; | ||
customFds = customFds || [-1, -1, -1]; | ||
setsid = false; | ||
uid = -1; | ||
gid = -1; | ||
} else { | ||
// Recommended API: (path, args, options) | ||
cwd = options.cwd || ''; | ||
env = options.env || process.env; | ||
customFds = options.customFds || [-1, -1, -1]; | ||
setsid = options.setsid ? true : false; | ||
uid = options.hasOwnProperty('uid') ? options.uid : -1; | ||
gid = options.hasOwnProperty('gid') ? options.gid : -1; | ||
} | ||
!options || options.cwd === void 0 && options.env === void 0 && options.customFds === void 0 && options.gid === void 0 && options.uid === void 0 ? | ||
( cwd = '', env = options || process.env, customFds = customFds || [-1, -1, -1], setsid = false, uid = -1, gid = -1 ) : // Deprecated API: (path, args, options, env, customFds) | ||
(cwd = options.cwd || '', env = options.env || process.env, customFds = options.customFds || [-1, -1, -1], setsid = options.setsid ? true : false, uid = options.hasOwnProperty('uid') ? options.uid : -1, gid = options.hasOwnProperty('gid') ? options.gid : -1); // Recommended API: (path, args, options) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WOAH |
||
var envPairs = []; | ||
var keys = Object.keys(env); | ||
|
@@ -310,15 +286,15 @@ ChildProcess.prototype.spawn = function(path, args, options, customFds) { | |
gid); | ||
this.fds = fds; | ||
|
||
if (customFds[0] === -1 || customFds[0] === undefined) { | ||
if (customFds[0] === -1 || customFds[0] === void 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What in the world is this? This surely isn't a typical way to do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As specified by V8 and the Closure-Compiler, void 0 is the better way to do undefined, anyway, I'll replace it, if needed. |
||
this.stdin.open(fds[0]); | ||
this.stdin.writable = true; | ||
this.stdin.readable = false; | ||
} else { | ||
this.stdin = null; | ||
} | ||
|
||
if (customFds[1] === -1 || customFds[1] === undefined) { | ||
if (customFds[1] === -1 || customFds[1] === void 0) { | ||
this.stdout.open(fds[1]); | ||
this.stdout.writable = false; | ||
this.stdout.readable = true; | ||
|
@@ -327,7 +303,7 @@ ChildProcess.prototype.spawn = function(path, args, options, customFds) { | |
this.stdout = null; | ||
} | ||
|
||
if (customFds[2] === -1 || customFds[2] === undefined) { | ||
if (customFds[2] === -1 || customFds[2] === void 0) { | ||
this.stderr.open(fds[2]); | ||
this.stderr.writable = false; | ||
this.stderr.readable = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these hex->dec changes was also completely unneeded.
It's much easier to read in hex. Don't keep any of these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of optimizing: hex-values have to be converted to decimals, costs runtime. Anyway, fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should all be optimized by V8 itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget: V8 is smarter than us all :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, just a few billion times faster. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no really... V8 is smarter than you :P
don't try to outwit it, unless your a v8 developer.