File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,13 @@ extern {
293
293
#[ wasm_bindgen( method, js_name = isPrototypeOf) ]
294
294
pub fn is_prototype_of ( this : & Object , value : & JsValue ) -> bool ;
295
295
296
+ /// The Object.keys() method returns an array of a given object's property
297
+ /// names, in the same order as we get with a normal loop.
298
+ ///
299
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
300
+ #[ wasm_bindgen( static_method_of = Object ) ]
301
+ pub fn keys ( object : & Object ) -> Array ;
302
+
296
303
/// The Object constructor creates an object wrapper.
297
304
///
298
305
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
Original file line number Diff line number Diff line change @@ -123,6 +123,33 @@ fn is_prototype_of() {
123
123
. test ( )
124
124
}
125
125
126
+ #[ test]
127
+ fn keys ( ) {
128
+ project ( )
129
+ . file ( "src/lib.rs" , r#"
130
+ #![feature(proc_macro, wasm_custom_section)]
131
+
132
+ extern crate wasm_bindgen;
133
+ use wasm_bindgen::prelude::*;
134
+ use wasm_bindgen::js;
135
+
136
+ #[wasm_bindgen]
137
+ pub fn keys(obj: &js::Object) -> js::Array {
138
+ js::Object::keys(obj)
139
+ }
140
+ "# )
141
+ . file ( "test.ts" , r#"
142
+ import * as assert from "assert";
143
+ import * as wasm from "./out";
144
+
145
+ export function test() {
146
+ const obj = { a: 1, b: 2, c: 3 };
147
+ assert.deepStrictEqual(wasm.keys(obj), ["a", "b", "c"]);
148
+ }
149
+ "# )
150
+ . test ( )
151
+ }
152
+
126
153
#[ test]
127
154
fn property_is_enumerable ( ) {
128
155
project ( )
You can’t perform that action at this time.
0 commit comments