@@ -84,14 +84,22 @@ function assert(actual, expected, message) {
84
84
if ( arguments . length == 1 )
85
85
expected = true ;
86
86
87
- if ( actual === expected )
88
- return ;
89
-
90
- if ( actual !== null && expected !== null
91
- && typeof actual == 'object' && typeof expected == 'object'
92
- && actual . toString ( ) === expected . toString ( ) )
93
- return ;
94
-
87
+ if ( typeof actual === typeof expected ) {
88
+ if ( actual === expected ) {
89
+ if ( actual !== 0 || ( 1 / actual ) === ( 1 / expected ) )
90
+ return ;
91
+ }
92
+ if ( typeof actual === 'number' ) {
93
+ if ( isNaN ( actual ) && isNaN ( expected ) )
94
+ return true ;
95
+ }
96
+ if ( typeof actual === 'object' ) {
97
+ if ( actual !== null && expected !== null
98
+ && actual . constructor === expected . constructor
99
+ && actual . toString ( ) === expected . toString ( ) )
100
+ return ;
101
+ }
102
+ }
95
103
throw Error ( "assertion failed: got |" + actual + "|" +
96
104
", expected |" + expected + "|" +
97
105
( message ? " (" + message + ")" : "" ) ) ;
@@ -594,20 +602,54 @@ function test_date()
594
602
assert ( d . toISOString ( ) , "2017-09-22T18:10:11.091Z" ) ;
595
603
a = Date . parse ( d . toISOString ( ) ) ;
596
604
assert ( ( new Date ( a ) ) . toISOString ( ) , d . toISOString ( ) ) ;
605
+ s = new Date ( "2020-01-01T01:01:01.123Z" ) . toISOString ( ) ;
606
+ assert ( s , "2020-01-01T01:01:01.123Z" ) ;
607
+ // implementation defined behavior
597
608
s = new Date ( "2020-01-01T01:01:01.1Z" ) . toISOString ( ) ;
598
- assert ( s == "2020-01-01T01:01:01.100Z" ) ;
609
+ assert ( s , "2020-01-01T01:01:01.100Z" ) ;
599
610
s = new Date ( "2020-01-01T01:01:01.12Z" ) . toISOString ( ) ;
600
- assert ( s == "2020-01-01T01:01:01.120Z" ) ;
601
- s = new Date ( "2020-01-01T01:01:01.123Z" ) . toISOString ( ) ;
602
- assert ( s == "2020-01-01T01:01:01.123Z" ) ;
611
+ assert ( s , "2020-01-01T01:01:01.120Z" ) ;
603
612
s = new Date ( "2020-01-01T01:01:01.1234Z" ) . toISOString ( ) ;
604
- assert ( s == "2020-01-01T01:01:01.123Z" ) ;
613
+ assert ( s , "2020-01-01T01:01:01.123Z" ) ;
605
614
s = new Date ( "2020-01-01T01:01:01.12345Z" ) . toISOString ( ) ;
606
- assert ( s == "2020-01-01T01:01:01.123Z" ) ;
615
+ assert ( s , "2020-01-01T01:01:01.123Z" ) ;
607
616
s = new Date ( "2020-01-01T01:01:01.1235Z" ) . toISOString ( ) ;
608
- assert ( s == "2020-01-01T01:01:01.124Z" ) ;
617
+ assert ( s == "2020-01-01T01:01:01.124Z" || // QuickJS
618
+ s == "2020-01-01T01:01:01.123Z" ) ; // nodeJS
609
619
s = new Date ( "2020-01-01T01:01:01.9999Z" ) . toISOString ( ) ;
610
- assert ( s == "2020-01-01T01:01:02.000Z" ) ;
620
+ assert ( s == "2020-01-01T01:01:02.000Z" || // QuickJS
621
+ s == "2020-01-01T01:01:01.999Z" ) ; // nodeJS
622
+
623
+ assert ( Date . UTC ( 2017 ) , 1483228800000 ) ;
624
+ assert ( Date . UTC ( 2017 , 9 ) , 1506816000000 ) ;
625
+ assert ( Date . UTC ( 2017 , 9 , 22 ) , 1508630400000 ) ;
626
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 ) , 1508695200000 ) ;
627
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 ) , 1508695800000 ) ;
628
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , 11 ) , 1508695811000 ) ;
629
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , 11 , 91 ) , 1508695811091 ) ;
630
+
631
+ assert ( Date . UTC ( NaN ) , NaN ) ;
632
+ assert ( Date . UTC ( 2017 , NaN ) , NaN ) ;
633
+ assert ( Date . UTC ( 2017 , 9 , NaN ) , NaN ) ;
634
+ assert ( Date . UTC ( 2017 , 9 , 22 , NaN ) , NaN ) ;
635
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , NaN ) , NaN ) ;
636
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , NaN ) , NaN ) ;
637
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , 11 , NaN ) , NaN ) ;
638
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , 11 , 91 , NaN ) , 1508695811091 ) ;
639
+
640
+ // TODO: Fix rounding errors on Windows/Cygwin.
641
+ if ( ! [ 'win32' , 'cygwin' ] . includes ( os . platform ) ) {
642
+ // from test262/test/built-ins/Date/UTC/fp-evaluation-order.js
643
+ assert ( Date . UTC ( 1970 , 0 , 1 , 80063993375 , 29 , 1 , - 288230376151711740 ) , 29312 ,
644
+ 'order of operations / precision in MakeTime' ) ;
645
+ assert ( Date . UTC ( 1970 , 0 , 213503982336 , 0 , 0 , 0 , - 18446744073709552000 ) , 34447360 ,
646
+ 'precision in MakeDate' ) ;
647
+ }
648
+ //assert(Date.UTC(2017 - 1e9, 9 + 12e9), 1506816000000); // node fails this
649
+ assert ( Date . UTC ( 2017 , 9 , 22 - 1e10 , 18 + 24e10 ) , 1508695200000 ) ;
650
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 - 1e10 , 10 + 60e10 ) , 1508695800000 ) ;
651
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 - 1e10 , 11 + 60e10 ) , 1508695811000 ) ;
652
+ assert ( Date . UTC ( 2017 , 9 , 22 , 18 , 10 , 11 - 1e12 , 91 + 1000e12 ) , 1508695811091 ) ;
611
653
}
612
654
613
655
function test_regexp ( )
0 commit comments