Title: [293808] trunk
Revision
293808
Author
ysuz...@apple.com
Date
2022-05-04 17:51:07 -0700 (Wed, 04 May 2022)

Log Message

[JSC] Temporal.Instant since/until should not accept year / month / day / week units
https://bugs.webkit.org/show_bug.cgi?id=240097

Reviewed by Ross Kirsling.

Temporal.Instant.{since,until} should not accept year / month / day / week units as smallestUnit / largestUnit
according to the spec [1,2]. But we missed that and crashing with the attached test. This patch fixes it.

[1]: https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.until
[2]: https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.since

* JSTests/stress/temporal-instant-since-and-until-with-year-month-week-day.js: Added.
(shouldThrow):
(let.smallestUnit.of.units.shouldThrow):
(let.largestUnit.of.units.shouldThrow):
* Source/_javascript_Core/runtime/TemporalInstant.cpp:

Canonical link: https://commits.webkit.org/250281@main

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (293807 => 293808)


--- trunk/JSTests/ChangeLog	2022-05-05 00:44:40 UTC (rev 293807)
+++ trunk/JSTests/ChangeLog	2022-05-05 00:51:07 UTC (rev 293808)
@@ -1,3 +1,15 @@
+2022-05-04  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Temporal.Instant since/until should not accept year / month / day / week units
+        https://bugs.webkit.org/show_bug.cgi?id=240097
+
+        Reviewed by Ross Kirsling.
+
+        * stress/temporal-instant-since-and-until-with-year-month-week-day.js: Added.
+        (shouldThrow):
+        (let.smallestUnit.of.units.shouldThrow):
+        (let.largestUnit.of.units.shouldThrow):
+
 2022-05-04  Keith Miller  <keith_mil...@apple.com>
 
         May 2022 test262 update

Added: trunk/JSTests/stress/temporal-instant-since-and-until-with-year-month-week-day.js (0 => 293808)


--- trunk/JSTests/stress/temporal-instant-since-and-until-with-year-month-week-day.js	                        (rev 0)
+++ trunk/JSTests/stress/temporal-instant-since-and-until-with-year-month-week-day.js	2022-05-05 00:51:07 UTC (rev 293808)
@@ -0,0 +1,39 @@
+//@ requireOptions("--useTemporal=1")
+function shouldThrow(func, errorMessage) {
+    var errorThrown = false;
+    var error = null;
+    try {
+        func();
+    } catch (e) {
+        errorThrown = true;
+        error = e;
+    }
+    if (!errorThrown)
+        throw new Error('not thrown');
+    if (String(error) !== errorMessage)
+        throw new Error(`bad error: ${String(error)}`);
+}
+
+let earlier = new Temporal.Instant(1_000_000_000_000_000_000n);
+let later = new Temporal.Instant(1_000_090_061_987_654_321n);
+let units = [ "year", "month", "week", "day", ];
+for (let smallestUnit of units) {
+    shouldThrow(() => {
+        later.since(earlier, { smallestUnit });
+    }, `RangeError: smallestUnit is a disallowed unit`);
+}
+for (let largestUnit of units) {
+    shouldThrow(() => {
+        later.since(earlier, { largestUnit });
+    }, `RangeError: largestUnit is a disallowed unit`);
+}
+for (let smallestUnit of units) {
+    shouldThrow(() => {
+        earlier.until(later, { smallestUnit });
+    }, `RangeError: smallestUnit is a disallowed unit`);
+}
+for (let largestUnit of units) {
+    shouldThrow(() => {
+        earlier.until(later, { largestUnit });
+    }, `RangeError: largestUnit is a disallowed unit`);
+}

Modified: trunk/JSTests/test262/expectations.yaml (293807 => 293808)


--- trunk/JSTests/test262/expectations.yaml	2022-05-05 00:44:40 UTC (rev 293807)
+++ trunk/JSTests/test262/expectations.yaml	2022-05-05 00:51:07 UTC (rev 293808)
@@ -1110,15 +1110,9 @@
 test/built-ins/Temporal/Instant/prototype/round/smallestunit-string-shorthand.js:
   default: 'TypeError: options argument is not an object or undefined'
   strict mode: 'TypeError: options argument is not an object or undefined'
-test/built-ins/Temporal/Instant/prototype/since/largestunit-invalid-string.js:
-  default: 'Test262Error: "year" is not a valid value for largestUnit Expected a RangeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: "year" is not a valid value for largestUnit Expected a RangeError to be thrown but no exception was thrown at all'
 test/built-ins/Temporal/Instant/prototype/since/largestunit.js:
   default: 'Test262Error: does not include higher units than necessary (largest unit unspecified) nanoseconds result Expected SameValue(«40», «101») to be true'
   strict mode: 'Test262Error: does not include higher units than necessary (largest unit unspecified) nanoseconds result Expected SameValue(«40», «101») to be true'
