Skip to content

Commit 139e960

Browse files
committed
lib: fix position of new const funcs, jslint
1 parent efa4814 commit 139e960

File tree

11 files changed

+257
-254
lines changed

11 files changed

+257
-254
lines changed

lib/_debugger.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ function Interface(stdin, stdout, args) {
785785
} else {
786786
this.repl.context[key] = fn;
787787
}
788-
}
788+
};
789789

790790
// Copy all prototype methods in repl context
791791
// Setup them as getters if possible
@@ -1259,13 +1259,6 @@ Interface.prototype.watchers = function() {
12591259
return callback();
12601260
}
12611261

1262-
this._watchers.forEach((watcher, i) => {
1263-
this.debugEval(watcher, null, null, function(err, value) {
1264-
values[i] = err ? '<error>' : value;
1265-
wait();
1266-
});
1267-
});
1268-
12691262
const wait = () => {
12701263
if (--waiting === 0) {
12711264
if (verbose) this.print('Watchers:');
@@ -1283,6 +1276,13 @@ Interface.prototype.watchers = function() {
12831276
callback(null);
12841277
}
12851278
};
1279+
1280+
this._watchers.forEach((watcher, i) => {
1281+
this.debugEval(watcher, null, null, function(err, value) {
1282+
values[i] = err ? '<error>' : value;
1283+
wait();
1284+
});
1285+
});
12861286
};
12871287

12881288
// Break on exception

lib/_http_server.js

Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -322,135 +322,16 @@ function connectionListener(socket) {
322322
parser.maxHeaderPairs = 2000;
323323
}
324324

325-
socket.addListener('error', socketOnError);
326-
socket.addListener('close', serverSocketCloseListener);
327-
parser.onIncoming = parserOnIncoming;
328-
socket.on('end', socketOnEnd);
329-
socket.on('data', socketOnData);
330-
331-
// We are consuming socket, so it won't get any actual data
332-
socket.on('resume', onSocketResume);
333-
socket.on('pause', onSocketPause);
334-
335-
socket.on('drain', socketOnDrain);
336-
337-
// Override on to unconsume on `data`, `readable` listeners
338-
socket.on = socketOnWrap;
339-
340-
var external = socket._handle._externalStream;
341-
if (external) {
342-
parser._consumed = true;
343-
parser.consume(external);
344-
}
345-
external = null;
346-
parser[kOnExecute] = onParserExecute;
347-
348325
// TODO(isaacs): Move all these functions out of here
349326
const socketOnError = (e) => {
350327
// Ignore further errors
351-
this.removeListener('error', socketOnError);
352-
this.on('error', () => {});
353-
354-
if (!this.emit('clientError', e, this))
355-
this.destroy(e);
356-
};
357-
358-
function socketOnData(d) {
359-
assert(!socket._paused);
360-
debug('SERVER socketOnData %d', d.length);
361-
var ret = parser.execute(d);
362-
363-
onParserExecuteCommon(ret, d);
364-
}
365-
366-
function onParserExecute(ret, d) {
367-
debug('SERVER socketOnParserExecute %d', ret);
368-
onParserExecuteCommon(ret, undefined);
369-
}
370-
371-
const onParserExecuteCommon = (ret, d) => {
372-
if (ret instanceof Error) {
373-
debug('parse error');
374-
socketOnError.call(socket, ret);
375-
} else if (parser.incoming && parser.incoming.upgrade) {
376-
// Upgrade or CONNECT
377-
var bytesParsed = ret;
378-
var req = parser.incoming;
379-
debug('SERVER upgrade or connect', req.method);
380-
381-
if (!d)
382-
d = parser.getCurrentBuffer();
383-
384-
socket.removeListener('data', socketOnData);
385-
socket.removeListener('end', socketOnEnd);
386-
socket.removeListener('close', serverSocketCloseListener);
387-
unconsume(parser, socket);
388-
parser.finish();
389-
freeParser(parser, req, null);
390-
parser = null;
391-
392-
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
393-
if (this.listenerCount(eventName) > 0) {
394-
debug('SERVER have listener for %s', eventName);
395-
var bodyHead = d.slice(bytesParsed, d.length);
328+
socket.removeListener('error', socketOnError);
329+
socket.on('error', () => {});
396330

397-
// TODO(isaacs): Need a way to reset a stream to fresh state
398-
// IE, not flowing, and not explicitly paused.
399-
socket._readableState.flowing = null;
400-
this.emit(eventName, req, socket, bodyHead);
401-
} else {
402-
// Got upgrade header or CONNECT method, but have no handler.
403-
socket.destroy();
404-
}
405-
}
406-
407-
if (socket._paused && socket.parser) {
408-
// onIncoming paused the socket, we should pause the parser as well
409-
debug('pause parser');
410-
socket.parser.pause();
411-
}
331+
if (!this.emit('clientError', e, socket))
332+
socket.destroy(e);
412333
};
413334

