Title: [286560] trunk/Source
Revision
286560
Author
drou...@apple.com
Date
2021-12-06 12:04:24 -0800 (Mon, 06 Dec 2021)

Log Message

Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates
https://bugs.webkit.org/show_bug.cgi?id=233781

Reviewed by Darin Adler.

JS `Date` is milliseconds-based, but some native dates (e.g. `NSDate`) are seconds-based.
`WallTime` will help avoid confusion since not a generic type (e.g. `double`) and instead
has explicitly defined conversion methods to seconds, milliseconds, etc..

Source/WebCore:

* bindings/IDLTypes.h:
(WebCore::IDLDate::nullValue):
(WebCore::IDLDate::isNullValue):
(WebCore::IDLDate::extractValueFromNullable):
* bindings/js/JSDOMConvertDate.h:
(WebCore::Converter<IDLDate>::convert):
(WebCore::JSConverter<IDLDate>::convert):
* bindings/js/JSDOMConvertDate.cpp:
(WebCore::jsDate):
(WebCore::valueToDate):

* Modules/applepay/ApplePayLineItem.h:
(WebCore::ApplePayLineItem::decode):
* Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm:
(WebCore::toDate):
* bindings/js/IDBBindingUtilities.cpp:
(WebCore::get):
(WebCore::toJS):
(WebCore::createIDBKeyFromValue):
* html/BaseDateAndTimeInputType.h:
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::valueAsDate const):
(WebCore::DateTimeLocalInputType::setValueAsDate const):
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::valueAsDate const):
(WebCore::BaseDateAndTimeInputType::setValueAsDate const):
* html/DateTimeLocalInputType.h:
* html/HTMLInputElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::valueAsDate const):
(WebCore::HTMLInputElement::setValueAsDate):
* html/InputType.h:
* html/InputType.cpp:
(WebCore::InputType::valueAsDate const):
(WebCore::InputType::setValueAsDate const):
* html/MonthInputType.h:
* html/MonthInputType.cpp:
(WebCore::MonthInputType::valueAsDate const):

* html/HTMLMediaElement.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::getStartDate const):
This also fixes an apparently longstanding bug in that `MediaTime::toDouble` is apparently a
seconds-based value, so this is the one case that doesn't need `Seconds::fromMilliseconds`.

Source/WebKitLegacy/mac:

* DOM/DOMInternal.h:
(kit):
(core):

* DOM/DOMHTMLMediaElement.mm:
(-[DOMHTMLMediaElement getStartDate]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286559 => 286560)


--- trunk/Source/WebCore/ChangeLog	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/ChangeLog	2021-12-06 20:04:24 UTC (rev 286560)
@@ -1,3 +1,59 @@
+2021-12-06  Devin Rousso  <drou...@apple.com>
+
+        Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates
+        https://bugs.webkit.org/show_bug.cgi?id=233781
+
+        Reviewed by Darin Adler.
+
+        JS `Date` is milliseconds-based, but some native dates (e.g. `NSDate`) are seconds-based.
+        `WallTime` will help avoid confusion since not a generic type (e.g. `double`) and instead
+        has explicitly defined conversion methods to seconds, milliseconds, etc..
+
+        * bindings/IDLTypes.h:
+        (WebCore::IDLDate::nullValue):
+        (WebCore::IDLDate::isNullValue):
+        (WebCore::IDLDate::extractValueFromNullable):
+        * bindings/js/JSDOMConvertDate.h:
+        (WebCore::Converter<IDLDate>::convert):
+        (WebCore::JSConverter<IDLDate>::convert):
+        * bindings/js/JSDOMConvertDate.cpp:
+        (WebCore::jsDate):
+        (WebCore::valueToDate):
+
+        * Modules/applepay/ApplePayLineItem.h:
+        (WebCore::ApplePayLineItem::decode):
+        * Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm:
+        (WebCore::toDate):
+        * bindings/js/IDBBindingUtilities.cpp:
+        (WebCore::get):
+        (WebCore::toJS):
+        (WebCore::createIDBKeyFromValue):
+        * html/BaseDateAndTimeInputType.h:
+        * html/DateTimeLocalInputType.cpp:
+        (WebCore::DateTimeLocalInputType::valueAsDate const):
+        (WebCore::DateTimeLocalInputType::setValueAsDate const):
+        * html/BaseDateAndTimeInputType.cpp:
+        (WebCore::BaseDateAndTimeInputType::valueAsDate const):
+        (WebCore::BaseDateAndTimeInputType::setValueAsDate const):
+        * html/DateTimeLocalInputType.h:
+        * html/HTMLInputElement.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::valueAsDate const):
+        (WebCore::HTMLInputElement::setValueAsDate):
+        * html/InputType.h:
+        * html/InputType.cpp:
+        (WebCore::InputType::valueAsDate const):
+        (WebCore::InputType::setValueAsDate const):
+        * html/MonthInputType.h:
+        * html/MonthInputType.cpp:
+        (WebCore::MonthInputType::valueAsDate const):
+
+        * html/HTMLMediaElement.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::getStartDate const):
+        This also fixes an apparently longstanding bug in that `MediaTime::toDouble` is apparently a
+        seconds-based value, so this is the one case that doesn't need `Seconds::fromMilliseconds`.
+
 2021-12-06  Patrick Angle  <pan...@apple.com>
 
         Web Inspector: Support Cascade Layers in the Styles sidebar

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayLineItem.h (286559 => 286560)


