WebKit Bugzilla
Attachment 346906 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-20180811002826.patch (text/plain), 5.25 KB, created by
Yusuke Suzuki
on 2018-08-10 08:28:27 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-08-10 08:28:27 PDT
Size:
5.25 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..d0c2fc223c12d03c382286f88c01d6559515610f 100644 >--- a/Source/JavaScriptCore/runtime/DateConstructor.cpp >+++ b/Source/JavaScriptCore/runtime/DateConstructor.cpp >@@ -88,34 +88,35 @@ 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 >+ }; >+ // First value "year" is not optional. The others are optional. >+ doubleArguments[0] = args.at(0).toNumber(exec); >+ RETURN_IF_EXCEPTION(scope, 0); >+ >+ unsigned numberOfUsedArguments = std::min<unsigned>(7U, args.size()); >+ for (unsigned i = 1; 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/ChangeLog b/JSTests/ChangeLog >index e83671fd371f22362816ec9cf7593dccd37eb84d..d8a0bf6cee8455f69869bf947d4792a8ed9351b4 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,13 @@ >+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!). >+ >+ * 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..4e723a9cccfd868aa1bf888dbbc19026693b81b8 >--- /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()), false); >+ 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
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188378
:
346904
|
346905
|
346906
|
346908