diff --git a/closure/goog/labs/net/webchannel/channelrequest.js b/closure/goog/labs/net/webchannel/channelrequest.js index 3c3ed7d627..80de41503e 100644 --- a/closure/goog/labs/net/webchannel/channelrequest.js +++ b/closure/goog/labs/net/webchannel/channelrequest.js @@ -867,7 +867,7 @@ ChannelRequest.prototype.decodeXmlHttpResponse_ = function() { responseText += this.fetchResponseState_.textDecoder.decode( responseChunks[i], {stream: isLastChunk}); } - responseChunks.splice(0, responseLength); + responseChunks.length = 0; // Empty the `responseChunks` array. this.fetchResponseState_.responseBuffer += responseText; this.xmlHttpChunkStart_ = 0; return this.fetchResponseState_.responseBuffer; @@ -906,22 +906,6 @@ ChannelRequest.prototype.useFetchStreamsForResponse_ = function() { }; -/** - * Resets the response buffer if the saved chunk has been processed. - * @private - * @param {string|!Object|undefined} chunkText - */ -ChannelRequest.prototype.maybeResetBuffer_ = function(chunkText) { - 'use strict'; - if (this.useFetchStreamsForResponse_() && - chunkText != ChannelRequest.INCOMPLETE_CHUNK_ && - chunkText != ChannelRequest.INVALID_CHUNK_) { - this.fetchResponseState_.responseBuffer = ''; - this.xmlHttpChunkStart_ = 0; - } -}; - - /** * Decodes the next set of available chunks in the response. * @param {number} readyState The value of readyState. @@ -960,7 +944,12 @@ ChannelRequest.prototype.decodeNextChunks_ = function( } } - this.maybeResetBuffer_(chunkText); + if (this.useFetchStreamsForResponse_() && this.xmlHttpChunkStart_ != 0) { + // Remove processed chunk text from response buffer. + this.fetchResponseState_.responseBuffer = + this.fetchResponseState_.responseBuffer.slice(this.xmlHttpChunkStart_); + this.xmlHttpChunkStart_ = 0; + } if (readyState == goog.net.XmlHttp.ReadyState.COMPLETE && responseText.length == 0 &&