-test/built-ins/Temporal/Instant/prototype/since/smallestunit-invalid-string.js:
-  default: 'Test262Error: "year" is not a valid value for smallest unit Expected a RangeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: "year" is not a valid value for smallest unit Expected a RangeError to be thrown but no exception was thrown at all'
 test/built-ins/Temporal/Instant/prototype/since/year-zero.js:
   default: 'Test262Error: reject minus zero as extended year Expected a RangeError to be thrown but no exception was thrown at all'
   strict mode: 'Test262Error: reject minus zero as extended year Expected a RangeError to be thrown but no exception was thrown at all'
@@ -1146,12 +1140,6 @@
 test/built-ins/Temporal/Instant/prototype/toString/year-format.js:
   default: 'Test262Error: year 0 formatted as 4-digit Expected SameValue(«+000000-07-01T21:30:36Z», «0000-07-01T21:30:36Z») to be true'
   strict mode: 'Test262Error: year 0 formatted as 4-digit Expected SameValue(«+000000-07-01T21:30:36Z», «0000-07-01T21:30:36Z») to be true'
-test/built-ins/Temporal/Instant/prototype/until/largestunit-invalid-string.js:
-  default: 'Test262Error: "year" is not a valid value for largestUnit Expected a RangeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: "year" is not a valid value for largestUnit Expected a RangeError to be thrown but no exception was thrown at all'
-test/built-ins/Temporal/Instant/prototype/until/smallestunit-invalid-string.js:
-  default: 'Test262Error: "year" is not a valid value for smallest unit Expected a RangeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: "year" is not a valid value for smallest unit Expected a RangeError to be thrown but no exception was thrown at all'
 test/built-ins/Temporal/Instant/prototype/until/year-zero.js:
   default: 'Test262Error: reject minus zero as extended year Expected a RangeError to be thrown but no exception was thrown at all'
   strict mode: 'Test262Error: reject minus zero as extended year Expected a RangeError to be thrown but no exception was thrown at all'

Modified: trunk/Source/_javascript_Core/ChangeLog (293807 => 293808)


--- trunk/Source/_javascript_Core/ChangeLog	2022-05-05 00:44:40 UTC (rev 293807)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-05-05 00:51:07 UTC (rev 293808)
@@ -1,5 +1,20 @@
 2022-05-04  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] Temporal.Instant since/until should not accept year / month / day / week units
+        https://bugs.webkit.org/show_bug.cgi?id=240097
+
+        Reviewed by Ross Kirsling.
+
+        Temporal.Instant.{since,until} should not accept year / month / day / week units as smallestUnit / largestUnit
+        according to the spec [1,2]. But we missed that and crashing with the attached test. This patch fixes it.
+
+        [1]: https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.until
+        [2]: https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.since
+
+        * runtime/TemporalInstant.cpp:
+
+2022-05-04  Yusuke Suzuki  <ysuz...@apple.com>
+
         [JSC] Use decontaminate in StructureID::decode
         https://bugs.webkit.org/show_bug.cgi?id=240088
 

Modified: trunk/Source/_javascript_Core/runtime/TemporalInstant.cpp (293807 => 293808)


--- trunk/Source/_javascript_Core/runtime/TemporalInstant.cpp	2022-05-05 00:44:40 UTC (rev 293807)
+++ trunk/Source/_javascript_Core/runtime/TemporalInstant.cpp	2022-05-05 00:51:07 UTC (rev 293808)
@@ -295,6 +295,8 @@
 
 ISO8601::Duration TemporalInstant::difference(JSGlobalObject* globalObject, TemporalInstant* other, JSValue optionsValue) const
 {
+    // https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.since
+    // https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.until
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
@@ -301,12 +303,12 @@
     JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
     RETURN_IF_EXCEPTION(scope, { });
 
-    auto smallest = temporalSmallestUnit(globalObject, options, { });
+    auto smallest = temporalSmallestUnit(globalObject, options, { TemporalUnit::Year, TemporalUnit::Month, TemporalUnit::Week, TemporalUnit::Day });
     RETURN_IF_EXCEPTION(scope, { });
     TemporalUnit smallestUnit = smallest.value_or(TemporalUnit::Nanosecond);
 
     TemporalUnit defaultLargestUnit = std::min(smallestUnit, TemporalUnit::Second);
-    auto largest = temporalLargestUnit(globalObject, options, { }, defaultLargestUnit);
+    auto largest = temporalLargestUnit(globalObject, options, { TemporalUnit::Year, TemporalUnit::Month, TemporalUnit::Week, TemporalUnit::Day }, defaultLargestUnit);
     RETURN_IF_EXCEPTION(scope, { });
     TemporalUnit largestUnit = largest.value_or(defaultLargestUnit);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to