@@ -1529,12 +1529,12 @@ IdlInterface.prototype.test_self = function()
1529
1529
// https://github.com/heycam/webidl/issues/698
1530
1530
assert_true ( isConstructor ( this . get_interface_object ( ) ) , "interface object must pass IsConstructor check" ) ;
1531
1531
1532
+ var interface_object = this . get_interface_object ( ) ;
1533
+ assert_throws_js ( globalOf ( interface_object ) . TypeError , function ( ) {
1534
+ interface_object ( ) ;
1535
+ } , "interface object didn't throw TypeError when called as a function" ) ;
1536
+
1532
1537
if ( ! this . constructors ( ) . length ) {
1533
- // "If I was not declared with a constructor operation, then throw a TypeError."
1534
- var interface_object = this . get_interface_object ( ) ;
1535
- assert_throws_js ( globalOf ( interface_object ) . TypeError , function ( ) {
1536
- interface_object ( ) ;
1537
- } , "interface object didn't throw TypeError when called as a function" ) ;
1538
1538
assert_throws_js ( globalOf ( interface_object ) . TypeError , function ( ) {
1539
1539
new interface_object ( ) ;
1540
1540
} , "interface object didn't throw TypeError when called as a constructor" ) ;
@@ -2458,7 +2458,7 @@ IdlInterface.prototype.test_member_iterable = function(member)
2458
2458
] . forEach ( ( [ property , length ] ) => {
2459
2459
var desc = Object . getOwnPropertyDescriptor ( proto , property ) ;
2460
2460
assert_equals ( typeof desc . value , "function" , property + " property should be a function" ) ;
2461
- assert_equals ( desc . value . length , length , property + " function object length should be " + length ) ;
2461
+ assert_equals ( desc . value . length , length , property + " function object should have the right length" ) ;
2462
2462
assert_equals ( desc . value . name , property , property + " function object should have the right name" ) ;
2463
2463
} ) ;
2464
2464
} else {
@@ -2471,6 +2471,97 @@ IdlInterface.prototype.test_member_iterable = function(member)
2471
2471
} . bind ( this ) , this . name + " interface: iterable<" + member . idlType . map ( function ( t ) { return t . idlType ; } ) . join ( ", " ) + ">" ) ;
2472
2472
} ;
2473
2473
2474
+ IdlInterface . prototype . test_member_maplike = function ( member ) {
2475
+ subsetTestByKey ( this . name , test , ( ) => {
2476
+ const proto = this . get_interface_object ( ) . prototype ;
2477
+
2478
+ const methods = [
2479
+ [ "entries" , 0 ] ,
2480
+ [ "keys" , 0 ] ,
2481
+ [ "values" , 0 ] ,
2482
+ [ "forEach" , 1 ] ,
2483
+ [ "get" , 1 ] ,
2484
+ [ "has" , 1 ]
2485
+ ] ;
2486
+ if ( ! member . readonly ) {
2487
+ methods . push (
2488
+ [ "set" , 2 ] ,
2489
+ [ "delete" , 1 ] ,
2490
+ [ "clear" , 1 ]
2491
+ ) ;
2492
+ }
2493
+
2494
+ for ( const [ name , length ] of methods ) {
2495
+ const desc = Object . getOwnPropertyDescriptor ( proto , name ) ;
2496
+ assert_equals ( typeof desc . value , "function" , `${ name } should be a function` ) ;
2497
+ assert_equals ( desc . enumerable , false , `${ name } enumerable` ) ;
2498
+ assert_equals ( desc . configurable , true , `${ name } configurable` ) ;
2499
+ assert_equals ( desc . writable , true , `${ name } writable` ) ;
2500
+ assert_equals ( desc . value . length , length , `${ name } function object length should be ${ length } ` ) ;
2501
+ assert_equals ( desc . value . name , name , `${ name } function object should have the right name` ) ;
2502
+ }
2503
+
2504
+ const iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . iterator ) ;
2505
+ assert_equals ( iteratorDesc . value , proto . entries , `@@iterator should equal entries` ) ;
2506
+ assert_equals ( iteratorDesc . enumerable , false , `@@iterator enumerable` ) ;
2507
+ assert_equals ( iteratorDesc . configurable , true , `@@iterator configurable` ) ;
2508
+ assert_equals ( iteratorDesc . writable , true , `@@iterator writable` ) ;
2509
+
2510
+ const sizeDesc = Object . getOwnPropertyDescriptor ( proto , "size" ) ;
2511
+ assert_equals ( typeof sizeDesc . get , "function" , `size getter should be a function` ) ;
2512
+ assert_equals ( sizeDesc . set , undefined , `size should not have a setter` ) ;
2513
+ assert_equals ( sizeDesc . enumerable , false , `size enumerable` ) ;
2514
+ assert_equals ( sizeDesc . configurable , true , `size configurable` ) ;
2515
+ assert_equals ( sizeDesc . get . length , 0 , `size getter length should have the right length` ) ;
2516
+ assert_equals ( sizeDesc . get . name , "get size" , `size getter have the right name` ) ;
2517
+ } , `${ this . name } interface: maplike<${ member . idlType . map ( t => t . idlType ) . join ( ", " ) } >` ) ;
2518
+ } ;
2519
+
2520
+ IdlInterface . prototype . test_member_setlike = function ( member ) {
2521
+ subsetTestByKey ( this . name , test , ( ) => {
2522
+ const proto = this . get_interface_object ( ) . prototype ;
2523
+
2524
+ const methods = [
2525
+ [ "entries" , 0 ] ,
2526
+ [ "keys" , 0 ] ,
2527
+ [ "values" , 0 ] ,
2528
+ [ "forEach" , 1 ] ,
2529
+ [ "has" , 1 ]
2530
+ ] ;
2531
+ if ( ! member . readonly ) {
2532
+ methods . push (
2533
+ [ "add" , 1 ] ,
2534
+ [ "delete" , 1 ] ,
2535
+ [ "clear" , 1 ]
2536
+ ) ;
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 , false , `${ 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
+
2549
+ const iteratorDesc = Object . getOwnPropertyDescriptor ( proto , Symbol . iterator ) ;
2550
+ assert_equals ( iteratorDesc . value , proto . values , `@@iterator should equal values` ) ;
2551
+ assert_equals ( iteratorDesc . enumerable , false , `@@iterator enumerable` ) ;
2552
+ assert_equals ( iteratorDesc . configurable , true , `@@iterator configurable` ) ;
2553
+ assert_equals ( iteratorDesc . writable , true , `@@iterator writable` ) ;
2554
+
2555
+ const sizeDesc = Object . getOwnPropertyDescriptor ( proto , "size" ) ;
2556
+ assert_equals ( typeof sizeDesc . get , "function" , `size getter should be a function` ) ;
2557
+ assert_equals ( sizeDesc . set , undefined , `size should not have a setter` ) ;
2558
+ assert_equals ( sizeDesc . enumerable , false , `size enumerable` ) ;
2559
+ assert_equals ( sizeDesc . configurable , true , `size configurable` ) ;
2560
+ assert_equals ( sizeDesc . get . length , 0 , `size getter length should have the right length` ) ;
2561
+ assert_equals ( sizeDesc . get . name , "size" , `size getter have the right name` ) ;
2562
+ } , `${ this . name } interface: setlike<${ member . idlType . map ( t => t . idlType ) . join ( ", " ) } >` ) ;
2563
+ } ;
2564
+
2474
2565
IdlInterface . prototype . test_member_async_iterable = function ( member )
2475
2566
{
2476
2567
subsetTestByKey ( this . name , test , function ( )
@@ -2624,6 +2715,12 @@ IdlInterface.prototype.test_members = function()
2624
2715
this . test_member_iterable ( member ) ;
2625
2716
}
2626
2717
break ;
2718
+ case "maplike" :
2719
+ this . test_member_maplike ( member ) ;
2720
+ break ;
2721
+ case "setlike" :
2722
+ this . test_member_setlike ( member ) ;
2723
+ break ;
2627
2724
default :
2628
2725
// TODO: check more member types.
2629
2726
break ;
0 commit comments