Diff
Added: trunk/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc (0 => 234763)
--- trunk/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc (rev 0)
+++ trunk/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc 2018-08-10 17:42:32 UTC (rev 234763)
@@ -0,0 +1,13 @@
+126230400000
+126230400000
+149817600000
+151804800000
+151804800000
+151806000000
+151806030000
+151806030040
+151806030040
+-2151877169960
+151806030040
+NaN
+NaN
Modified: trunk/JSTests/ChakraCore.yaml (234762 => 234763)
--- trunk/JSTests/ChakraCore.yaml 2018-08-10 17:39:53 UTC (rev 234762)
+++ trunk/JSTests/ChakraCore.yaml 2018-08-10 17:42:32 UTC (rev 234763)
@@ -490,7 +490,7 @@
- path: ChakraCore/test/Date/toISO_3.js
cmd: runChakra :baseline, "NoException", "toISO_3.baseline", []
- path: ChakraCore/test/Date/dateutc.js
- cmd: runChakra :baseline, "NoException", "dateutc.baseline", []
+ cmd: runChakra :baseline, "NoException", "dateutc.baseline-jsc", []
- path: ChakraCore/test/Date/MillisecondTruncationCheckAfterCopyConstructor.js
cmd: runChakra :baseline, "NoException", "MillisecondTruncationCheckAfterCopyConstructor.es6.baseline", []
# FIXME: unskip the following test on Windows when https://bugs.webkit.org/show_bug.cgi?id=165193 is fixed.
Modified: trunk/JSTests/ChangeLog (234762 => 234763)
--- trunk/JSTests/ChangeLog 2018-08-10 17:39:53 UTC (rev 234762)
+++ trunk/JSTests/ChangeLog 2018-08-10 17:42:32 UTC (rev 234763)
@@ -1,3 +1,16 @@
+2018-08-10 Yusuke Suzuki <[email protected]>
+
+ Date.UTC should not return NaN with only Year param
+ https://bugs.webkit.org/show_bug.cgi?id=188378
+
+ Reviewed by Keith Miller.
+
+ * ChakraCore.yaml:
+ * ChakraCore/test/Date/dateutc.baseline-jsc: Added.
+ * stress/date-utc-optional.js: Added.
+ (shouldBe):
+ * test262/expectations.yaml:
+
2018-08-08 Keith Miller <[email protected]>
Array.prototype.sort should call @toLength instead of ">>> 0"
Added: trunk/JSTests/stress/date-utc-optional.js (0 => 234763)
--- trunk/JSTests/stress/date-utc-optional.js (rev 0)
+++ trunk/JSTests/stress/date-utc-optional.js 2018-08-10 17:42:32 UTC (rev 234763)
@@ -0,0 +1,16 @@
+function shouldBe(actual, expected) {
+ if (actual !== expected)
+ throw new Error('bad value: ' + actual);
+}
+
+for (var i = 0; i < 1e5; ++i) {
+ shouldBe(Number.isNaN(Date.UTC()), true);
+ shouldBe(Date.UTC(2018), 1514764800000);
+ shouldBe(Date.UTC(2018, 1), 1517443200000);
+ shouldBe(Date.UTC(2018, 1, 2), 1517529600000);
+ shouldBe(Date.UTC(2018, 1, 2, 3), 1517540400000);
+ shouldBe(Date.UTC(2018, 1, 2, 3, 4), 1517540640000);
+ shouldBe(Date.UTC(2018, 1, 2, 3, 4, 5), 1517540645000);
+ shouldBe(Date.UTC(2018, 1, 2, 3, 4, 5, 6), 1517540645006);
+ shouldBe(Date.UTC(2018, 1, 2, 3, 4, 5, 6, 7), 1517540645006);
+}
Modified: trunk/JSTests/test262/expectations.yaml (234762 => 234763)
--- trunk/JSTests/test262/expectations.yaml 2018-08-10 17:39:53 UTC (rev 234762)
+++ trunk/JSTests/test262/expectations.yaml 2018-08-10 17:42:32 UTC (rev 234763)
@@ -855,9 +855,6 @@
test/built-ins/DataView/prototype/setUint8/detached-buffer.js:
default: 'Test262Error: Expected a TypeError but got a RangeError'
strict mode: 'Test262Error: Expected a TypeError but got a RangeError'
-test/built-ins/Date/UTC/return-value.js:
- default: 'Test262Error: 1970 Expected SameValue(«NaN», «0») to be true'
- strict mode: 'Test262Error: 1970 Expected SameValue(«NaN», «0») to be true'
test/built-ins/Date/proto-from-ctor-realm-one.js:
default: 'TypeError: Type error'
strict mode: 'TypeError: Type error'
Modified: trunk/Source/_javascript_Core/ChangeLog (234762 => 234763)
--- trunk/Source/_javascript_Core/ChangeLog 2018-08-10 17:39:53 UTC (rev 234762)
+++ trunk/Source/_javascript_Core/ChangeLog 2018-08-10 17:42:32 UTC (rev 234763)
@@ -1,3 +1,16 @@
+2018-08-10 Yusuke Suzuki <[email protected]>
+
+ Date.UTC should not return NaN with only Year param
+ https://bugs.webkit.org/show_bug.cgi?id=188378
+
+ Reviewed by Keith Miller.
+
+ Date.UTC requires one argument for |year|. But the other ones are optional.
+ This patch fix this handling.
+
+ * runtime/DateConstructor.cpp:
+ (JSC::millisecondsFromComponents):
+
2018-08-08 Keith Miller <[email protected]>
Array.prototype.sort should call @toLength instead of ">>> 0"
Modified: trunk/Source/_javascript_Core/runtime/DateConstructor.cpp (234762 => 234763)
--- trunk/Source/_javascript_Core/runtime/DateConstructor.cpp 2018-08-10 17:39:53 UTC (rev 234762)
+++ trunk/Source/_javascript_Core/runtime/DateConstructor.cpp 2018-08-10 17:42:32 UTC (rev 234763)
@@ -88,34 +88,30 @@
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- double doubleArguments[7];
- for (int i = 0; i < 7; i++) {
+ // Initialize doubleArguments with default values.
+ double doubleArguments[7] {
+ 0, 0, 1, 0, 0, 0, 0
+ };
+ unsigned numberOfUsedArguments = std::max(std::min<unsigned>(7U, args.size()), 1U);
+ for (unsigned i = 0; i < numberOfUsedArguments; ++i) {
doubleArguments[i] = args.at(i).toNumber(exec);
RETURN_IF_EXCEPTION(scope, 0);
}
+ for (unsigned i = 0; i < numberOfUsedArguments; ++i) {
+ if (!std::isfinite(doubleArguments[i]) || (doubleArguments[i] > INT_MAX) || (doubleArguments[i] < INT_MIN))
+ return PNaN;
+ }
- int numArgs = args.size();
-
- if ((!std::isfinite(doubleArguments[0]) || (doubleArguments[0] > INT_MAX) || (doubleArguments[0] < INT_MIN))
- || (!std::isfinite(doubleArguments[1]) || (doubleArguments[1] > INT_MAX) || (doubleArguments[1] < INT_MIN))
- || (numArgs >= 3 && (!std::isfinite(doubleArguments[2]) || (doubleArguments[2] > INT_MAX) || (doubleArguments[2] < INT_MIN)))
- || (numArgs >= 4 && (!std::isfinite(doubleArguments[3]) || (doubleArguments[3] > INT_MAX) || (doubleArguments[3] < INT_MIN)))
- || (numArgs >= 5 && (!std::isfinite(doubleArguments[4]) || (doubleArguments[4] > INT_MAX) || (doubleArguments[4] < INT_MIN)))
- || (numArgs >= 6 && (!std::isfinite(doubleArguments[5]) || (doubleArguments[5] > INT_MAX) || (doubleArguments[5] < INT_MIN)))
- || (numArgs >= 7 && (!std::isfinite(doubleArguments[6]) || (doubleArguments[6] > INT_MAX) || (doubleArguments[6] < INT_MIN))))
- return PNaN;
-
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
t.setYear((year >= 0 && year <= 99) ? (year + 1900) : year);
t.setMonth(JSC::toInt32(doubleArguments[1]));
- t.setMonthDay((numArgs >= 3) ? JSC::toInt32(doubleArguments[2]) : 1);
+ t.setMonthDay(JSC::toInt32(doubleArguments[2]));
t.setHour(JSC::toInt32(doubleArguments[3]));
t.setMinute(JSC::toInt32(doubleArguments[4]));
t.setSecond(JSC::toInt32(doubleArguments[5]));
t.setIsDST(-1);
- double ms = (numArgs >= 7) ? doubleArguments[6] : 0;
- return gregorianDateTimeToMS(vm, t, ms, timeType);
+ return gregorianDateTimeToMS(vm, t, doubleArguments[6], timeType);
}
// ECMA 15.9.3