proto._onStream = function _onStream (stream) { var state = this._spdyState var handle = spdy.handle.create(this._spdyState.options, stream) var socketOptions = { handle: handle, allowHalfOpen: true } var socket if (state.secure) { socket = new spdy.Socket(stream.connection.socket, socketOptions) } else { socket = new net.Socket(socketOptions) } // This is needed because the `error` listener, added by the default // `connection` listener, no longer has bound arguments. It relies instead // on the `server` property of the socket. See https://github.com/nodejs/node/pull/11926 // for more details. // This is only done for Node.js >= 4 in order to not break compatibility // with older versions of the platform. if (process.versions.modules >= 46) { socket.server = this } handle.assignSocket(socket) // For v0.8 socket.readable = true socket.writable = true this._invokeDefault(socket) // For v0.8, 0.10 and 0.12 if (process.versions.modules < 46) { // eslint-disable-next-line this.listenerCount = EventEmitter.listenerCount.bind(this) } // Add lazy `checkContinue` listener, otherwise `res.writeContinue` will be // called before the response object was patched by us. if (stream.headers.expect !== undefined && /100-continue/i.test(stream.headers.expect) && this.listenerCount('checkContinue') === 0) { this.once('checkContinue', function (req, res) { res.writeContinue() this.emit('request', req, res) }) } handle.emitRequest() }
_lintByProcessor(processor, text, ext, filePath) { assert(processor, `processor is not found for ${ext}`); const {preProcess, postProcess} = processor.processor(ext); assert(typeof preProcess === "function" && typeof postProcess === "function", `processor should implement {preProcess, postProcess}`); const ast = preProcess(text, filePath); let promiseQueue = []; const ruleContextAgent = this._createRuleContextAgent(text, filePath); const listenerCount = (typeof ruleContextAgent.listenerCount !== 'undefined') ? ruleContextAgent.listenerCount.bind(ruleContextAgent) // Node 4.x >= : EventEmitter.listenerCount.bind(EventEmitter, ruleContextAgent);// Node 0.12 traverseController.traverse(ast, { enter(node, parent) { const type = node.type; Object.defineProperty(node, 'parent', {value: parent}); if (listenerCount(type) > 0) { let promise = ruleContextAgent.emit(type, node); promiseQueue.push(promise); } }, leave(node) { const type = `${node.type}:exit`; if (listenerCount(type) > 0) { let promise = ruleContextAgent.emit(type, node); promiseQueue.push(promise); } } }); return Promise.all(promiseQueue).then(() => { let messages = ruleContextAgent.messages; let result = postProcess(messages, filePath); if (result.filePath == null) { result.filePath = `<Unkown${ext}>`; } assert(result.filePath && result.messages.length >= 0, "postProcess should return { messages, filePath } "); return result; }); }