--- trunk/Source/WebCore/Modules/applepay/ApplePayLineItem.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayLineItem.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -29,8 +29,8 @@
 
 #include "ApplePayPaymentTiming.h"
 #include "ApplePayRecurringPaymentDateUnit.h"
-#include <limits>
 #include <optional>
+#include <wtf/WallTime.h>
 #include <wtf/text/WTFString.h>
 
 #if USE(APPLE_INTERNAL_SDK)
@@ -52,14 +52,14 @@
     ApplePayPaymentTiming paymentTiming { ApplePayPaymentTiming::Immediate };
 
 #if ENABLE(APPLE_PAY_RECURRING_LINE_ITEM)
-    double recurringPaymentStartDate { std::numeric_limits<double>::quiet_NaN() };
+    WallTime recurringPaymentStartDate { WallTime::nan() };
     ApplePayRecurringPaymentDateUnit recurringPaymentIntervalUnit { ApplePayRecurringPaymentDateUnit::Month };
     unsigned recurringPaymentIntervalCount = 1;
-    double recurringPaymentEndDate { std::numeric_limits<double>::quiet_NaN() };
+    WallTime recurringPaymentEndDate { WallTime::nan() };
 #endif
 
 #if ENABLE(APPLE_PAY_DEFERRED_LINE_ITEM)
-    double deferredPaymentDate { std::numeric_limits<double>::quiet_NaN() };
+    WallTime deferredPaymentDate { WallTime::nan() };
 #endif
 
 #if defined(ApplePayLineItemAdditions_members)
@@ -105,13 +105,13 @@
     DECODE(amount, String)
     DECODE(paymentTiming, ApplePayPaymentTiming)
 #if ENABLE(APPLE_PAY_RECURRING_LINE_ITEM)
-    DECODE(recurringPaymentStartDate, double)
+    DECODE(recurringPaymentStartDate, WallTime)
     DECODE(recurringPaymentIntervalUnit, ApplePayRecurringPaymentDateUnit)
     DECODE(recurringPaymentIntervalCount, unsigned)
-    DECODE(recurringPaymentEndDate, double)
+    DECODE(recurringPaymentEndDate, WallTime)
 #endif
 #if ENABLE(APPLE_PAY_DEFERRED_LINE_ITEM)
-    DECODE(deferredPaymentDate, double)
+    DECODE(deferredPaymentDate, WallTime)
 #endif
 #if defined(ApplePayLineItemAdditions_decode_members)
     ApplePayLineItemAdditions_decode_members

Modified: trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm (286559 => 286560)


--- trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm	2021-12-06 20:04:24 UTC (rev 286560)
@@ -60,9 +60,9 @@
 
 #if HAVE(PASSKIT_RECURRING_SUMMARY_ITEM) || HAVE(PASSKIT_DEFERRED_SUMMARY_ITEM)
 
