@@ -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,35 @@ extern "C" {
483
484
pub fn value_of ( this : & Boolean ) -> bool ;
484
485
}
485
486
487
+ impl From < bool > for Boolean {
488
+ #[ inline]
489
+ fn from ( b : bool ) -> Boolean {
490
+ Boolean :: unchecked_from_js ( JsValue :: from ( b) )
491
+ }
492
+ }
493
+
494
+ impl From < Boolean > for bool {
495
+ #[ inline]
496
+ fn from ( b : Boolean ) -> bool {
497
+ b. value_of ( )
498
+ }
499
+ }
500
+
501
+ impl PartialEq < bool > for Boolean {
502
+ #[ inline]
503
+ fn eq ( & self , other : & bool ) -> bool {
504
+ self . value_of ( ) == * other
505
+ }
506
+ }
507
+
508
+ impl Eq for Boolean { }
509
+
510
+ impl fmt:: Debug for Boolean {
511
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
512
+ self . value_of ( ) . fmt ( f)
513
+ }
514
+ }
515
+
486
516
// DataView
487
517
#[ wasm_bindgen]
488
518
extern "C" {
@@ -1406,7 +1436,7 @@ extern "C" {
1406
1436
#[ wasm_bindgen]
1407
1437
extern "C" {
1408
1438
#[ wasm_bindgen( extends = Object ) ]
1409
- #[ derive( Clone , Debug ) ]
1439
+ #[ derive( Clone ) ]
1410
1440
pub type Number ;
1411
1441
1412
1442
/// The Number.isFinite() method determines whether the passed value is a finite number.
@@ -1441,6 +1471,7 @@ extern "C" {
1441
1471
///
1442
1472
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
1443
1473
#[ wasm_bindgen( constructor) ]
1474
+ #[ deprecated( note = "recommended to use `Number::from` instead" ) ]
1444
1475
pub fn new ( value : & JsValue ) -> Number ;
1445
1476
1446
1477
/// The Number.parseInt() method parses a string argument and returns an
@@ -1500,6 +1531,38 @@ extern "C" {
1500
1531
pub fn value_of ( this : & Number ) -> f64 ;
1501
1532
}
1502
1533
1534
+ macro_rules! number_from {
1535
+ ( $( $x: ident) * ) => ( $(
1536
+ impl From <$x> for Number {
1537
+ #[ inline]
1538
+ fn from( x: $x) -> Number {
1539
+ Number :: unchecked_from_js( JsValue :: from( x) )
1540
+ }
1541
+ }
1542
+
1543
+ impl PartialEq <$x> for Number {
1544
+ #[ inline]
1545
+ fn eq( & self , other: & $x) -> bool {
1546
+ self . value_of( ) == f64 :: from( * other)
1547
+ }
1548
+ }
1549
+ ) * )
1550
+ }
1551
+ number_from ! ( i8 u8 i16 u16 i32 u32 f32 f64 ) ;
1552
+
1553
+ impl From < Number > for f64 {
1554
+ #[ inline]
1555
+ fn from ( n : Number ) -> f64 {
1556
+ n. value_of ( )
1557
+ }
1558
+ }
1559
+
1560
+ impl fmt:: Debug for Number {
1561
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1562
+ self . value_of ( ) . fmt ( f)
1563
+ }
1564
+ }
1565
+
1503
1566
// Date.
1504
1567
#[ wasm_bindgen]
1505
1568
extern "C" {
0 commit comments