Skip to content

Commit e6d1e7b

Browse files
jimmyhmillergbrail
authored andcommitted
Fix double-evaluation of Date constructor arguments
The date_msecFromArgs function was calling toNumber() and then toInteger() on the same argument, which caused the argument's toString/valueOf to be called twice. Fixed by using the already-computed number value when converting to integer. Fixes 2 test262 tests: - built-ins/Date/UTC/coercion-order.js - built-ins/Date/coercion-order.js
1 parent 8ed9aa9 commit e6d1e7b

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/NativeDate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ private static double date_msecFromArgs(Object[] args) {
925925
if (Double.isNaN(d) || Double.isInfinite(d)) {
926926
return ScriptRuntime.NaN;
927927
}
928-
array[loop] = ScriptRuntime.toInteger(args[loop]);
928+
array[loop] = ScriptRuntime.toInteger(d);
929929
} else {
930930
if (loop == 2) {
931931
array[loop] = 1; /* Default the date argument to 1. */

tests/testsrc/test262.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ built-ins/DataView 86/561 (15.33%)
775775
toindex-bytelength-sab.js {unsupported: [SharedArrayBuffer]}
776776
toindex-byteoffset-sab.js {unsupported: [SharedArrayBuffer]}
777777

778-
built-ins/Date 85/594 (14.31%)
778+
built-ins/Date 83/594 (13.97%)
779779
now/not-a-constructor.js
780780
parse/not-a-constructor.js
781781
parse/year-zero.js
@@ -846,10 +846,8 @@ built-ins/Date 85/594 (14.31%)
846846
prototype/valueOf/not-a-constructor.js
847847
prototype/valueOf/S9.4_A3_T1.js
848848
prototype/no-date-value.js
849-
UTC/coercion-order.js
850849
UTC/fp-evaluation-order.js
851850
UTC/not-a-constructor.js
852-
coercion-order.js
853851
proto-from-ctor-realm-one.js
854852
proto-from-ctor-realm-two.js
855853
proto-from-ctor-realm-zero.js

0 commit comments

Comments
 (0)