File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1996,6 +1996,14 @@ extern "C" {
1996
1996
#[ wasm_bindgen( static_method_of = Object ) ]
1997
1997
pub fn create ( prototype : & Object ) -> Object ;
1998
1998
1999
+ /// The static method Object.defineProperty() defines a new
2000
+ /// property directly on an object, or modifies an existing
2001
+ /// property on an object, and returns the object.
2002
+ ///
2003
+ /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
2004
+ #[ wasm_bindgen( static_method_of = Object , js_name = defineProperty) ]
2005
+ pub fn define_property ( obj : & Object , prop : & JsValue , descriptor : & Object ) -> Object ;
2006
+
1999
2007
/// The `Object.freeze()` method freezes an object: that is, prevents new
2000
2008
/// properties from being added to it; prevents existing properties from
2001
2009
/// being removed; and prevents existing properties, or their enumerability,
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ extern "C" {
9
9
type Foo42 ;
10
10
#[ wasm_bindgen( method, setter, structural) ]
11
11
fn set_foo ( this : & Foo42 , val : JsValue ) ;
12
+
13
+ type DefinePropertyAttrs ;
14
+ #[ wasm_bindgen( method, setter, structural) ]
15
+ fn set_value ( this : & DefinePropertyAttrs , val : & JsValue ) ;
12
16
}
13
17
14
18
#[ wasm_bindgen( module = "tests/wasm/Object.js" ) ]
@@ -73,6 +77,16 @@ fn create() {
73
77
assert ! ( my_array. is_instance_of:: <Array >( ) ) ;
74
78
}
75
79
80
+ #[ wasm_bindgen_test]
81
+ fn define_property ( ) {
82
+ let value = DefinePropertyAttrs :: from ( JsValue :: from ( Object :: new ( ) ) ) ;
83
+ value. set_value ( & 43 . into ( ) ) ;
84
+ let descriptor = Object :: from ( JsValue :: from ( value) ) ;
85
+ let foo = foo_42 ( ) ;
86
+ let foo = Object :: define_property ( & foo, & "bar" . into ( ) , & descriptor) ;
87
+ assert ! ( foo. has_own_property( & "bar" . into( ) ) ) ;
88
+ }
89
+
76
90
#[ wasm_bindgen_test]
77
91
fn has_own_property ( ) {
78
92
assert ! ( foo_42( ) . has_own_property( & "foo" . into( ) ) ) ;
You can’t perform that action at this time.
0 commit comments