mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-30 22:25:35 +03:00
Merge pull request #833 from brisad/object-define-properties
Add binding for Object.defineProperties()
This commit is contained in:
commit
2d5d485e46
@ -2004,6 +2004,14 @@ extern "C" {
|
|||||||
#[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
|
#[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
|
||||||
pub fn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object;
|
pub fn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object;
|
||||||
|
|
||||||
|
/// The Object.defineProperties() method defines new or modifies
|
||||||
|
/// existing properties directly on an object, returning the
|
||||||
|
/// object.
|
||||||
|
///
|
||||||
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
|
||||||
|
#[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
|
||||||
|
pub fn define_properties(obj: &Object, props: &Object) -> Object;
|
||||||
|
|
||||||
/// The `Object.freeze()` method freezes an object: that is, prevents new
|
/// The `Object.freeze()` method freezes an object: that is, prevents new
|
||||||
/// properties from being added to it; prevents existing properties from
|
/// properties from being added to it; prevents existing properties from
|
||||||
/// being removed; and prevents existing properties, or their enumerability,
|
/// being removed; and prevents existing properties, or their enumerability,
|
||||||
|
@ -87,6 +87,20 @@ fn define_property() {
|
|||||||
assert!(foo.has_own_property(&"bar".into()));
|
assert!(foo.has_own_property(&"bar".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn define_properties() {
|
||||||
|
let props = Object::new();
|
||||||
|
let descriptor = DefinePropertyAttrs::from(JsValue::from(Object::new()));
|
||||||
|
descriptor.set_value(&42.into());
|
||||||
|
let descriptor = JsValue::from(descriptor);
|
||||||
|
Reflect::set(props.as_ref(), &JsValue::from("bar"), &descriptor);
|
||||||
|
Reflect::set(props.as_ref(), &JsValue::from("car"), &descriptor);
|
||||||
|
let foo = foo_42();
|
||||||
|
let foo = Object::define_properties(&foo, &props);
|
||||||
|
assert!(foo.has_own_property(&"bar".into()));
|
||||||
|
assert!(foo.has_own_property(&"car".into()));
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn has_own_property() {
|
fn has_own_property() {
|
||||||
assert!(foo_42().has_own_property(&"foo".into()));
|
assert!(foo_42().has_own_property(&"foo".into()));
|
||||||
|
Loading…
Reference in New Issue
Block a user