-static NSDate *toDate(double date)
+static NSDate *toDate(WallTime date)
 {
-    return [NSDate dateWithTimeIntervalSince1970:(date / 1000)];
+    return [NSDate dateWithTimeIntervalSince1970:date.secondsSinceEpoch().value()];
 }
 
 #endif // HAVE(PASSKIT_RECURRING_SUMMARY_ITEM) || HAVE(PASSKIT_DEFERRED_SUMMARY_ITEM)

Modified: trunk/Source/WebCore/bindings/IDLTypes.h (286559 => 286560)


--- trunk/Source/WebCore/bindings/IDLTypes.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/bindings/IDLTypes.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -32,6 +32,7 @@
 #include <wtf/Brigand.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/URL.h>
+#include <wtf/WallTime.h>
 
 #if ENABLE(WEBGL)
 #include "WebGLAny.h"
@@ -259,11 +260,11 @@
 
 // Non-WebIDL extensions
 
-struct IDLDate : IDLType<double> { 
-    using NullableType = double;
-    static double nullValue() { return std::numeric_limits<double>::quiet_NaN(); }
-    static bool isNullValue(double value) { return std::isnan(value); }
-    static double extractValueFromNullable(double value) { return value; }
+struct IDLDate : IDLType<WallTime> { 
+    using NullableType = WallTime;
+    static WallTime nullValue() { return WallTime::nan(); }
+    static bool isNullValue(WallTime value) { return std::isnan(value); }
+    static WallTime extractValueFromNullable(WallTime value) { return value; }
 };
 
 struct IDLJSON : IDLType<String> { 

Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp (286559 => 286560)


--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -101,7 +101,7 @@
             return true;
         }
         if (keyPathElement == "lastModifiedDate") {
-            result = jsDate(lexicalGlobalObject, jsCast<JSFile*>(obj)->wrapped().lastModified());
+            result = jsDate(lexicalGlobalObject, WallTime::fromRawSeconds(Seconds::fromMilliseconds(jsCast<JSFile*>(obj)->wrapped().lastModified()).value()));
             return true;
         }
     }
@@ -177,7 +177,7 @@
     case IndexedDB::KeyType::Date:
         // FIXME: This should probably be toJS<IDLDate>(...) as per:
         // http://w3c.github.io/IndexedDB/#request-convert-a-key-to-a-value
-        RELEASE_AND_RETURN(scope, toJS<IDLNullable<IDLDate>>(lexicalGlobalObject, key->date()));
+        RELEASE_AND_RETURN(scope, toJS<IDLNullable<IDLDate>>(lexicalGlobalObject, WallTime::fromRawSeconds(Seconds::fromMilliseconds(key->date()).value())));
     case IndexedDB::KeyType::Number:
         return jsNumber(key->number());
     case IndexedDB::KeyType::Min:
@@ -211,7 +211,7 @@
         auto dateValue = valueToDate(lexicalGlobalObject, value);
         RETURN_IF_EXCEPTION(scope, { });
         if (!std::isnan(dateValue))
-            return IDBKey::createDate(dateValue);
+            return IDBKey::createDate(dateValue.secondsSinceEpoch().milliseconds());
     }
 
     if (value.isObject()) {

Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp (286559 => 286560)


--- trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -30,21 +30,24 @@
 namespace WebCore {
 using namespace JSC;
 
-JSValue jsDate(JSGlobalObject& lexicalGlobalObject, double value)
+JSValue jsDate(JSGlobalObject& lexicalGlobalObject, WallTime value)
 {
-    return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value);
+    return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value.secondsSinceEpoch().milliseconds());
 }
 
-double valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value)
+WallTime valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value)
 {
+    double milliseconds = std::numeric_limits<double>::quiet_NaN();
+
     auto& vm = lexicalGlobalObject.vm();
     if (value.inherits<DateInstance>(vm))
-        return jsCast<DateInstance*>(value)->internalNumber();
-    if (value.isNumber())
-        return value.asNumber();
-    if (value.isString())
-        return vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject));
-    return std::numeric_limits<double>::quiet_NaN();
+        milliseconds = jsCast<DateInstance*>(value)->internalNumber();
+    else if (value.isNumber())
+        milliseconds = value.asNumber();
+    else if (value.isString())
+        milliseconds = vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject));
+
+    return WallTime::fromRawSeconds(Seconds::fromMilliseconds(milliseconds).value());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h (286559 => 286560)


--- trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -28,14 +28,15 @@
 #include "IDLTypes.h"
 #include "JSDOMConvertBase.h"
 #include <_javascript_Core/JSGlobalObject.h>
+#include <wtf/WallTime.h>
 
 namespace WebCore {
 
-JSC::JSValue jsDate(JSC::JSGlobalObject&, double value);
-double valueToDate(JSC::JSGlobalObject&, JSC::JSValue); // NaN if the value can't be converted to a date.
+JSC::JSValue jsDate(JSC::JSGlobalObject&, WallTime value);
+WallTime valueToDate(JSC::JSGlobalObject&, JSC::JSValue); // NaN if the value can't be converted to a date.
 
 template<> struct Converter<IDLDate> : DefaultConverter<IDLDate> {
-    static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
+    static WallTime convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)
     {
         return valueToDate(lexicalGlobalObject, value);
     }
@@ -46,7 +47,7 @@
     static constexpr bool needsGlobalObject = false;
 
     // FIXME: This should be taking a JSDOMGlobalObject and passing it to jsDate.
-    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, double value)
+    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, WallTime value)
     {
         return jsDate(lexicalGlobalObject, value);
     }

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -127,15 +127,15 @@
     closeDateTimeChooser();
 }
 
-double BaseDateAndTimeInputType::valueAsDate() const
+WallTime BaseDateAndTimeInputType::valueAsDate() const
 {
-    return valueAsDouble();
+    return WallTime::fromRawSeconds(Seconds::fromMilliseconds(valueAsDouble()).value());
 }
 
-ExceptionOr<void> BaseDateAndTimeInputType::setValueAsDate(double value) const
+ExceptionOr<void> BaseDateAndTimeInputType::setValueAsDate(WallTime value) const
 {
     ASSERT(element());
-    element()->setValue(serializeWithMilliseconds(value));
+    element()->setValue(serializeWithMilliseconds(value.secondsSinceEpoch().milliseconds()));
     return { };
 }
 

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.h (286559 => 286560)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -102,8 +102,8 @@
     String visibleValue() const final;
     String sanitizeValue(const String&) const final;
     void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final;
-    double valueAsDate() const override;
-    ExceptionOr<void> setValueAsDate(double) const override;
+    WallTime valueAsDate() const override;
+    ExceptionOr<void> setValueAsDate(WallTime) const override;
     double valueAsDouble() const final;
     ExceptionOr<void> setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const final;
     Decimal defaultValueForStepUp() const override;

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -62,13 +62,13 @@
     return DateComponentsType::DateTimeLocal;
 }
 
-double DateTimeLocalInputType::valueAsDate() const
+WallTime DateTimeLocalInputType::valueAsDate() const
 {
     // valueAsDate doesn't work for the datetime-local type according to the standard.
-    return DateComponents::invalidMilliseconds();
+    return WallTime::nan();
 }
 
-ExceptionOr<void> DateTimeLocalInputType::setValueAsDate(double value) const
+ExceptionOr<void> DateTimeLocalInputType::setValueAsDate(WallTime value) const
 {
     // valueAsDate doesn't work for the datetime-local type according to the standard.
     return InputType::setValueAsDate(value);

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.h (286559 => 286560)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -47,8 +47,8 @@
 private:
     const AtomString& formControlType() const final;
     DateComponentsType dateType() const final;
-    double valueAsDate() const final;
-    ExceptionOr<void> setValueAsDate(double) const final;
+    WallTime valueAsDate() const final;
+    ExceptionOr<void> setValueAsDate(WallTime) const final;
     StepRange createStepRange(AnyStepHandling) const final;
     std::optional<DateComponents> parseToDateComponents(StringView) const final;
     std::optional<DateComponents> setMillisecondToDateComponents(double) const final;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -1108,12 +1108,12 @@
     updateValidity();
 }
 
-double HTMLInputElement::valueAsDate() const
+WallTime HTMLInputElement::valueAsDate() const
 {
     return m_inputType->valueAsDate();
 }
 
