Merge pull request #285 from belfz/expose-bindings/object-property-is-enumerable

implements Object.prototype.propertyIsEnumerable() binding
This commit is contained in:
Nick Fitzgerald 2018-06-21 13:39:09 -07:00 committed by GitHub
commit 0b29721194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -98,6 +98,13 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf
#[wasm_bindgen(method, js_name = isPrototypeOf)]
pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
/// The propertyIsEnumerable() method returns a Boolean indicating
/// whether the specified property is enumerable.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable
#[wasm_bindgen(method, js_name = propertyIsEnumerable)]
pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
}
// Array

View File

@ -118,3 +118,38 @@ fn is_prototype_of() {
"#)
.test()
}
#[test]
fn property_is_enumerable() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn property_is_enumerable(obj: &js::Object, property: &JsValue) -> bool {
obj.property_is_enumerable(&property)
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert(wasm.property_is_enumerable({ foo: 42 }, "foo"));
assert(wasm.property_is_enumerable({ 42: "foo" }, 42));
assert(!wasm.property_is_enumerable({}, 42));
const obj = {};
Object.defineProperty(obj, "foo", { enumerable: false });
assert(!wasm.property_is_enumerable(obj, "foo"));
const s = Symbol();
assert.ok(wasm.property_is_enumerable({ [s]: true }, s));
}
"#)
.test()
}