@@ -9,7 +9,7 @@ use mozjs::jsval::UndefinedValue;
9
9
use mozjs:: rooted;
10
10
use mozjs:: rust:: { JSEngine , RealmOptions , Runtime , SIMPLE_GLOBAL_CLASS } ;
11
11
use mozjs:: typedarray;
12
- use mozjs:: typedarray:: { CreateWith , Uint32Array } ;
12
+ use mozjs:: typedarray:: { CreateWith , Float32Array , Uint32Array } ;
13
13
14
14
#[ test]
15
15
fn typedarray ( ) {
@@ -42,7 +42,7 @@ fn typedarray() {
42
42
assert ! ( rval. is_object( ) ) ;
43
43
44
44
typedarray ! ( in( context) let array: Uint8Array = rval. to_object( ) ) ;
45
- assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 0 , 2 , 4 ] [ .. ] ) ;
45
+ assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 0 , 2 , 4 ] ) ;
46
46
47
47
typedarray ! ( in( context) let array: Uint8Array = rval. to_object( ) ) ;
48
48
assert_eq ! ( array. unwrap( ) . len( ) , 3 ) ;
@@ -62,11 +62,11 @@ fn typedarray() {
62
62
) ;
63
63
64
64
typedarray ! ( in( context) let array: Uint32Array = rval. get( ) ) ;
65
- assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 1 , 3 , 5 ] [ .. ] ) ;
65
+ assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 1 , 3 , 5 ] ) ;
66
66
67
67
typedarray ! ( in( context) let mut array: Uint32Array = rval. get( ) ) ;
68
68
array. as_mut ( ) . unwrap ( ) . update ( & [ 2 , 4 , 6 ] ) ;
69
- assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 2 , 4 , 6 ] [ .. ] ) ;
69
+ assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 2 , 4 , 6 ] ) ;
70
70
71
71
rooted ! ( in( context) let rval = ptr:: null_mut:: <JSObject >( ) ) ;
72
72
typedarray ! ( in( context) let array: Uint8Array = rval. get( ) ) ;
@@ -87,5 +87,15 @@ fn typedarray() {
87
87
88
88
typedarray ! ( in( context) let view: ArrayBufferView = rval. get( ) ) ;
89
89
assert_eq ! ( view. unwrap( ) . is_shared( ) , false ) ;
90
+
91
+ rooted ! ( in( context) let mut rval = ptr:: null_mut:: <JSObject >( ) ) ;
92
+ assert ! ( Float32Array :: create( context, CreateWith :: Slice ( & [ 0.25 , 0.5 , 1.0 , 2.0 , 4.0 ] ) , rval. handle_mut( ) ) . is_ok( ) ) ;
93
+
94
+ typedarray ! ( in( context) let array: Float32Array = rval. get( ) ) ;
95
+ assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 0.25 , 0.5 , 1.0 , 2.0 , 4.0 ] ) ;
96
+
97
+ typedarray ! ( in( context) let mut array: Float32Array = rval. get( ) ) ;
98
+ array. as_mut ( ) . unwrap ( ) . update ( & [ 0.5 , 1.0 , 2.0 ] ) ;
99
+ assert_eq ! ( array. unwrap( ) . as_slice( ) , & [ 0.5 , 1.0 , 2.0 , 2.0 , 4.0 ] ) ;
90
100
}
91
101
}
0 commit comments