Add binding for Object.getOwnPropertyNames()

This commit is contained in:
Michael Hoffmann 2018-09-19 20:43:50 +02:00
parent 35f5127010
commit 4e18493fd7
2 changed files with 17 additions and 0 deletions

View File

@ -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).

View File

@ -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()));