mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
Merge pull request #284 from belfz/expose-bindings/object-is-prototype-of
implements Object.isPrototypeOf binding
This commit is contained in:
commit
bab5bd79a0
@ -92,7 +92,12 @@ extern {
|
|||||||
#[wasm_bindgen(method, js_name = toString)]
|
#[wasm_bindgen(method, js_name = toString)]
|
||||||
pub fn to_string(this: &Object) -> String;
|
pub fn to_string(this: &Object) -> String;
|
||||||
|
|
||||||
|
/// The isPrototypeOf() method checks if an object exists in another
|
||||||
|
/// object's prototype chain.
|
||||||
|
///
|
||||||
|
/// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array
|
// Array
|
||||||
|
@ -87,3 +87,34 @@ fn to_string() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_prototype_of() {
|
||||||
|
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 obj_is_prototype_of_value(obj: &js::Object, value: &JsValue) -> bool {
|
||||||
|
obj.is_prototype_of(&value)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
class Bar {}
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
const foo = new Foo();
|
||||||
|
assert(wasm.obj_is_prototype_of_value(Foo.prototype, foo));
|
||||||
|
assert(!wasm.obj_is_prototype_of_value(Bar.prototype, foo));
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user