implements Object.isPrototypeOf binding

This commit is contained in:
belfz 2018-06-21 07:36:24 +02:00
parent 669ed4d644
commit 77ad68673c
2 changed files with 37 additions and 1 deletions

View File

@ -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

View File

@ -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()
}