Add binding for Object.getPrototypeOf()

This commit is contained in:
Michael Hoffmann 2018-09-19 21:10:40 +02:00
parent 76969bd1e3
commit 326e4c0262
2 changed files with 21 additions and 0 deletions

View File

@ -2055,6 +2055,14 @@ extern "C" {
#[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
pub fn get_own_property_symbols(obj: &Object) -> Array;
/// The Object.getPrototypeOf() method returns the prototype
/// (i.e. the value of the internal [[Prototype]] property) of the
/// specified object.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
#[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
pub fn get_prototype_of(obj: &JsValue) -> Object;
/// The `hasOwnProperty()` method returns a boolean indicating whether the
/// object has the specified property as its own property (as opposed to
/// inheriting it).

View File

@ -10,6 +10,11 @@ extern "C" {
#[wasm_bindgen(method, setter, structural)]
fn set_foo(this: &Foo42, val: JsValue);
#[wasm_bindgen(js_name = prototype, js_namespace = Object)]
static OBJECT_PROTOTYPE: JsValue;
#[wasm_bindgen(js_name = prototype, js_namespace = Array)]
static ARRAY_PROTOTYPE: JsValue;
type DefinePropertyAttrs;
#[wasm_bindgen(method, setter, structural)]
fn set_value(this: &DefinePropertyAttrs, val: &JsValue);
@ -137,6 +142,14 @@ fn get_own_property_symbols() {
assert_eq!(symbols.length(), 1);
}
#[wasm_bindgen_test]
fn get_prototype_of() {
let proto = JsValue::from(Object::get_prototype_of(&Object::new().into()));
assert_eq!(proto, *OBJECT_PROTOTYPE);
let proto = JsValue::from(Object::get_prototype_of(&Array::new().into()));
assert_eq!(proto, *ARRAY_PROTOTYPE);
}
#[wasm_bindgen_test]
fn has_own_property() {
assert!(foo_42().has_own_property(&"foo".into()));