File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -4884,6 +4884,14 @@ macro_rules! arrays {
4884
4884
/// input values from a specified array.
4885
4885
#[ wasm_bindgen( method) ]
4886
4886
pub fn set( this: & $name, src: & JsValue , offset: u32 ) ;
4887
+
4888
+ /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
4889
+ #[ wasm_bindgen( method, structural, indexing_getter) ]
4890
+ pub fn get_index( this: & $name, idx: u32 ) -> $ty;
4891
+
4892
+ /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
4893
+ #[ wasm_bindgen( method, structural, indexing_setter) ]
4894
+ pub fn set_index( this: & $name, idx: u32 , value: $ty) ;
4887
4895
}
4888
4896
4889
4897
impl $name {
Original file line number Diff line number Diff line change @@ -89,6 +89,19 @@ fn new_fill() {
89
89
each ! ( test_fill) ;
90
90
}
91
91
92
+ macro_rules! test_get_set {
93
+ ( $arr: ident) => { {
94
+ let arr = $arr:: new( & 1 . into( ) ) ;
95
+ assert_eq!( arr. get_index( 0 ) as f64 , 0 as f64 ) ;
96
+ arr. set_index( 0 , 1 as _) ;
97
+ assert_eq!( arr. get_index( 0 ) as f64 , 1 as f64 ) ;
98
+ } } ;
99
+ }
100
+ #[ wasm_bindgen_test]
101
+ fn new_get_set ( ) {
102
+ each ! ( test_get_set) ;
103
+ }
104
+
92
105
macro_rules! test_slice {
93
106
( $arr: ident) => { {
94
107
let arr = $arr:: new( & 4 . into( ) ) ;
You can’t perform that action at this time.
0 commit comments