-ExceptionOr<void> HTMLInputElement::setValueAsDate(double value)
+ExceptionOr<void> HTMLInputElement::setValueAsDate(WallTime value)
 {
     return m_inputType->setValueAsDate(value);
 }

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (286559 => 286560)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -184,8 +184,8 @@
     // The value which is drawn by a renderer.
     String visibleValue() const;
 
-    WEBCORE_EXPORT double valueAsDate() const;
-    WEBCORE_EXPORT ExceptionOr<void> setValueAsDate(double);
+    WEBCORE_EXPORT WallTime valueAsDate() const;
+    WEBCORE_EXPORT ExceptionOr<void> setValueAsDate(WallTime);
 
     WEBCORE_EXPORT double valueAsNumber() const;
     WEBCORE_EXPORT ExceptionOr<void> setValueAsNumber(double, TextFieldEventBehavior = DispatchNoEvent);

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -1111,11 +1111,12 @@
     return canPlay;
 }
 
-double HTMLMediaElement::getStartDate() const
+WallTime HTMLMediaElement::getStartDate() const
 {
     if (!m_player)
-        return std::numeric_limits<double>::quiet_NaN();
-    return m_player->getStartDate().toDouble();
+        return WallTime::nan();
+
+    return WallTime::fromRawSeconds(m_player->getStartDate().toDouble());
 }
 
 void HTMLMediaElement::load()

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (286559 => 286560)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -46,6 +46,7 @@
 #include <wtf/Function.h>
 #include <wtf/LoggerHelper.h>
 #include <wtf/Observer.h>
+#include <wtf/WallTime.h>
 #include <wtf/WeakPtr.h>
 
 #if USE(AUDIO_SESSION) && PLATFORM(MAC)
@@ -242,7 +243,7 @@
     void setCurrentTimeWithTolerance(double, double toleranceBefore, double toleranceAfter);
     double currentTimeForBindings() const { return currentTime(); }
     WEBCORE_EXPORT ExceptionOr<void> setCurrentTimeForBindings(double);
-    WEBCORE_EXPORT double getStartDate() const;
+    WEBCORE_EXPORT WallTime getStartDate() const;
     WEBCORE_EXPORT double duration() const override;
     WEBCORE_EXPORT bool paused() const override;
     void setPaused(bool);

Modified: trunk/Source/WebCore/html/InputType.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/InputType.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/InputType.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -204,12 +204,12 @@
     return true;
 }
 
-double InputType::valueAsDate() const
+WallTime InputType::valueAsDate() const
 {
-    return DateComponents::invalidMilliseconds();
+    return WallTime::nan();
 }
 
-ExceptionOr<void> InputType::setValueAsDate(double) const
+ExceptionOr<void> InputType::setValueAsDate(WallTime) const
 {
     return Exception { InvalidStateError };
 }

Modified: trunk/Source/WebCore/html/InputType.h (286559 => 286560)


--- trunk/Source/WebCore/html/InputType.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/InputType.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -220,8 +220,8 @@
     virtual bool getTypeSpecificValue(String&); // Checked first, before internal storage or the value attribute.
     virtual String fallbackValue() const; // Checked last, if both internal storage and value attribute are missing.
     virtual String defaultValue() const; // Checked after even fallbackValue, only when the valueWithDefault function is called.
-    virtual double valueAsDate() const;
-    virtual ExceptionOr<void> setValueAsDate(double) const;
+    virtual WallTime valueAsDate() const;
+    virtual ExceptionOr<void> setValueAsDate(WallTime) const;
     virtual double valueAsDouble() const;
     virtual ExceptionOr<void> setValueAsDouble(double, TextFieldEventBehavior) const;
     virtual ExceptionOr<void> setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const;

Modified: trunk/Source/WebCore/html/MonthInputType.cpp (286559 => 286560)


--- trunk/Source/WebCore/html/MonthInputType.cpp	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/MonthInputType.cpp	2021-12-06 20:04:24 UTC (rev 286560)
@@ -64,15 +64,15 @@
     return DateComponentsType::Month;
 }
 
