mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
allows using &JsValue as an arg to Object's has_own_property
This commit is contained in:
parent
0b29721194
commit
dd3740e2fb
@ -84,7 +84,7 @@ extern {
|
|||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
|
||||||
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
||||||
pub fn has_own_property(this: &Object, property: &str) -> bool;
|
pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
|
||||||
|
|
||||||
/// The toString() method returns a string representing the object.
|
/// The toString() method returns a string representing the object.
|
||||||
///
|
///
|
||||||
|
@ -39,8 +39,8 @@ fn has_own_property() {
|
|||||||
use wasm_bindgen::js;
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn has_own_foo_property(obj: &js::Object) -> bool {
|
pub fn has_own_foo_property(obj: &js::Object, property: &JsValue) -> bool {
|
||||||
obj.has_own_property("foo")
|
obj.has_own_property(&property)
|
||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.file("test.ts", r#"
|
.file("test.ts", r#"
|
||||||
@ -48,8 +48,12 @@ fn has_own_property() {
|
|||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.ok(wasm.has_own_foo_property({ foo: 42 }));
|
assert(wasm.has_own_foo_property({ foo: 42 }, "foo"));
|
||||||
assert.ok(!wasm.has_own_foo_property({}));
|
assert(wasm.has_own_foo_property({ 42: "foo" }, 42));
|
||||||
|
assert(!wasm.has_own_foo_property({ foo: 42 }, "bar"));
|
||||||
|
|
||||||
|
const s = Symbol();
|
||||||
|
assert(wasm.has_own_foo_property({ [s]: "foo" }, s));
|
||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user