414-
const socketOnEnd = () => {
415-
var socket = this;
416-
var ret = parser.finish();
417-
418-
if (ret instanceof Error) {
419-
debug('parse error');
420-
socketOnError.call(socket, ret);
421-
return;
422-
}
423-
424-
if (!this.httpAllowHalfOpen) {
425-
abortIncoming();
426-
if (socket.writable) socket.end();
427-
} else if (outgoing.length) {
428-
outgoing[outgoing.length - 1]._last = true;
429-
} else if (socket._httpMessage) {
430-
socket._httpMessage._last = true;
431-
} else {
432-
if (socket.writable) socket.end();
433-
}
434-
};
435-
436-
437-
// The following callback is issued after the headers have been read on a
438-
// new message. In this callback we setup the response object and pass it
439-
// to the user.
440-
441-
socket._paused = false;
442-
function socketOnDrain() {
443-
var needPause = outgoingData > socket._writableState.highWaterMark;
444-
445-
// If we previously paused, then start reading again.
446-
if (socket._paused && !needPause) {
447-
socket._paused = false;
448-
if (socket.parser)
449-
socket.parser.resume();
450-
socket.resume();
451-
}
452-
}
453-
454335
const parserOnIncoming = (req, shouldKeepAlive) => {
455336
incoming.push(req);
456337

@@ -486,7 +367,6 @@ function connectionListener(socket) {
486367

487368
// When we're finished writing the response, check if this is the last
488369
// respose, if so destroy the socket.
489-
res.on('finish', resOnFinish);
490370
const resOnFinish = () => {
491371
// Usually the first incoming element should be our request. it may
492372
// be that in the case abortIncoming() was called that the incoming
@@ -512,7 +392,8 @@ function connectionListener(socket) {
512392
m.assignSocket(socket);
513393
}
514394
}
515-
}
395+
};
396+
res.on('finish', resOnFinish);
516397

