mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-06 01:21:22 +00:00
feat: add Reflect.getPrototypeOf
This commit is contained in:
parent
2422c5e945
commit
edddd4b08e
@ -1027,6 +1027,15 @@ extern "C" {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor
|
||||||
#[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)]
|
#[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)]
|
||||||
pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> Result<JsValue, JsValue>;
|
pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> Result<JsValue, JsValue>;
|
||||||
|
|
||||||
|
/// The static Reflect.getPrototypeOf() method is almost the same
|
||||||
|
/// method as Object.getPrototypeOf(). It returns the prototype
|
||||||
|
/// (i.e. the value of the internal [[Prototype]] property) of
|
||||||
|
/// the specified object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf
|
||||||
|
#[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)]
|
||||||
|
pub fn get_prototype_of(target: &JsValue) -> Result<JsValue, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
|
@ -344,3 +344,47 @@ fn get_own_property_descriptor() {
|
|||||||
)
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_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 get_prototype_of(target: &JsValue) -> JsValue {
|
||||||
|
let result = js::Reflect::get_prototype_of(target);
|
||||||
|
let result = match result {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_err) => "TypeError".into()
|
||||||
|
};
|
||||||
|
result
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
const object = {
|
||||||
|
property: 42
|
||||||
|
};
|
||||||
|
const array: number[] = [1, 2, 3];
|
||||||
|
|
||||||
|
assert.equal(wasm.get_prototype_of(object), Object.prototype);
|
||||||
|
assert.equal(wasm.get_prototype_of(array), Array.prototype);
|
||||||
|
assert.equal(wasm.get_prototype_of(""), "TypeError");
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user