@@ -4,6 +4,7 @@ import { getInt64, getUint64 } from "./utils/int";
4
4
import { utf8DecodeJs , TEXT_DECODER_THRESHOLD , utf8DecodeTD } from "./utils/utf8" ;
5
5
import { createDataView , ensureUint8Array } from "./utils/typedArrays" ;
6
6
import { CachedKeyDecoder , KeyDecoder } from "./CachedKeyDecoder" ;
7
+ import { DecodeError } from "./DecodeError" ;
7
8
8
9
const enum State {
9
10
ARRAY ,
@@ -60,22 +61,6 @@ const DEFAULT_MAX_LENGTH = 0xffff_ffff; // uint32_max
60
61
61
62
const sharedCachedKeyDecoder = new CachedKeyDecoder ( ) ;
62
63
63
- export class DecodeError extends Error {
64
- constructor ( message : string ) {
65
- super ( message ) ;
66
-
67
- // fix the prototype chain in a cross-platform way
68
- const proto : typeof DecodeError . prototype = Object . create ( DecodeError . prototype ) ;
69
- Object . setPrototypeOf ( this , proto ) ;
70
-
71
- Object . defineProperty ( this , "name" , {
72
- configurable : true ,
73
- enumerable : false ,
74
- value : DecodeError . name ,
75
- } ) ;
76
- }
77
- }
78
-
79
64
export class Decoder < ContextType = undefined > {
80
65
private totalPos = 0 ;
81
66
private pos = 0 ;
@@ -133,6 +118,10 @@ export class Decoder<ContextType = undefined> {
133
118
return new RangeError ( `Extra ${ view . byteLength - pos } of ${ view . byteLength } byte(s) found at buffer[${ posToShow } ]` ) ;
134
119
}
135
120
121
+ /**
122
+ * @throws {DecodeError }
123
+ * @throws {RangeError }
124
+ */
136
125
public decode ( buffer : ArrayLike < number > | BufferSource ) : unknown {
137
126
this . reinitializeState ( ) ;
138
127
this . setBuffer ( buffer ) ;
0 commit comments