Skip to content

Commit 7cff993

Browse files
committed
add sanity check for Decoder
1 parent d6c1319 commit 7cff993

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Decoder.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ const HEAD_BYTE_REQUIRED = -1;
3838
const EMPTY_VIEW = new DataView(new ArrayBuffer(0));
3939
const EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
4040

41+
try {
42+
// IE11: The spec says it should throw RangeError,
43+
// IE11: but in IE11 it throws TypeError.
44+
EMPTY_VIEW.getInt8(0);
45+
} catch (e) {
46+
if (!(e instanceof RangeError)) {
47+
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
48+
}
49+
}
4150
export const DataViewIndexOutOfBoundsError = RangeError;
51+
4252
const MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
4353

4454
const sharedCachedKeyDecoder = new CachedKeyDecoder();

0 commit comments

Comments
 (0)