mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-24 18:43:33 +03:00
implements Object.isPrototypeOf binding
This commit is contained in:
parent
669ed4d644
commit
77ad68673c
@ -92,7 +92,12 @@ extern {
|
||||
#[wasm_bindgen(method, js_name = toString)]
|
||||
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
|
||||
|
@ -87,3 +87,34 @@ fn to_string() {
|
||||
"#)
|
||||
.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…
Reference in New Issue
Block a user