WebKit Bugzilla
Attachment 346908 Details for
Bug 188378
: Date.UTC should not return NaN with only Year param
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188378-20180811020613.patch (text/plain), 5.63 KB, created by
Yusuke Suzuki
on 2018-08-10 10:06:15 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-08-10 10:06:15 PDT
Size:
5.63 KB
patch
obsolete
>Subversion Revision: 234753 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index f048ee111b4c7e6d6f68fd6039859a33b129f7a3..f4065d2105843ac254852b12920fb1a213c2076a 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,16 @@ >+2018-08-10 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ Date.UTC should not return NaN with only Year param >+ https://bugs.webkit.org/show_bug.cgi?id=188378 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 <keith_miller@apple.com> > > Array.prototype.sort should call @toLength instead of ">>> 0" >diff --git a/Source/JavaScriptCore/runtime/DateConstructor.cpp b/Source/JavaScriptCore/runtime/DateConstructor.cpp >index fd442216fec77ca2e4a7b188cfe0c256faae9053..e38e5ed87455f0b0942e80215ba83ecdaf801bf4 100644 >--- a/Source/JavaScriptCore/runtime/DateConstructor.cpp >+++ b/Source/JavaScriptCore/runtime/DateConstructor.cpp >@@ -88,34 +88,30 @@ static double millisecondsFromComponents(ExecState* exec, const ArgList& args, W > 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); > } >- >- 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; >+ for (unsigned i = 0; i < numberOfUsedArguments; ++i) { >+ if (!std::isfinite(doubleArguments[i]) || (doubleArguments[i] > INT_MAX) || (doubleArguments[i] < 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 >diff --git a/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc b/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc >new file mode 100644 >index 0000000000000000000000000000000000000000..2a565e712e9a4a2dd09e6a1574f97c25c3830ca4 >--- /dev/null >+++ b/JSTests/ChakraCore/test/Date/dateutc.baseline-jsc >@@ -0,0 +1,13 @@ >+126230400000 >+126230400000 >+149817600000 >+151804800000 >+151804800000 >+151806000000 >+151806030000 >+151806030040 >+151806030040 >+-2151877169960 >+151806030040 >+NaN >+NaN >diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog >index e83671fd371f22362816ec9cf7593dccd37eb84d..b3806aaefc5c2f645012cd08127ca002f30fc288 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,14 @@ >+2018-08-10 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ Date.UTC should not return NaN with only Year param >+ https://bugs.webkit.org/show_bug.cgi?id=188378 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * ChakraCore/test/Date/dateutc.baseline-jsc: Added. >+ * stress/date-utc-optional.js: Added. >+ (shouldBe): >+ > 2018-08-08 Keith Miller <keith_miller@apple.com> > > Array.prototype.sort should call @toLength instead of ">>> 0" >diff --git a/JSTests/stress/date-utc-optional.js b/JSTests/stress/date-utc-optional.js >new file mode 100644 >index 0000000000000000000000000000000000000000..f14f7c60c6b620c0b72106d7e4176a49248d1d09 >--- /dev/null >+++ b/JSTests/stress/date-utc-optional.js >@@ -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); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
keith_miller
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188378
:
346904
|
346905
|
346906
| 346908