3
3
const { labelToName, isSupported, decode } = require ( "./whatwg-encoding" ) ;
4
4
5
5
exports . implementation = class TextDecoderImpl {
6
- constructor ( globalObject , constructorArgs = [ ] ) {
7
- const label = constructorArgs [ 0 ] ;
8
- const options = constructorArgs [ 1 ] || { } ;
9
-
6
+ constructor ( globalObject , [ label , options = { } ] ) {
10
7
const encoding = labelToName ( label ) ;
11
- if ( ! isSupported ( encoding ) || encoding === "replacement" ) {
12
- throw new RangeError ( `"${ encoding } " is not a supported encoding name` ) ;
8
+ if ( encoding === null || ! isSupported ( encoding ) || encoding === "replacement" ) {
9
+ throw new RangeError ( `"${ label } " is not a supported encoding name` ) ;
13
10
}
14
11
this . _encoding = encoding ;
15
- this . _errorMode = options . _fatal ? "fatal" : "replacement" ;
16
- this . _ignoreBOM = options . _ignoreBOM || false ;
12
+ this . _errorMode = options . fatal === true ? "fatal" : "replacement" ;
13
+ this . _ignoreBOM = options . ignoreBOM || false ;
17
14
}
18
15
19
16
get encoding ( ) {
20
- return String ( this . _encoding ) . toLowerCase ( ) ;
17
+ return this . _encoding . toLowerCase ( ) ;
21
18
}
22
19
23
20
get fatal ( ) {
@@ -29,12 +26,12 @@ exports.implementation = class TextDecoderImpl {
29
26
}
30
27
31
28
decode ( input , options = { } ) {
32
- if ( options . steam === true ) {
29
+ if ( options . stream === true ) {
33
30
// TODO: Implement stream support
34
31
}
35
32
try {
36
33
// TODO: Implement ignoreBOM support
37
- return decode ( Buffer . from ( input ) , this . _encoding ) ;
34
+ return decode ( Buffer . from ( input ) , this . _encoding , this . _ignoreBOM ) ;
38
35
} catch ( exception ) {
39
36
if ( this . _errorMode === "fatal" ) {
40
37
throw new TypeError ( exception ) ;
0 commit comments