* @param {Buffer} chunk
(chunk)
| 7246 | * @param {Buffer} chunk |
| 7247 | */ |
| 7248 | execute(chunk) { |
| 7249 | assert(currentParser === null); |
| 7250 | assert(this.ptr != null); |
| 7251 | assert(!this.paused); |
| 7252 | const { socket, llhttp } = this; |
| 7253 | if (chunk.length > currentBufferSize) { |
| 7254 | if (currentBufferPtr) { |
| 7255 | llhttp.free(currentBufferPtr); |
| 7256 | } |
| 7257 | currentBufferSize = Math.ceil(chunk.length / 4096) * 4096; |
| 7258 | currentBufferPtr = llhttp.malloc(currentBufferSize); |
| 7259 | } |
| 7260 | if (currentBuffer === null || currentBuffer.buffer !== llhttp.memory.buffer || currentBuffer.byteOffset !== currentBufferPtr || currentBuffer.byteLength !== currentBufferSize) { |
| 7261 | currentBuffer = new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize); |
| 7262 | } |
| 7263 | currentBuffer.set(chunk); |
| 7264 | try { |
| 7265 | let ret; |
| 7266 | try { |
| 7267 | currentBufferRef = chunk; |
| 7268 | currentParser = this; |
| 7269 | ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, chunk.length); |
| 7270 | } finally { |
| 7271 | currentParser = null; |
| 7272 | currentBufferRef = null; |
| 7273 | } |
| 7274 | if (ret !== constants.ERROR.OK) { |
| 7275 | const data = chunk.subarray(llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr); |
| 7276 | if (ret === constants.ERROR.PAUSED_UPGRADE) { |
| 7277 | this.onUpgrade(data); |
| 7278 | } else if (ret === constants.ERROR.PAUSED) { |
| 7279 | this.paused = true; |
| 7280 | socket.unshift(data); |
| 7281 | } else { |
| 7282 | throw this.createError(ret, data); |
| 7283 | } |
| 7284 | } |
| 7285 | } catch (err) { |
| 7286 | util.destroy(socket, err); |
| 7287 | } |
| 7288 | } |
| 7289 | finish() { |
| 7290 | assert(currentParser === null); |
| 7291 | assert(this.ptr != null); |
no test coverage detected