diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index d72bbcac..86b9d05b 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2040,6 +2040,14 @@ extern "C" { #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)] pub fn get_own_property_descriptors(obj: &Object) -> JsValue; + /// The Object.getOwnPropertyNames() method returns an array of + /// all properties (including non-enumerable properties except for + /// those which use Symbol) found directly upon a given object. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames) + #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)] + pub fn get_own_property_names(obj: &Object) -> Array; + /// The `hasOwnProperty()` method returns a boolean indicating whether the /// object has the specified property as its own property (as opposed to /// inheriting it). diff --git a/crates/js-sys/tests/wasm/Object.rs b/crates/js-sys/tests/wasm/Object.rs index 525bfab3..ccd555cb 100644 --- a/crates/js-sys/tests/wasm/Object.rs +++ b/crates/js-sys/tests/wasm/Object.rs @@ -122,6 +122,15 @@ fn get_own_property_descriptors() { assert_eq!(PropertyDescriptor::from(foo_desc).value(), 42); } +#[wasm_bindgen_test] +fn get_own_property_names() { + let names = Object::get_own_property_names(&foo_42()); + assert_eq!(names.length(), 1); + names.for_each(&mut |x, _, _| { + assert_eq!(x, "foo"); + }); +} + #[wasm_bindgen_test] fn has_own_property() { assert!(foo_42().has_own_property(&"foo".into()));