From c86d7daa74a5f69b6cf929b5143c102af42d13ef Mon Sep 17 00:00:00 2001 From: Takeshi Yoshino Date: Tue, 28 Jun 2016 17:12:11 +0900 Subject: [PATCH] Fix pendingPullIntos access in ReadableByteStreamControllerClose() The size of pendingPullIntos must be checked before getting the head of it. As a bonus, this commit removes unnecessary ReadableStreamHasBYOBReader checking. Fixes #470 --- index.bs | 12 ++++++------ reference-implementation/lib/readable-stream.js | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/index.bs b/index.bs index b04da8352..bb0e6c171 100644 --- a/index.bs +++ b/index.bs @@ -2067,12 +2067,12 @@ throws>ReadableByteStreamControllerClose ( controller ) 1. If _controller_.[[totalQueuedBytes]] > *0*, 1. Set _controller_.[[closeRequested]] to *true*. 1. Return. - 1. Let _firstPendingPullInto_ be the first element of _controller_.[[pendingPullIntos]]. - 1. If ! ReadableStreamHasBYOBReader(_stream_) is *true*, _controller_.[[pendingPullIntos]] is not empty, and - _firstPendingPullInto_.[[bytesFilled]] > *0*. - 1. Let _e_ be a new *TypeError* exception. - 1. Perform ! ReadableByteStreamControllerError(_controller_, _e_). - 1. Throw _e_. + 1. If _controller_.[[pendingPullIntos]] is not empty, + 1. Let _firstPendingPullInto_ be the first element of _controller_.[[pendingPullIntos]]. + 1. If _firstPendingPullInto_.[[bytesFilled]] > *0*, + 1. Let _e_ be a new *TypeError* exception. + 1. Perform ! ReadableByteStreamControllerError(_controller_, _e_). + 1. Throw _e_. 1. Perform ! ReadableStreamClose(_stream_). diff --git a/reference-implementation/lib/readable-stream.js b/reference-implementation/lib/readable-stream.js index 46c4ad09b..a8d63b7c3 100644 --- a/reference-implementation/lib/readable-stream.js +++ b/reference-implementation/lib/readable-stream.js @@ -1672,14 +1672,14 @@ function ReadableByteStreamControllerClose(controller) { return; } - const firstPendingPullInto = controller._pendingPullIntos[0]; - if (ReadableStreamHasBYOBReader(stream) === true && - controller._pendingPullIntos.length > 0 && - firstPendingPullInto.bytesFilled > 0) { - const e = new TypeError('Insufficient bytes to fill elements in the given buffer'); - ReadableByteStreamControllerError(controller, e); - - throw e; + if (controller._pendingPullIntos.length > 0) { + const firstPendingPullInto = controller._pendingPullIntos[0]; + if (firstPendingPullInto.bytesFilled > 0) { + const e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + + throw e; + } } ReadableStreamClose(stream);