From a11b7341a1f2b32d05ba2794c738ed65043d1a3b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 11 Sep 2020 13:11:40 +0200 Subject: [PATCH] Ensure that the `length` property won't be *accidentally* accessed on a `DecodeStream`-instance For these streams, compared to `Stream` and `ChunkedStream`, there's no well defined concept of length and consequently no `length` getter.[1] However, attempting to access the non-existent `length` won't currently error, but just return `undefined`, which could thus easily lead to bugs elsewhere in the code-base. --- [1] However, note that *all* stream implementations have an `isEmpty` getter which can be used instead. --- src/core/stream.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/stream.js b/src/core/stream.js index 0b5d5e1f6375d..03c827d82bd41 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -167,6 +167,11 @@ var DecodeStream = (function DecodeStreamClosure() { } DecodeStream.prototype = { + // eslint-disable-next-line getter-return + get length() { + unreachable("Should not access DecodeStream.length"); + }, + get isEmpty() { while (!this.eof && this.bufferLength === 0) { this.readBlock();