mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Add binding for Object.getOwnPropertyNames()
This commit is contained in:
parent
35f5127010
commit
4e18493fd7
@ -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).
|
||||
|
@ -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()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user