@@ -2433,44 +2433,6 @@ IdlInterface.prototype.test_to_json_operation = function(desc, memberHolderObjec
2433
2433
}
2434
2434
} ;
2435
2435
2436
- IdlInterface . prototype . test_member_iterable = function ( member )
2437
- {
2438
- subsetTestByKey ( this . name , test , function ( )
2439
- {
2440
- var isPairIterator = member . idlType . length === 2 ;
2441
- var proto = this . get_interface_object ( ) . prototype ;
2442
- var iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . iterator ) ;
2443
-
2444
- assert_true ( iteratorDesc . writable , "@@iterator property should be writable" ) ;
2445
- assert_true ( iteratorDesc . configurable , "@@iterator property should be configurable" ) ;
2446
- assert_false ( iteratorDesc . enumerable , "@@iterator property should not be enumerable" ) ;
2447
- assert_equals ( typeof iteratorDesc . value , "function" , "@@iterator property should be a function" ) ;
2448
- assert_equals ( iteratorDesc . value . length , 0 , "@@iterator function object length should be 0" ) ;
2449
- assert_equals ( iteratorDesc . value . name , isPairIterator ? "entries" : "values" , "@@iterator function object should have the right name" ) ;
2450
-
2451
- if ( isPairIterator ) {
2452
- assert_equals ( proto [ "entries" ] , proto [ Symbol . iterator ] , "entries method should be the same as @@iterator method" ) ;
2453
- [
2454
- [ "entries" , 0 ] ,
2455
- [ "keys" , 0 ] ,
2456
- [ "values" , 0 ] ,
2457
- [ "forEach" , 1 ]
2458
- ] . forEach ( ( [ property , length ] ) => {
2459
- var desc = Object . getOwnPropertyDescriptor ( proto , property ) ;
2460
- assert_equals ( typeof desc . value , "function" , property + " property should be a function" ) ;
2461
- assert_equals ( desc . value . length , length , property + " function object should have the right length" ) ;
2462
- assert_equals ( desc . value . name , property , property + " function object should have the right name" ) ;
2463
- } ) ;
2464
- } else {
2465
- assert_equals ( proto [ Symbol . iterator ] , Array . prototype [ Symbol . iterator ] , "@@iterator method should be the same as Array prototype's" ) ;
2466
- [ "entries" , "keys" , "values" , "forEach" , Symbol . iterator ] . forEach ( property => {
2467
- var propertyName = property === Symbol . iterator ? "@@iterator" : property ;
2468
- assert_equals ( proto [ property ] , Array . prototype [ property ] , propertyName + " method should be the same as Array prototype's" ) ;
2469
- } ) ;
2470
- }
2471
- } . bind ( this ) , this . name + " interface: iterable<" + member . idlType . map ( function ( t ) { return t . idlType ; } ) . join ( ", " ) + ">" ) ;
2472
- } ;
2473
-
2474
2436
IdlInterface . prototype . test_member_maplike = function ( member ) {
2475
2437
subsetTestByKey ( this . name , test , ( ) => {
2476
2438
const proto = this . get_interface_object ( ) . prototype ;
@@ -2562,35 +2524,85 @@ IdlInterface.prototype.test_member_setlike = function(member) {
2562
2524
} , `${ this . name } interface: setlike<${ member . idlType . map ( t => t . idlType ) . join ( ", " ) } >` ) ;
2563
2525
} ;
2564
2526
2565
- IdlInterface . prototype . test_member_async_iterable = function ( member )
2566
- {
2567
- subsetTestByKey ( this . name , test , function ( )
2568
- {
2569
- var isPairIterator = member . idlType . length === 2 ;
2570
- var proto = this . get_interface_object ( ) . prototype ;
2571
- var iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . asyncIterator ) ;
2527
+ IdlInterface . prototype . test_member_iterable = function ( member ) {
2528
+ subsetTestByKey ( this . name , test , ( ) => {
2529
+ const isPairIterator = member . idlType . length === 2 ;
2530
+ const proto = this . get_interface_object ( ) . prototype ;
2572
2531
2573
- assert_true ( iteratorDesc . writable , "@@asyncIterator property should be writable" ) ;
2574
- assert_true ( iteratorDesc . configurable , "@@asyncIterator property should be configurable" ) ;
2575
- assert_false ( iteratorDesc . enumerable , "@@asyncIterator property should not be enumerable" ) ;
2576
- assert_equals ( typeof iteratorDesc . value , "function" , "@@asyncIterator property should be a function" ) ;
2577
- assert_equals ( iteratorDesc . value . length , 0 , "@@asyncIterator function object length should be 0" ) ;
2578
- assert_equals ( iteratorDesc . value . name , isPairIterator ? "entries" : "values" , "@@asyncIterator function object should have the right name" ) ;
2532
+ const methods = [
2533
+ [ "entries" , 0 ] ,
2534
+ [ "keys" , 0 ] ,
2535
+ [ "values" , 0 ] ,
2536
+ [ "forEach" , 1 ]
2537
+ ] ;
2538
+
2539
+ for ( const [ name , length ] of methods ) {
2540
+ const desc = Object . getOwnPropertyDescriptor ( proto , name ) ;
2541
+ assert_equals ( typeof desc . value , "function" , `${ name } should be a function` ) ;
2542
+ assert_equals ( desc . enumerable , true , `${ name } enumerable` ) ;
2543
+ assert_equals ( desc . configurable , true , `${ name } configurable` ) ;
2544
+ assert_equals ( desc . writable , true , `${ name } writable` ) ;
2545
+ assert_equals ( desc . value . length , length , `${ name } function object length should be ${ length } ` ) ;
2546
+ assert_equals ( desc . value . name , name , `${ name } function object should have the right name` ) ;
2547
+
2548
+ if ( ! isPairIterator ) {
2549
+ assert_equals ( desc . value , Array . prototype [ name ] , `${ name } equality with Array.prototype version` ) ;
2550
+ }
2551
+ }
2552
+
2553
+ const iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . iterator ) ;
2554
+ assert_equals ( iteratorDesc . enumerable , false , `@@iterator enumerable` ) ;
2555
+ assert_equals ( iteratorDesc . configurable , true , `@@iterator configurable` ) ;
2556
+ assert_equals ( iteratorDesc . writable , true , `@@iterator writable` ) ;
2579
2557
2580
2558
if ( isPairIterator ) {
2581
- assert_equals ( proto [ "entries" ] , proto [ Symbol . asyncIterator ] , "entries method should be the same as @@asyncIterator method" ) ;
2582
- [ "entries" , "keys" , "values" ] . forEach ( property => {
2583
- var desc = Object . getOwnPropertyDescriptor ( proto , property ) ;
2584
- assert_equals ( typeof desc . value , "function" , property + " property should be a function" ) ;
2585
- assert_equals ( desc . value . length , 0 , property + " function object length should be 0" ) ;
2586
- assert_equals ( desc . value . name , property , property + " function object should have the right name" ) ;
2587
- } ) ;
2559
+ assert_equals ( iteratorDesc . value , proto . entries , `@@iterator equality with entries` ) ;
2560
+ } else {
2561
+ assert_equals ( iteratorDesc . value , Array . prototype [ Symbol . iterator ] , `@@iterator equality with Array.prototype version` ) ;
2562
+ }
2563
+ } , `${ this . name } interface: iterable<${ member . idlType . map ( t => t . idlType ) . join ( ", " ) } >` ) ;
2564
+ } ;
2565
+
2566
+ IdlInterface . prototype . test_member_async_iterable = function ( member ) {
2567
+ subsetTestByKey ( this . name , test , ( ) => {
2568
+ const isPairIterator = member . idlType . length === 2 ;
2569
+ const proto = this . get_interface_object ( ) . prototype ;
2570
+
2571
+ // Note that although the spec allows arguments, which will be passed to the @@asyncIterator
2572
+ // method (which is either values or entries), those arguments must always be optional. So
2573
+ // length of 0 is still correct for values and entries.
2574
+ const methods = [
2575
+ [ "values" , 0 ] ,
2576
+ ] ;
2577
+
2578
+ if ( isPairIterator ) {
2579
+ methods . push (
2580
+ [ "entries" , 0 ] ,
2581
+ [ "keys" , 0 ]
2582
+ ) ;
2583
+ }
2584
+
2585
+ for ( const [ name , length ] of methods ) {
2586
+ const desc = Object . getOwnPropertyDescriptor ( proto , name ) ;
2587
+ assert_equals ( typeof desc . value , "function" , `${ name } should be a function` ) ;
2588
+ assert_equals ( desc . enumerable , true , `${ name } enumerable` ) ;
2589
+ assert_equals ( desc . configurable , true , `${ name } configurable` ) ;
2590
+ assert_equals ( desc . writable , true , `${ name } writable` ) ;
2591
+ assert_equals ( desc . value . length , length , `${ name } function object length should be ${ length } ` ) ;
2592
+ assert_equals ( desc . value . name , name , `${ name } function object should have the right name` ) ;
2593
+ }
2594
+
2595
+ const iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . asyncIterator ) ;
2596
+ assert_equals ( iteratorDesc . enumerable , false , `@@iterator enumerable` ) ;
2597
+ assert_equals ( iteratorDesc . configurable , true , `@@iterator configurable` ) ;
2598
+ assert_equals ( iteratorDesc . writable , true , `@@iterator writable` ) ;
2599
+
2600
+ if ( isPairIterator ) {
2601
+ assert_equals ( iteratorDesc . value , proto . entries , `@@iterator equality with entries` ) ;
2588
2602
} else {
2589
- assert_equals ( proto [ "values" ] , proto [ Symbol . asyncIterator ] , "values method should be the same as @@asyncIterator method" ) ;
2590
- assert_false ( "entries" in proto , "should not have an entries method" ) ;
2591
- assert_false ( "keys" in proto , "should not have a keys method" ) ;
2603
+ assert_equals ( iteratorDesc . value , proto . values , `@@iterator equality with values` ) ;
2592
2604
}
2593
- } . bind ( this ) , this . name + " interface: async iterable<" + member . idlType . map ( function ( t ) { return t . idlType ; } ) . join ( ", " ) + ">" ) ;
2605
+ } , ` ${ this . name } interface: async iterable<${ member . idlType . map ( t => t . idlType ) . join ( ", " ) } >` ) ;
2594
2606
} ;
2595
2607
2596
2608
IdlInterface . prototype . test_member_stringifier = function ( member )
0 commit comments