@@ -12,6 +12,7 @@ const {
12
12
NumberMAX_SAFE_INTEGER,
13
13
NumberMIN_SAFE_INTEGER,
14
14
ObjectAssign,
15
+ ObjectPrototypeIsPrototypeOf,
15
16
SafeSet,
16
17
String,
17
18
SymbolIterator,
@@ -20,6 +21,7 @@ const {
20
21
21
22
const {
22
23
codes : {
24
+ ERR_INVALID_ARG_TYPE ,
23
25
ERR_INVALID_ARG_VALUE ,
24
26
} ,
25
27
} = require ( 'internal/errors' ) ;
@@ -275,20 +277,34 @@ function createSequenceConverter(converter) {
275
277
const val = converter ( res . value , {
276
278
__proto__ : null ,
277
279
...opts ,
278
- context : `${ opts . context } , index ${ array . length } ` ,
280
+ context : `${ opts . context } [ ${ array . length } ] ` ,
279
281
} ) ;
280
282
ArrayPrototypePush ( array , val ) ;
281
283
} ;
282
284
return array ;
283
285
} ;
284
286
}
285
287
288
+ // https://webidl.spec.whatwg.org/#js-interface
289
+ function createInterfaceConverter ( name , I ) {
290
+ return ( V , opts = kEmptyObject ) => {
291
+ // 1. If V implements I, then return the IDL interface type value that
292
+ // represents a reference to that platform object.
293
+ if ( ObjectPrototypeIsPrototypeOf ( I , V ) ) return V ;
294
+ // 2. Throw a TypeError.
295
+ throw new ERR_INVALID_ARG_TYPE (
296
+ typeof opts . context === 'string' ? opts . context : 'value' , name , V ,
297
+ ) ;
298
+ } ;
299
+ }
300
+
286
301
287
302
module . exports = {
288
303
type,
289
304
converters,
290
305
convertToInt,
291
306
createEnumConverter,
307
+ createInterfaceConverter,
292
308
createSequenceConverter,
293
309
evenRound,
294
310
makeException,
0 commit comments