@@ -90,18 +90,35 @@ if (common.hasIntl) {
90
90
}
91
91
92
92
{
93
- const fn = TextDecoder . prototype [ inspect ] ;
94
- assert . doesNotThrow ( ( ) => {
95
- fn . call ( new TextDecoder ( ) , Infinity , { } ) ;
96
- } ) ;
97
-
98
- [ { } , [ ] , true , 1 , '' , new TextEncoder ( ) ] . forEach ( ( i ) => {
99
- assert . throws ( ( ) => fn . call ( i , Infinity , { } ) ,
100
- common . expectsError ( {
101
- code : 'ERR_INVALID_THIS' ,
102
- type : TypeError ,
103
- message : 'Value of "this" must be of type TextDecoder'
104
- } ) ) ;
93
+ const inspectFn = TextDecoder . prototype [ inspect ] ;
94
+ const decodeFn = TextDecoder . prototype . decode ;
95
+ const {
96
+ encoding : { get : encodingGetter } ,
97
+ fatal : { get : fatalGetter } ,
98
+ ignoreBOM : { get : ignoreBOMGetter } ,
99
+ } = Object . getOwnPropertyDescriptors ( TextDecoder . prototype ) ;
100
+
101
+ const instance = new TextDecoder ( ) ;
102
+
103
+ const expectedError = {
104
+ code : 'ERR_INVALID_THIS' ,
105
+ type : TypeError ,
106
+ message : 'Value of "this" must be of type TextDecoder'
107
+ } ;
108
+
109
+ assert . doesNotThrow ( ( ) => inspectFn . call ( instance , Infinity , { } ) ) ;
110
+ assert . doesNotThrow ( ( ) => decodeFn . call ( instance ) ) ;
111
+ assert . doesNotThrow ( ( ) => encodingGetter . call ( instance ) ) ;
112
+ assert . doesNotThrow ( ( ) => fatalGetter . call ( instance ) ) ;
113
+ assert . doesNotThrow ( ( ) => ignoreBOMGetter . call ( instance ) ) ;
114
+
115
+ const invalidThisArgs = [ { } , [ ] , true , 1 , '' , new TextEncoder ( ) ] ;
116
+ invalidThisArgs . forEach ( ( i ) => {
117
+ common . expectsError ( ( ) => inspectFn . call ( i , Infinity , { } ) , expectedError ) ;
118
+ common . expectsError ( ( ) => decodeFn . call ( i ) , expectedError ) ;
119
+ common . expectsError ( ( ) => encodingGetter . call ( i ) , expectedError ) ;
120
+ common . expectsError ( ( ) => fatalGetter . call ( i ) , expectedError ) ;
121
+ common . expectsError ( ( ) => ignoreBOMGetter . call ( i ) , expectedError ) ;
105
122
} ) ;
106
123
}
107
124
0 commit comments