Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

(Finally) Fix for "Natives' Syntax-Issues & Implementation Laziness." (Issue #1774) #1804

Closed
wants to merge 13 commits into from
27 changes: 14 additions & 13 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Client.prototype._onResponse = function(res) {
index = i;
return true;
}
return null;
});

var self = this;
Expand Down Expand Up @@ -259,7 +260,7 @@ Client.prototype.reqVersion = function(cb) {
cb = cb || function () {};
this.req({ command: 'version' } , function(err, body, res) {
if (err) return cb(err);
cb(null, res.body.body.V8Version, res.body.running);
return cb(null, res.body.body.V8Version, res.body.running);
});
};

Expand All @@ -285,7 +286,7 @@ Client.prototype.reqLookup = function(refs, cb) {
}
}

cb(null, res);
return cb(null, res);
});
};

Expand All @@ -303,7 +304,7 @@ Client.prototype.reqScopes = function(cb) {
return scope.object.ref;
});

self.reqLookup(refs, function(err, res) {
return self.reqLookup(refs, function(err, res) {
if (err) return cb(err);

var globals = Object.keys(res).map(function(key) {
Expand All @@ -312,7 +313,7 @@ Client.prototype.reqScopes = function(cb) {
});
});

cb(null, globals.reverse());
return cb(null, globals.reverse());
});
});
};
Expand All @@ -339,13 +340,13 @@ Client.prototype.reqEval = function(expression, cb) {
var frame = bt.frames[self.currentFrame];

var evalFrames = frame.scopes.map(function(s) {
if (!s) return;
if (!s) return null;
var x = bt.frames[s.index];
if (!x) return;
if (!x) return null;
return x.index;
});

self._reqFramesEval(expression, evalFrames, cb);
return self._reqFramesEval(expression, evalFrames, cb);
});
};

Expand All @@ -364,7 +365,7 @@ Client.prototype._reqFramesEval = function(expression, evalFrames, cb) {
cb = cb || function () {};
this.reqFrameEval(expression, i, function(err, res) {
if (!err) return cb(null, res);
self._reqFramesEval(expression, evalFrames, cb);
return self._reqFramesEval(expression, evalFrames, cb);
});
};

Expand Down Expand Up @@ -423,7 +424,7 @@ Client.prototype.reqScripts = function(cb) {
for (var i = 0; i < res.length; i++) {
self._addHandle(res[i]);
}
cb(null);
return cb(null);
});
};

Expand All @@ -438,7 +439,7 @@ Client.prototype.listbreakpoints = function(cb) {
};

Client.prototype.setBreakpoint = function(req, cb) {
var req = {
req = {
command: 'setbreakpoint',
arguments: req
};
Expand All @@ -447,7 +448,7 @@ Client.prototype.setBreakpoint = function(req, cb) {
};

Client.prototype.clearBreakpoint = function(req, cb) {
var req = {
req = {
command: 'clearbreakpoint',
arguments: req
};
Expand Down Expand Up @@ -612,7 +613,7 @@ Client.prototype.fullTrace = function(cb) {
refs.push(frame.receiver.ref);
}

self.reqLookup(refs, function(err, res) {
return self.reqLookup(refs, function(err, res) {
if (err) return cb(err);

for (var i = 0; i < trace.frames.length; i++) {
Expand All @@ -622,7 +623,7 @@ Client.prototype.fullTrace = function(cb) {
frame.receiver = res[frame.receiver.ref];
}

cb(null, trace);
return cb(null, trace);
});
});
};
Expand Down
15 changes: 7 additions & 8 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,13 @@ Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
assert.ok(offset < buffer.length,
'Trying to write beyond buffer length');

verifsint(value, 0x7f, -0xf0);
verifsint(value, 127, -240);
}

if (value >= 0) {
buffer.writeUInt8(value, offset, noAssert);
} else {
buffer.writeUInt8(0xff + value + 1, offset, noAssert);
buffer.writeUInt8(255 + value + 1, offset, noAssert);
Copy link

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.

Copy link
Author

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.

Copy link

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.

Copy link

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

Copy link
Author

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. :)

Copy link

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.

}
};

Expand All @@ -1012,13 +1012,13 @@ function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
assert.ok(offset + 1 < buffer.length,
'Trying to write beyond buffer length');

verifsint(value, 0x7fff, -0xf000);
verifsint(value, 32767, -61440);
}

if (value >= 0) {
writeUInt16(buffer, value, offset, isBigEndian, noAssert);
} else {
writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
writeUInt16(buffer, 65535 + value + 1, offset, isBigEndian, noAssert);
}
}

Expand All @@ -1044,13 +1044,13 @@ function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
assert.ok(offset + 3 < buffer.length,
'Trying to write beyond buffer length');

verifsint(value, 0x7fffffff, -0xf0000000);
verifsint(value, 2147483647, -4026531840);
}

if (value >= 0) {
writeUInt32(buffer, value, offset, isBigEndian, noAssert);
} else {
writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
writeUInt32(buffer, 2147483647 + value + 1, offset, isBigEndian, noAssert);
}
}

Expand Down Expand Up @@ -1079,8 +1079,7 @@ function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
}

require('buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
23, 4);
require('buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, 23, 4);
}

Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
Expand Down
63 changes: 16 additions & 47 deletions lib/buffer_ieee754.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Choose a reason for hiding this comment

The 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);
};

Expand All @@ -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 {
Copy link

Choose a reason for hiding this comment

The 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;
};
40 changes: 8 additions & 32 deletions lib/child_process_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOAH

var envPairs = [];
var keys = Object.keys(env);
Expand All @@ -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) {
Copy link

Choose a reason for hiding this comment

The 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.
no 'change for changes sake' as bnoor said. leave these out.

Copy link
Author

Choose a reason for hiding this comment

The 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;
Expand All @@ -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;
Expand Down
Loading