@@ -9,41 +9,43 @@ const { Buffer } = require('buffer');
99const assert = require ( 'assert' ) ;
1010const { getRandomValues } = require ( 'crypto' ) . webcrypto ;
1111
12- [ undefined , null , '' , 1 , { } , [ ] ] . forEach ( ( i ) => {
13- assert . throws ( ( ) => getRandomValues ( i ) , { code : 17 } ) ;
12+ [
13+ undefined , null , '' , 1 , { } , [ ] ,
14+ new Float32Array ( 1 ) ,
15+ new Float64Array ( 1 ) ,
16+ ] . forEach ( ( i ) => {
17+ assert . throws (
18+ ( ) => getRandomValues ( i ) ,
19+ { name : 'TypeMismatchError' , code : 17 } ,
20+ ) ;
1421} ) ;
1522
1623{
1724 const buf = new Uint8Array ( 0 ) ;
1825 getRandomValues ( buf ) ;
1926}
2027
21- {
22- const buf = new Uint8Array ( new Array ( 10 ) . fill ( 0 ) ) ;
23- const before = Buffer . from ( buf ) . toString ( 'hex' ) ;
24- getRandomValues ( buf ) ;
25- const after = Buffer . from ( buf ) . toString ( 'hex' ) ;
26- assert . notStrictEqual ( before , after ) ;
27- }
28-
29- {
30- const buf = new Uint16Array ( new Array ( 10 ) . fill ( 0 ) ) ;
31- const before = Buffer . from ( buf ) . toString ( 'hex' ) ;
32- getRandomValues ( buf ) ;
33- const after = Buffer . from ( buf ) . toString ( 'hex' ) ;
34- assert . notStrictEqual ( before , after ) ;
35- }
28+ const intTypedConstructors = [
29+ Int8Array ,
30+ Int16Array ,
31+ Int32Array ,
32+ Uint8Array ,
33+ Uint16Array ,
34+ Uint32Array ,
35+ BigInt64Array ,
36+ BigUint64Array ,
37+ ] ;
3638
37- {
38- const buf = new Uint32Array ( new Array ( 10 ) . fill ( 0 ) ) ;
39- const before = Buffer . from ( buf ) . toString ( 'hex' ) ;
39+ for ( const ctor of intTypedConstructors ) {
40+ const buf = new ctor ( 10 ) ;
41+ const before = Buffer . from ( buf . buffer ) . toString ( 'hex' ) ;
4042 getRandomValues ( buf ) ;
41- const after = Buffer . from ( buf ) . toString ( 'hex' ) ;
43+ const after = Buffer . from ( buf . buffer ) . toString ( 'hex' ) ;
4244 assert . notStrictEqual ( before , after ) ;
4345}
4446
4547{
46- const buf = new Uint16Array ( new Array ( 10 ) . fill ( 0 ) ) ;
48+ const buf = new Uint16Array ( 10 ) ;
4749 const before = Buffer . from ( buf ) . toString ( 'hex' ) ;
4850 getRandomValues ( new DataView ( buf . buffer ) ) ;
4951 const after = Buffer . from ( buf ) . toString ( 'hex' ) ;
0 commit comments