@@ -12,6 +12,7 @@ const {
1212 NumberMAX_SAFE_INTEGER,
1313 NumberMIN_SAFE_INTEGER,
1414 ObjectAssign,
15+ ObjectPrototypeIsPrototypeOf,
1516 SafeSet,
1617 String,
1718 SymbolIterator,
@@ -20,6 +21,7 @@ const {
2021
2122const {
2223 codes : {
24+ ERR_INVALID_ARG_TYPE ,
2325 ERR_INVALID_ARG_VALUE ,
2426 } ,
2527} = require ( 'internal/errors' ) ;
@@ -275,20 +277,34 @@ function createSequenceConverter(converter) {
275277 const val = converter ( res . value , {
276278 __proto__ : null ,
277279 ...opts ,
278- context : `${ opts . context } , index ${ array . length } ` ,
280+ context : `${ opts . context } [ ${ array . length } ] ` ,
279281 } ) ;
280282 ArrayPrototypePush ( array , val ) ;
281283 } ;
282284 return array ;
283285 } ;
284286}
285287
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+
286301
287302module . exports = {
288303 type,
289304 converters,
290305 convertToInt,
291306 createEnumConverter,
307+ createInterfaceConverter,
292308 createSequenceConverter,
293309 evenRound,
294310 makeException,
0 commit comments