Skip to content

Commit 0b29721

Browse files
authored
Merge pull request #285 from belfz/expose-bindings/object-property-is-enumerable
implements Object.prototype.propertyIsEnumerable() binding
2 parents 6ef817b + 420eaff commit 0b29721

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/js.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ extern {
9898
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf
9999
#[wasm_bindgen(method, js_name = isPrototypeOf)]
100100
pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
101+
102+
/// The propertyIsEnumerable() method returns a Boolean indicating
103+
/// whether the specified property is enumerable.
104+
///
105+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable
106+
#[wasm_bindgen(method, js_name = propertyIsEnumerable)]
107+
pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
101108
}
102109

103110
// Array

tests/all/js_globals/Object.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,38 @@ fn is_prototype_of() {
118118
"#)
119119
.test()
120120
}
121+
122+
#[test]
123+
fn property_is_enumerable() {
124+
project()
125+
.file("src/lib.rs", r#"
126+
#![feature(proc_macro, wasm_custom_section)]
127+
128+
extern crate wasm_bindgen;
129+
use wasm_bindgen::prelude::*;
130+
use wasm_bindgen::js;
131+
132+
#[wasm_bindgen]
133+
pub fn property_is_enumerable(obj: &js::Object, property: &JsValue) -> bool {
134+
obj.property_is_enumerable(&property)
135+
}
136+
"#)
137+
.file("test.ts", r#"
138+
import * as assert from "assert";
139+
import * as wasm from "./out";
140+
141+
export function test() {
142+
assert(wasm.property_is_enumerable({ foo: 42 }, "foo"));
143+
assert(wasm.property_is_enumerable({ 42: "foo" }, 42));
144+
assert(!wasm.property_is_enumerable({}, 42));
145+
146+
const obj = {};
147+
Object.defineProperty(obj, "foo", { enumerable: false });
148+
assert(!wasm.property_is_enumerable(obj, "foo"));
149+
150+
const s = Symbol();
151+
assert.ok(wasm.property_is_enumerable({ [s]: true }, s));
152+
}
153+
"#)
154+
.test()
155+
}

0 commit comments

Comments
 (0)