-double MonthInputType::valueAsDate() const
+WallTime MonthInputType::valueAsDate() const
 {
     ASSERT(element());
     auto date = parseToDateComponents(element()->value());
     if (!date)
-        return DateComponents::invalidMilliseconds();
+        return WallTime::nan();
     double msec = date->millisecondsSinceEpoch();
     ASSERT(std::isfinite(msec));
-    return msec;
+    return WallTime::fromRawSeconds(Seconds::fromMilliseconds(msec).value());
 }
 
 String MonthInputType::serializeWithMilliseconds(double value) const

Modified: trunk/Source/WebCore/html/MonthInputType.h (286559 => 286560)


--- trunk/Source/WebCore/html/MonthInputType.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebCore/html/MonthInputType.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -47,7 +47,7 @@
 private:
     const AtomString& formControlType() const override;
     DateComponentsType dateType() const override;
-    double valueAsDate() const override;
+    WallTime valueAsDate() const override;
     String serializeWithMilliseconds(double) const override;
     Decimal parseToNumber(const String&, const Decimal&) const override;
     Decimal defaultValueForStepUp() const override;

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (286559 => 286560)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-06 20:04:24 UTC (rev 286560)
@@ -1,3 +1,21 @@
+2021-12-06  Devin Rousso  <drou...@apple.com>
+
+        Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates
+        https://bugs.webkit.org/show_bug.cgi?id=233781
+
+        Reviewed by Darin Adler.
+
+        JS `Date` is milliseconds-based, but some native dates (e.g. `NSDate`) are seconds-based.
+        `WallTime` will help avoid confusion since not a generic type (e.g. `double`) and instead
+        has explicitly defined conversion methods to seconds, milliseconds, etc..
+
+        * DOM/DOMInternal.h:
+        (kit):
+        (core):
+
+        * DOM/DOMHTMLMediaElement.mm:
+        (-[DOMHTMLMediaElement getStartDate]):
+
 2021-12-02  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [WebGPU] Hook up navigator.gpu.requestAdapter()

Modified: trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLMediaElement.mm (286559 => 286560)


--- trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLMediaElement.mm	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLMediaElement.mm	2021-12-06 20:04:24 UTC (rev 286560)
@@ -28,6 +28,7 @@
 
 #import "DOMHTMLMediaElement.h"
 
+#import "DOMInternal.h"
 #import "DOMMediaErrorInternal.h"
 #import "DOMNodeInternal.h"
 #import "DOMTimeRangesInternal.h"
@@ -313,7 +314,7 @@
 - (NSTimeInterval)getStartDate
 {
     WebCore::JSMainThreadNullState state;
-    return IMPL->getStartDate();
+    return kit(IMPL->getStartDate());
 }
 
 - (void)play

Modified: trunk/Source/WebKitLegacy/mac/DOM/DOMInternal.h (286559 => 286560)


--- trunk/Source/WebKitLegacy/mac/DOM/DOMInternal.h	2021-12-06 20:02:14 UTC (rev 286559)
+++ trunk/Source/WebKitLegacy/mac/DOM/DOMInternal.h	2021-12-06 20:04:24 UTC (rev 286560)
@@ -29,6 +29,7 @@
 #import "DOMObject.h"
 #import "DOMXPathNSResolver.h"
 #import <wtf/Forward.h>
+#import <wtf/WallTime.h>
 
 namespace JSC {
     class JSObject;
@@ -77,12 +78,12 @@
 DOMNativeXPathNSResolver *kit(WebCore::XPathNSResolver*);
 WebCore::XPathNSResolver* core(DOMNativeXPathNSResolver *);
 
-inline NSTimeInterval kit(double msSinceEpoch)
+inline NSTimeInterval kit(WallTime time)
 {
-    return msSinceEpoch / 1000.0 - NSTimeIntervalSince1970;
+    return time.secondsSinceEpoch().value() - NSTimeIntervalSince1970;
 }
 
-inline double core(NSTimeInterval sec)
+inline WallTime core(NSTimeInterval sec)
 {
-    return sec * 1000.0 + NSTimeIntervalSince1970;
+    return WallTime::fromRawSeconds(sec + NSTimeIntervalSince1970);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to