@@ -1016,6 +1016,86 @@ describe("Float16Array", () => {
10161016 } ) ;
10171017 } ) ;
10181018
1019+ describe ( "#filterReject()" , ( ) => {
1020+ it ( "property `name` is 'filterReject'" , ( ) => {
1021+ assert ( Float16Array . prototype . filterReject . name === "filterReject" ) ;
1022+ } ) ;
1023+
1024+ it ( "property `length` is 1" , ( ) => {
1025+ assert ( Float16Array . prototype . filterReject . length === 1 ) ;
1026+ } ) ;
1027+
1028+ it ( "check callback arguments" , ( ) => {
1029+ const float16 = new Float16Array ( [ 1 ] ) ;
1030+ const thisArg = { } ;
1031+
1032+ float16 . filterReject ( function ( val , key , f16 ) {
1033+ assert ( val === 1 ) ;
1034+ assert ( key === 0 ) ;
1035+ assert ( f16 === float16 ) ;
1036+ assert ( this === thisArg ) ;
1037+ } , thisArg ) ;
1038+ } ) ;
1039+
1040+ it ( "reject even value" , ( ) => {
1041+ const float16_1 = new Float16Array ( [ 1 , 2 , 3 , 4 ] ) ;
1042+ const float16_2 = float16_1 . filterReject ( ( val ) => val % 2 === 0 ) ;
1043+
1044+ assert ( float16_2 instanceof Float16Array ) ;
1045+ assert . equalFloat16ArrayValues ( float16_2 , [ 1 , 3 ] ) ;
1046+ } ) ;
1047+
1048+ it ( "respect @@species" , ( ) => {
1049+ let step = 0 ;
1050+ class Foo extends Float16Array {
1051+ constructor ( ...args ) {
1052+ super ( ...args ) ;
1053+ if ( step === 0 ) {
1054+ assert ( args . length === 1 ) ;
1055+ assert . deepStrictEqual ( args [ 0 ] , [ 1 , 2 , 3 , 4 ] ) ;
1056+ ++ step ;
1057+ } else {
1058+ assert ( args . length === 1 ) ;
1059+ assert . deepStrictEqual ( args [ 0 ] , [ 1 , 2 , 3 , 4 ] ) ;
1060+ }
1061+ }
1062+ }
1063+ const foo = new Foo ( [ 1 , 2 , 3 , 4 ] ) . filterReject ( ( ) => false ) ;
1064+ assert ( foo instanceof Foo ) ;
1065+ assert . equalFloat16ArrayValues ( foo , [ 1 , 2 , 3 , 4 ] ) ;
1066+
1067+ class Bar extends Float16Array {
1068+ static get [ Symbol . species ] ( ) {
1069+ return Float16Array ;
1070+ }
1071+ }
1072+ const bar = new Bar ( [ 1 , 2 , 3 , 4 ] ) . filterReject ( ( ) => false ) ;
1073+ assert ( ! ( bar instanceof Bar ) ) ;
1074+ assert ( bar instanceof Float16Array ) ;
1075+ assert . equalFloat16ArrayValues ( bar , [ 1 , 2 , 3 , 4 ] ) ;
1076+ } ) ;
1077+
1078+ it ( "SpeciesConstructor must return a TypedArray of the same Content Type" , function ( ) {
1079+ class Foo extends Float16Array {
1080+ static get [ Symbol . species ] ( ) {
1081+ return Array ;
1082+ }
1083+ }
1084+ const foo = new Foo ( [ 1 , 2 , 3 , 4 ] ) ;
1085+ assert . throws ( ( ) => foo . filterReject ( ( ) => true ) , TypeError ) ;
1086+
1087+ if ( typeof BigUint64Array !== "undefined" ) {
1088+ class Bar extends Float16Array {
1089+ static get [ Symbol . species ] ( ) {
1090+ return BigUint64Array ;
1091+ }
1092+ }
1093+ const bar = new Bar ( [ 1 , 2 , 3 , 4 ] ) ;
1094+ assert . throws ( ( ) => bar . filterReject ( ( ) => true ) , TypeError ) ;
1095+ }
1096+ } ) ;
1097+ } ) ;
1098+
10191099 describe ( "#reduce()" , ( ) => {
10201100 it ( "property `name` is 'reduce'" , ( ) => {
10211101 assert ( Float16Array . prototype . reduce . name === "reduce" ) ;
0 commit comments