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