File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -2176,6 +2176,13 @@ extern "C" {
2176
2176
#[ wasm_bindgen( static_method_of = Object ) ]
2177
2177
pub fn freeze ( value : & Object ) -> Object ;
2178
2178
2179
+ /// The Object.fromEntries() method transforms a list of key-value pairs
2180
+ /// into an object.
2181
+ ///
2182
+ /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
2183
+ #[ wasm_bindgen( static_method_of = Object , catch, js_name = fromEntries) ]
2184
+ pub fn from_entries ( iterable : & JsValue ) -> Result < Object , JsValue > ;
2185
+
2179
2186
/// The Object.getOwnPropertyDescriptor() method returns a
2180
2187
/// property descriptor for an own property (that is, one directly
2181
2188
/// present on an object and not in the object's prototype chain)
Original file line number Diff line number Diff line change @@ -123,6 +123,25 @@ fn entries() {
123
123
} ) ;
124
124
}
125
125
126
+ #[ wasm_bindgen_test]
127
+ fn from_entries ( ) {
128
+ let array = Array :: new ( ) ;
129
+ let entry_one = Array :: new ( ) ;
130
+ let entry_two = Array :: new ( ) ;
131
+ entry_one. push ( & "foo" . into ( ) ) ;
132
+ entry_one. push ( & "bar" . into ( ) ) ;
133
+ entry_two. push ( & "baz" . into ( ) ) ;
134
+ entry_two. push ( & 42 . into ( ) ) ;
135
+ let object = Object :: from_entries ( & array) . unwrap ( ) ;
136
+
137
+ assert_eq ! ( Reflect :: get( object. as_ref( ) , & "foo" . into( ) ) . unwrap( ) , "bar" ) ;
138
+ assert_eq ! ( Reflect :: get( object. as_ref( ) , & "baz" . into( ) ) . unwrap( ) , 42 ) ;
139
+
140
+ let not_iterable = Object :: new ( ) ;
141
+ let error = Object :: from_entries ( & not_iterable) . unwrap_err ( ) ;
142
+ assert ! ( error. is_instance_of:: <TypeError >( ) ) ;
143
+ }
144
+
126
145
#[ wasm_bindgen_test]
127
146
fn get_own_property_descriptor ( ) {
128
147
let foo = foo_42 ( ) ;
You can’t perform that action at this time.
0 commit comments