@@ -467,13 +467,14 @@ extern "C" {
467
467
#[ wasm_bindgen]
468
468
extern "C" {
469
469
#[ wasm_bindgen( extends = Object ) ]
470
- #[ derive( Clone , Debug ) ]
470
+ #[ derive( Clone ) ]
471
471
pub type Boolean ;
472
472
473
473
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
474
474
///
475
475
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
476
476
#[ wasm_bindgen( constructor) ]
477
+ #[ deprecated( note = "recommended to use `Boolean::from` instead" ) ]
477
478
pub fn new ( value : & JsValue ) -> Boolean ;
478
479
479
480
/// The `valueOf()` method returns the primitive value of a `Boolean` object.
@@ -483,6 +484,30 @@ extern "C" {
483
484
pub fn value_of ( this : & Boolean ) -> bool ;
484
485
}
485
486
487
+ impl From < bool > for Boolean {
488
+ fn from ( b : bool ) -> Boolean {
489
+ Boolean { obj : JsValue :: from ( b) }
490
+ }
491
+ }
492
+
493
+ impl From < Boolean > for bool {
494
+ fn from ( b : Boolean ) -> bool {
495
+ b. value_of ( )
496
+ }
497
+ }
498
+
499
+ impl PartialEq < bool > for Boolean {
500
+ fn eq ( & self , other : & bool ) -> bool {
501
+ self . value_of ( ) == * other
502
+ }
503
+ }
504
+
505
+ impl fmt:: Debug for Boolean {
506
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
507
+ self . value_of ( ) . fmt ( f)
508
+ }
509
+ }
510
+
486
511
// DataView
487
512
#[ wasm_bindgen]
488
513
extern "C" {
@@ -1406,7 +1431,7 @@ extern "C" {
1406
1431
#[ wasm_bindgen]
1407
1432
extern "C" {
1408
1433
#[ wasm_bindgen( extends = Object ) ]
1409
- #[ derive( Clone , Debug ) ]
1434
+ #[ derive( Clone ) ]
1410
1435
pub type Number ;
1411
1436
1412
1437
/// The Number.isFinite() method determines whether the passed value is a finite number.
@@ -1441,6 +1466,7 @@ extern "C" {
1441
1466
///
1442
1467
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
1443
1468
#[ wasm_bindgen( constructor) ]
1469
+ #[ deprecated( note = "recommended to use `Number::from` instead" ) ]
1444
1470
pub fn new ( value : & JsValue ) -> Number ;
1445
1471
1446
1472
/// The Number.parseInt() method parses a string argument and returns an
@@ -1500,6 +1526,35 @@ extern "C" {
1500
1526
pub fn value_of ( this : & Number ) -> f64 ;
1501
1527
}
1502
1528
1529
+ macro_rules! number_from {
1530
+ ( $( $x: ident) * ) => ( $(
1531
+ impl From <$x> for Number {
1532
+ fn from( x: $x) -> Number {
1533
+ Number { obj: x. into( ) }
1534
+ }
1535
+ }
1536
+
1537
+ impl PartialEq <$x> for Number {
1538
+ fn eq( & self , other: & $x) -> bool {
1539
+ self . value_of( ) == f64 :: from( * other)
1540
+ }
1541
+ }
1542
+ ) * )
1543
+ }
1544
+ number_from ! ( i8 u8 i16 u16 i32 u32 f32 f64 ) ;
1545
+
1546
+ impl From < Number > for f64 {
1547
+ fn from ( n : Number ) -> f64 {
1548
+ n. value_of ( )
1549
+ }
1550
+ }
1551
+
1552
+ impl fmt:: Debug for Number {
1553
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1554
+ self . value_of ( ) . fmt ( f)
1555
+ }
1556
+ }
1557
+
1503
1558
// Date.
1504
1559
#[ wasm_bindgen]
1505
1560
extern "C" {
0 commit comments