Title: [291603] trunk
Revision
291603
Author
ysuz...@apple.com
Date
2022-03-21 21:26:31 -0700 (Mon, 21 Mar 2022)

Log Message

[JSC] Change Date.parse to stop returning numbers with fractional part
https://bugs.webkit.org/show_bug.cgi?id=238050

Reviewed by Saam Barati.

JSTests:

* stress/date-parse-timeclip.js: Added.
(shouldBe):

Source/_javascript_Core:

Date.parse should return NaN or integer numbers[1,2]. This patch applies timeClip
to the result of Date.parse to ensure that the returned value is time value.

[1]: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.parse
[2]: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-time-values-and-time-range

* runtime/DateConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (291602 => 291603)


--- trunk/JSTests/ChangeLog	2022-03-22 03:54:43 UTC (rev 291602)
+++ trunk/JSTests/ChangeLog	2022-03-22 04:26:31 UTC (rev 291603)
@@ -1,5 +1,15 @@
 2022-03-21  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] Change Date.parse to stop returning numbers with fractional part
+        https://bugs.webkit.org/show_bug.cgi?id=238050
+
+        Reviewed by Saam Barati.
+
+        * stress/date-parse-timeclip.js: Added.
+        (shouldBe):
+
+2022-03-21  Yusuke Suzuki  <ysuz...@apple.com>
+
         [JSC] ReferenceError when using extra parens in class fields
         https://bugs.webkit.org/show_bug.cgi?id=236843
 

Added: trunk/JSTests/stress/date-parse-timeclip.js (0 => 291603)


--- trunk/JSTests/stress/date-parse-timeclip.js	                        (rev 0)
+++ trunk/JSTests/stress/date-parse-timeclip.js	2022-03-22 04:26:31 UTC (rev 291603)
@@ -0,0 +1,22 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+[
+    "1970-01-01T00:00:00.000500001Z",
+    "1969-12-31T23:59:59.999515625Z",
+    "1969-12-31T23:59:59.999015625Z",
+].forEach(str => {
+    const tv = Date.parse(str);
+    shouldBe(Object.is(tv, 0), true);
+    shouldBe((new Date(str)).toISOString(), `1970-01-01T00:00:00.000Z`);
+});
+
+[
+    0.500001,
+    -0.484375,
+    -0.984375,
+].forEach(value => {
+    shouldBe(new Date(value).valueOf(), 0);
+});

Modified: trunk/Source/_javascript_Core/ChangeLog (291602 => 291603)


--- trunk/Source/_javascript_Core/ChangeLog	2022-03-22 03:54:43 UTC (rev 291602)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-03-22 04:26:31 UTC (rev 291603)
@@ -1,3 +1,19 @@
+2022-03-21  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Change Date.parse to stop returning numbers with fractional part
+        https://bugs.webkit.org/show_bug.cgi?id=238050
+
+        Reviewed by Saam Barati.
+
+        Date.parse should return NaN or integer numbers[1,2]. This patch applies timeClip
+        to the result of Date.parse to ensure that the returned value is time value.
+
+        [1]: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.parse
+        [2]: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-time-values-and-time-range
+
+        * runtime/DateConstructor.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+
 2022-03-21  Saam Barati  <sbar...@apple.com>
 
         Fix bug in Relationship::mergeImpl

Modified: trunk/Source/_javascript_Core/runtime/DateConstructor.cpp (291602 => 291603)


--- trunk/Source/_javascript_Core/runtime/DateConstructor.cpp	2022-03-22 03:54:43 UTC (rev 291602)
+++ trunk/Source/_javascript_Core/runtime/DateConstructor.cpp	2022-03-22 04:26:31 UTC (rev 291603)
@@ -159,7 +159,7 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
     String dateStr = callFrame->argument(0).toWTFString(globalObject);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    RELEASE_AND_RETURN(scope, JSValue::encode(jsNumber(vm.dateCache.parseDate(globalObject, vm, dateStr))));
+    RELEASE_AND_RETURN(scope, JSValue::encode(jsNumber(timeClip(vm.dateCache.parseDate(globalObject, vm, dateStr)))));
 }
 
 JSValue dateNowImpl()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to