Skip to content

Commit 9b3b090

Browse files
author
Ruben Bridgewater
committed
Simplify parser and remove dead code
1 parent 851dd87 commit 9b3b090

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

lib/parsers/javascript.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
2222

2323
if (type === 43 || type === 58 || type === 45) { // + or : or -
2424
// up to the delimiter
25-
end = this._packetEndOffset() - 1;
25+
end = this._packetEndOffset();
2626
start = this._offset;
2727

28-
if (end > this._buffer.length) {
29-
throw new IncompleteReadBuffer('Wait for more data.');
30-
}
31-
3228
// include the delimiter
3329
this._offset = end + 2;
3430

@@ -91,13 +87,15 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
9187
}
9288

9389
return reply;
90+
} else {
91+
return null;
9492
}
9593
};
9694

9795
JavascriptReplyParser.prototype.execute = function (buffer) {
9896
this.append(buffer);
9997

100-
var type, ret, offset;
98+
var type, offset;
10199

102100
while (true) {
103101
offset = this._offset;
@@ -109,30 +107,16 @@ JavascriptReplyParser.prototype.execute = function (buffer) {
109107
try {
110108
type = this._buffer[this._offset++];
111109

112-
if (type === 43) { // Strings +
113-
ret = this._parseResult(type);
114-
115-
this.send_reply(ret);
110+
if (type === 43 || type === 58 || type === 36) { // Strings + // Integers : // Bulk strings $
111+
this.send_reply(this._parseResult(type));
116112
} else if (type === 45) { // Errors -
117-
ret = this._parseResult(type);
118-
119-
this.send_error(ret);
120-
} else if (type === 58) { // Integers :
121-
ret = this._parseResult(type);
122-
123-
this.send_reply(ret);
124-
} else if (type === 36) { // Bulk strings $
125-
ret = this._parseResult(type);
126-
127-
this.send_reply(ret);
113+
this.send_error(this._parseResult(type));
128114
} else if (type === 42) { // Arrays *
129115
// set a rewind point. if a failure occurs,
130116
// wait for the next execute()/append() and try again
131117
offset = this._offset - 1;
132118

133-
ret = this._parseResult(type);
134-
135-
this.send_reply(ret);
119+
this.send_reply(this._parseResult(type));
136120
} else if (type === 10 || type === 13) {
137121
break;
138122
} else {
@@ -162,7 +146,7 @@ JavascriptReplyParser.prototype.append = function (newBuffer) {
162146
};
163147

164148
JavascriptReplyParser.prototype.parseHeader = function () {
165-
var end = this._packetEndOffset(),
149+
var end = this._packetEndOffset() + 1,
166150
value = this._buffer.toString('ascii', this._offset, end - 1) | 0;
167151

168152
this._offset = end + 1;
@@ -182,7 +166,6 @@ JavascriptReplyParser.prototype._packetEndOffset = function () {
182166
}
183167
}
184168

185-
offset++;
186169
return offset;
187170
};
188171

0 commit comments

Comments
 (0)