Skip to content

Commit caaf13e

Browse files
committed
[breaking] does not export DataViewIndexOutOfBoundsError (actually RangeError)
1 parent 956e5ce commit caaf13e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/Decoder.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export type DecoderOptions<ContextType = undefined> = Readonly<
2323
/**
2424
* By default, string values will be decoded as UTF-8 strings. However, if this option is true,
2525
* string values will be returned as Uint8Arrays without additional decoding.
26-
*
26+
*
2727
* This is useful if the strings may contain invalid UTF-8 sequences.
28-
*
28+
*
2929
* Note that this option only applies to string values, not map keys. Additionally, when
3030
* enabled, raw string length is limited by the maxBinLength option.
3131
*/
@@ -196,9 +196,8 @@ try {
196196
);
197197
}
198198
}
199-
export const DataViewIndexOutOfBoundsError = RangeError;
200199

201-
const MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
200+
const MORE_DATA = new RangeError("Insufficient data");
202201

203202
const sharedCachedKeyDecoder = new CachedKeyDecoder();
204203

@@ -312,7 +311,7 @@ export class Decoder<ContextType = undefined> {
312311
object = this.doDecodeSync();
313312
decoded = true;
314313
} catch (e) {
315-
if (!(e instanceof DataViewIndexOutOfBoundsError)) {
314+
if (!(e instanceof RangeError)) {
316315
throw e; // rethrow
317316
}
318317
// fallthrough
@@ -368,7 +367,7 @@ export class Decoder<ContextType = undefined> {
368367
}
369368
}
370369
} catch (e) {
371-
if (!(e instanceof DataViewIndexOutOfBoundsError)) {
370+
if (!(e instanceof RangeError)) {
372371
throw e; // rethrow
373372
}
374373
// fallthrough
@@ -657,6 +656,9 @@ export class Decoder<ContextType = undefined> {
657656
return this.decodeBinary(byteLength, headerOffset);
658657
}
659658

659+
/**
660+
* @throws {@link RangeError}
661+
*/
660662
private decodeUtf8String(byteLength: number, headerOffset: number): string {
661663
if (byteLength > this.maxStrLength) {
662664
throw new DecodeError(
@@ -687,6 +689,9 @@ export class Decoder<ContextType = undefined> {
687689
return false;
688690
}
689691

692+
/**
693+
* @throws {@link RangeError}
694+
*/
690695
private decodeBinary(byteLength: number, headOffset: number): Uint8Array {
691696
if (byteLength > this.maxBinLength) {
692697
throw new DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export { decode, decodeMulti };
99
import { decodeAsync, decodeArrayStream, decodeMultiStream } from "./decodeAsync";
1010
export { decodeAsync, decodeArrayStream, decodeMultiStream };
1111

12-
import { Decoder, DataViewIndexOutOfBoundsError } from "./Decoder";
13-
export { Decoder, DataViewIndexOutOfBoundsError };
12+
import { Decoder } from "./Decoder";
13+
export { Decoder };
1414
import type { DecoderOptions } from "./Decoder";
1515
export type { DecoderOptions };
1616
import { DecodeError } from "./DecodeError";

test/edge-cases.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// any errors should not break Encoder/Decoder instance states
33
import assert from "assert";
44
import { encode, decodeAsync, decode, Encoder, Decoder, decodeMulti, decodeMultiStream } from "../src/index";
5-
import { DataViewIndexOutOfBoundsError } from "../src/Decoder";
65

76
function testEncoder(encoder: Encoder): void {
87
const object = {
@@ -91,8 +90,7 @@ describe("edge cases", () => {
9190
0x92, // fixarray size=2
9291
0xc0, // nil
9392
]);
94-
// [IE11] A raw error thrown by DataView
95-
}, DataViewIndexOutOfBoundsError);
93+
}, RangeError);
9694
testDecoder(decoder);
9795
});
9896

0 commit comments

Comments
 (0)