517398
if (req.headers.expect !== undefined &&
518399
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1)) {
@@ -537,6 +418,125 @@ function connectionListener(socket) {
537418
this.emit('request', req, res);
538419
}
539420
return false; // Not a HEAD response. (Not even a response!)
421+
};
422+
423+
const socketOnEnd = () => {
424+
var ret = parser.finish();
425+
426+
if (ret instanceof Error) {
427+
debug('parse error');
428+
socketOnError(ret);
429+
return;
430+
}
431+
432+
if (!this.httpAllowHalfOpen) {
433+
abortIncoming();
434+
if (socket.writable) socket.end();
435+
} else if (outgoing.length) {
436+
outgoing[outgoing.length - 1]._last = true;
437+
} else if (socket._httpMessage) {
438+
socket._httpMessage._last = true;
439+
} else {
440+
if (socket.writable) socket.end();
441+
}
442+
};
443+
444+
const onParserExecuteCommon = (ret, d) => {
445+
if (ret instanceof Error) {
446+
debug('parse error');
447+
socketOnError(ret);
448+
} else if (parser.incoming && parser.incoming.upgrade) {
449+
// Upgrade or CONNECT
450+
var bytesParsed = ret;
451+
var req = parser.incoming;
452+
debug('SERVER upgrade or connect', req.method);
453+
454+
if (!d)
455+
d = parser.getCurrentBuffer();
456+
457+
socket.removeListener('data', socketOnData);
458+
socket.removeListener('end', socketOnEnd);
459+
socket.removeListener('close', serverSocketCloseListener);
460+
unconsume(parser, socket);
461+
parser.finish();
462+
freeParser(parser, req, null);
463+
parser = null;
464+
465+
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
466+
if (this.listenerCount(eventName) > 0) {
467+
debug('SERVER have listener for %s', eventName);
468+
var bodyHead = d.slice(bytesParsed, d.length);
469+
470+
// TODO(isaacs): Need a way to reset a stream to fresh state
471+
// IE, not flowing, and not explicitly paused.
472+
socket._readableState.flowing = null;
473+
this.emit(eventName, req, socket, bodyHead);
474+
} else {
475+
// Got upgrade header or CONNECT method, but have no handler.
476+
socket.destroy();
477+
}
478+
}
479+
480+
if (socket._paused && socket.parser) {
481+
// onIncoming paused the socket, we should pause the parser as well
482+
debug('pause parser');
483+
socket.parser.pause();
484+
}
485+
};
486+
487+
socket.addListener('error', socketOnError);
488+
socket.addListener('close', serverSocketCloseListener);
489+
parser.onIncoming = parserOnIncoming;
490+
socket.on('end', socketOnEnd);
491+
socket.on('data', socketOnData);
492+
493+
// We are consuming socket, so it won't get any actual data
494+
socket.on('resume', onSocketResume);
495+
socket.on('pause', onSocketPause);
496+
497+
socket.on('drain', socketOnDrain);
498+
499+
// Override on to unconsume on `data`, `readable` listeners
500+
socket.on = socketOnWrap;
501+
502+
var external = socket._handle._externalStream;
503+
if (external) {
504+
parser._consumed = true;
505+
parser.consume(external);
506+
}
507+
external = null;
508+
parser[kOnExecute] = onParserExecute;
509+
510+
// TODO(isaacs): Move all these functions out of here
511+
512+
function socketOnData(d) {
513+
assert(!socket._paused);
514+
debug('SERVER socketOnData %d', d.length);
515+
var ret = parser.execute(d);
516+
517+
onParserExecuteCommon(ret, d);
518+
}
519+
520+
function onParserExecute(ret, d) {
521+
debug('SERVER socketOnParserExecute %d', ret);
522+
onParserExecuteCommon(ret, undefined);
523+
}
524+
525+
// The following callback is issued after the headers have been read on a
526+
// new message. In this callback we setup the response object and pass it
527+
// to the user.
528+
529+
socket._paused = false;
530+
function socketOnDrain() {
531+
var needPause = outgoingData > socket._writableState.highWaterMark;
532+
533+
// If we previously paused, then start reading again.
534+
if (socket._paused && !needPause) {
535+
socket._paused = false;
536+
if (socket.parser)
537+
socket.parser.resume();
538+
socket.resume();
539+
}
540540
}
541541
}
542542
exports._connectionListener = connectionListener;

lib/_stream_wrap.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ function StreamWrap(stream) {
3838
return this.doWrite(req, bufs);
3939
};
4040

41-
this.stream.pause();
42-
this.stream.on('error', (err) => {
41+
const onerror = (err) => {
4342
this.emit('error', err);
44-
});
45-
this.stream.on('data', (chunk) => {
43+
};
44+
45+
const ondata = (chunk) => {
4646
if (!(chunk instanceof Buffer)) {
4747
// Make sure that no further `data` events will happen
4848
this.pause();
@@ -54,7 +54,11 @@ function StreamWrap(stream) {
5454
debug('data', chunk.length);
5555
if (this._handle)
5656
this._handle.readBuffer(chunk);
57-
});
57+
};
58+
59+
this.stream.pause();
60+
this.stream.on('error', onerror);
61+
this.stream.on('data', ondata);
5862
this.stream.once('end', () => {
5963
debug('end');
6064
if (this._handle)
@@ -113,12 +117,6 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) {
113117
// Queue the request to be able to cancel it
114118
const item = this._enqueue('write', req);
115119

116-
this.stream.cork();
117-
bufs.forEach((buf) => {
118-
this.stream.write(buf, done);
119-
});
120-
this.stream.uncork();
121-
122120
const done = (err) => {
123121
if (!err && --pending !== 0)
124122
return;
@@ -145,6 +143,12 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) {
145143
});
146144
};
147145

146+
this.stream.cork();
147+
bufs.forEach((buf) => {
148+
this.stream.write(buf, done);
149+
});
150+
this.stream.uncork();
151+
148152
return 0;
149153
};
150154

lib/_tls_legacy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,6 @@ function onnewsession(key, session) {
633633

634634
var once = false;
635635

636-
if (!this.server.emit('newSession', key, session, done))
637-
done();
638-
639636
const done = () => {
640637
if (once)
641638
return;
@@ -644,6 +641,9 @@ function onnewsession(key, session) {
644641
if (this.ssl)
645642
this.ssl.newSessionDone();
646643
};
644+
645+
if (!this.server.emit('newSession', key, session, done))
646+
done();
647647
}
648648

649649

0 commit comments

Comments
 (0)