js-sys: Add bindings for Object.create

This commit is contained in:
Nick Fitzgerald 2018-08-10 11:49:22 -07:00
parent 4ea1603ddb
commit adad606ee3
2 changed files with 23 additions and 6 deletions

View File

@ -1914,6 +1914,13 @@ extern "C" {
#[wasm_bindgen(static_method_of = Object, js_name = assign)]
pub fn assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object) -> Object;
/// The Object.create() method creates a new object, using an existing
/// object to provide the newly created object's prototype.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
#[wasm_bindgen(static_method_of = Object)]
pub fn create(prototype: &Object) -> Object;
/// The `Object.freeze()` method freezes an object: that is, prevents new
/// properties from being added to it; prevents existing properties from
/// being removed; and prevents existing properties, or their enumerability,

View File

@ -1,17 +1,18 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use std::f64::NAN;
use js_sys::*;
use std::f64::NAN;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen]
extern {
extern "C" {
type Foo42;
#[wasm_bindgen(method, setter, structural)]
fn set_foo(this: &Foo42, val: JsValue);
}
#[wasm_bindgen(module = "tests/wasm/Object.js")]
extern {
extern "C" {
fn map_with_symbol_key() -> Object;
fn symbol_key() -> JsValue;
@ -36,7 +37,6 @@ fn new() {
assert!(JsValue::from(Object::new()).is_object());
}
#[wasm_bindgen_test]
fn assign() {
let a = JsValue::from("a");
@ -63,6 +63,16 @@ fn assign() {
assert_eq!(Reflect::get(target.as_ref(), &c), c);
}
#[wasm_bindgen_test]
fn create() {
let array_proto = eval("Array.prototype")
.unwrap()
.dyn_into::<Object>()
.unwrap();
let my_array = Object::create(&array_proto);
assert!(my_array.is_instance_of::<Array>());
}
#[wasm_bindgen_test]
fn has_own_property() {
assert!(foo_42().has_own_property(&"foo".into()));