Title: [293904] trunk/Source/_javascript_Core
- Revision
- 293904
- Author
- [email protected]
- Date
- 2022-05-06 10:39:42 -0700 (Fri, 06 May 2022)
Log Message
Temporal.Duration should handle -0 properly
https://bugs.webkit.org/show_bug.cgi?id=240145
Reviewed by Yusuke Suzuki.
r250284 broke a new test262 test which verifies that -0 is normalized to 0 in cases like
`new Temporal.Duration(-0)` and `Temporal.Duration.from({years: -0 })`.
This patch properly aligns these paths with the spec.
* runtime/JSCJSValue.h:
* runtime/JSCJSValueInlines.h:
(JSC::JSValue::toIntegerWithoutRounding const): Added.
(JSC::JSValue::toIntegerOrInfinity const):
* runtime/TemporalDuration.cpp:
(JSC::TemporalDuration::fromDurationLike):
* runtime/TemporalDurationConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
Canonical link: https://commits.webkit.org/250361@main
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (293903 => 293904)
--- trunk/Source/_javascript_Core/ChangeLog 2022-05-06 17:32:45 UTC (rev 293903)
+++ trunk/Source/_javascript_Core/ChangeLog 2022-05-06 17:39:42 UTC (rev 293904)
@@ -1,3 +1,23 @@
+2022-05-05 Ross Kirsling <[email protected]>
+
+ Temporal.Duration constructor should handle -0 properly
+ https://bugs.webkit.org/show_bug.cgi?id=240145
+
+ Reviewed by Yusuke Suzuki.
+
+ r250284 broke a new test262 test which verifies that -0 is normalized to 0 in cases like
+ `new Temporal.Duration(-0)` and `Temporal.Duration.from({years: -0 })`.
+ This patch properly aligns these paths with the spec.
+
+ * runtime/JSCJSValue.h:
+ * runtime/JSCJSValueInlines.h:
+ (JSC::JSValue::toIntegerWithoutRounding const): Added.
+ (JSC::JSValue::toIntegerOrInfinity const):
+ * runtime/TemporalDuration.cpp:
+ (JSC::TemporalDuration::fromDurationLike):
+ * runtime/TemporalDurationConstructor.cpp:
+ (JSC::JSC_DEFINE_HOST_FUNCTION):
+
2022-05-06 Fujii Hironori <[email protected]>
builtins-generator-tests are failing after 250242@main
Modified: trunk/Source/_javascript_Core/runtime/JSCJSValue.h (293903 => 293904)
--- trunk/Source/_javascript_Core/runtime/JSCJSValue.h 2022-05-06 17:32:45 UTC (rev 293903)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValue.h 2022-05-06 17:39:42 UTC (rev 293904)
@@ -293,6 +293,7 @@
// Integer conversions.
JS_EXPORT_PRIVATE double toIntegerPreserveNaN(JSGlobalObject*) const;
+ double toIntegerWithoutRounding(JSGlobalObject*) const;
double toIntegerOrInfinity(JSGlobalObject*) const;
int32_t toInt32(JSGlobalObject*) const;
uint32_t toUInt32(JSGlobalObject*) const;
Modified: trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h (293903 => 293904)
--- trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h 2022-05-06 17:32:45 UTC (rev 293903)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h 2022-05-06 17:39:42 UTC (rev 293904)
@@ -112,17 +112,21 @@
RELEASE_AND_RETURN(scope, outputOffset + static_cast<size_t>(static_cast<uint32_t>(JSC::toInt32(d - inputOffset))));
}
-// https://tc39.es/ecma262/#sec-tointegerorinfinity
-inline double JSValue::toIntegerOrInfinity(JSGlobalObject* globalObject) const
+// https://tc39.es/proposal-temporal/#sec-temporal-tointegerwithoutrounding
+inline double JSValue::toIntegerWithoutRounding(JSGlobalObject* globalObject) const
{
if (isInt32())
return asInt32();
double d = toNumber(globalObject);
- if (std::isnan(d) || !d)
- return 0.0;
- return trunc(d);
+ return (std::isnan(d) || !d) ? 0.0 : d;
}
+// https://tc39.es/ecma262/#sec-tointegerorinfinity
+inline double JSValue::toIntegerOrInfinity(JSGlobalObject* globalObject) const
+{
+ return trunc(toIntegerWithoutRounding(globalObject));
+}
+
inline bool JSValue::isUInt32() const
{
return isInt32() && asInt32() >= 0;
Modified: trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp (293903 => 293904)
--- trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp 2022-05-06 17:32:45 UTC (rev 293903)
+++ trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp 2022-05-06 17:39:42 UTC (rev 293904)
@@ -100,7 +100,7 @@
}
hasRelevantProperty = true;
- result[unit] = value.toNumber(globalObject);
+ result[unit] = value.toIntegerWithoutRounding(globalObject);
RETURN_IF_EXCEPTION(scope, { });
if (!isInteger(result[unit])) {
Modified: trunk/Source/_javascript_Core/runtime/TemporalDurationConstructor.cpp (293903 => 293904)
--- trunk/Source/_javascript_Core/runtime/TemporalDurationConstructor.cpp 2022-05-06 17:32:45 UTC (rev 293903)
+++ trunk/Source/_javascript_Core/runtime/TemporalDurationConstructor.cpp 2022-05-06 17:39:42 UTC (rev 293904)
@@ -96,7 +96,7 @@
if (value.isUndefined())
continue;
- result[i] = value.toNumber(globalObject);
+ result[i] = value.toIntegerWithoutRounding(globalObject);
RETURN_IF_EXCEPTION(scope, { });
if (!isInteger(result[i]))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes