Changeset 286560 in webkit
- Timestamp:
- Dec 6, 2021, 12:04:24 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 22 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/Modules/applepay/ApplePayLineItem.h (modified) (3 diffs)
-
WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm (modified) (1 diff)
-
WebCore/bindings/IDLTypes.h (modified) (2 diffs)
-
WebCore/bindings/js/IDBBindingUtilities.cpp (modified) (3 diffs)
-
WebCore/bindings/js/JSDOMConvertDate.cpp (modified) (1 diff)
-
WebCore/bindings/js/JSDOMConvertDate.h (modified) (2 diffs)
-
WebCore/html/BaseDateAndTimeInputType.cpp (modified) (1 diff)
-
WebCore/html/BaseDateAndTimeInputType.h (modified) (1 diff)
-
WebCore/html/DateTimeLocalInputType.cpp (modified) (1 diff)
-
WebCore/html/DateTimeLocalInputType.h (modified) (1 diff)
-
WebCore/html/HTMLInputElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLInputElement.h (modified) (1 diff)
-
WebCore/html/HTMLMediaElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLMediaElement.h (modified) (2 diffs)
-
WebCore/html/InputType.cpp (modified) (1 diff)
-
WebCore/html/InputType.h (modified) (1 diff)
-
WebCore/html/MonthInputType.cpp (modified) (1 diff)
-
WebCore/html/MonthInputType.h (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/DOM/DOMHTMLMediaElement.mm (modified) (2 diffs)
-
WebKitLegacy/mac/DOM/DOMInternal.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286558 r286560 1 2021-12-06 Devin Rousso <drousso@apple.com> 2 3 Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates 4 https://bugs.webkit.org/show_bug.cgi?id=233781 5 6 Reviewed by Darin Adler. 7 8 JS `Date` is milliseconds-based, but some native dates (e.g. `NSDate`) are seconds-based. 9 `WallTime` will help avoid confusion since not a generic type (e.g. `double`) and instead 10 has explicitly defined conversion methods to seconds, milliseconds, etc.. 11 12 * bindings/IDLTypes.h: 13 (WebCore::IDLDate::nullValue): 14 (WebCore::IDLDate::isNullValue): 15 (WebCore::IDLDate::extractValueFromNullable): 16 * bindings/js/JSDOMConvertDate.h: 17 (WebCore::Converter<IDLDate>::convert): 18 (WebCore::JSConverter<IDLDate>::convert): 19 * bindings/js/JSDOMConvertDate.cpp: 20 (WebCore::jsDate): 21 (WebCore::valueToDate): 22 23 * Modules/applepay/ApplePayLineItem.h: 24 (WebCore::ApplePayLineItem::decode): 25 * Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm: 26 (WebCore::toDate): 27 * bindings/js/IDBBindingUtilities.cpp: 28 (WebCore::get): 29 (WebCore::toJS): 30 (WebCore::createIDBKeyFromValue): 31 * html/BaseDateAndTimeInputType.h: 32 * html/DateTimeLocalInputType.cpp: 33 (WebCore::DateTimeLocalInputType::valueAsDate const): 34 (WebCore::DateTimeLocalInputType::setValueAsDate const): 35 * html/BaseDateAndTimeInputType.cpp: 36 (WebCore::BaseDateAndTimeInputType::valueAsDate const): 37 (WebCore::BaseDateAndTimeInputType::setValueAsDate const): 38 * html/DateTimeLocalInputType.h: 39 * html/HTMLInputElement.h: 40 * html/HTMLInputElement.cpp: 41 (WebCore::HTMLInputElement::valueAsDate const): 42 (WebCore::HTMLInputElement::setValueAsDate): 43 * html/InputType.h: 44 * html/InputType.cpp: 45 (WebCore::InputType::valueAsDate const): 46 (WebCore::InputType::setValueAsDate const): 47 * html/MonthInputType.h: 48 * html/MonthInputType.cpp: 49 (WebCore::MonthInputType::valueAsDate const): 50 51 * html/HTMLMediaElement.h: 52 * html/HTMLMediaElement.cpp: 53 (WebCore::HTMLMediaElement::getStartDate const): 54 This also fixes an apparently longstanding bug in that `MediaTime::toDouble` is apparently a 55 seconds-based value, so this is the one case that doesn't need `Seconds::fromMilliseconds`. 56 1 57 2021-12-06 Patrick Angle <pangle@apple.com> 2 58 -
trunk/Source/WebCore/Modules/applepay/ApplePayLineItem.h
r286344 r286560 30 30 #include "ApplePayPaymentTiming.h" 31 31 #include "ApplePayRecurringPaymentDateUnit.h" 32 #include <limits>33 32 #include <optional> 33 #include <wtf/WallTime.h> 34 34 #include <wtf/text/WTFString.h> 35 35 … … 53 53 54 54 #if ENABLE(APPLE_PAY_RECURRING_LINE_ITEM) 55 double recurringPaymentStartDate { std::numeric_limits<double>::quiet_NaN() };55 WallTime recurringPaymentStartDate { WallTime::nan() }; 56 56 ApplePayRecurringPaymentDateUnit recurringPaymentIntervalUnit { ApplePayRecurringPaymentDateUnit::Month }; 57 57 unsigned recurringPaymentIntervalCount = 1; 58 double recurringPaymentEndDate { std::numeric_limits<double>::quiet_NaN() };58 WallTime recurringPaymentEndDate { WallTime::nan() }; 59 59 #endif 60 60 61 61 #if ENABLE(APPLE_PAY_DEFERRED_LINE_ITEM) 62 double deferredPaymentDate { std::numeric_limits<double>::quiet_NaN() };62 WallTime deferredPaymentDate { WallTime::nan() }; 63 63 #endif 64 64 … … 106 106 DECODE(paymentTiming, ApplePayPaymentTiming) 107 107 #if ENABLE(APPLE_PAY_RECURRING_LINE_ITEM) 108 DECODE(recurringPaymentStartDate, double)108 DECODE(recurringPaymentStartDate, WallTime) 109 109 DECODE(recurringPaymentIntervalUnit, ApplePayRecurringPaymentDateUnit) 110 110 DECODE(recurringPaymentIntervalCount, unsigned) 111 DECODE(recurringPaymentEndDate, double)111 DECODE(recurringPaymentEndDate, WallTime) 112 112 #endif 113 113 #if ENABLE(APPLE_PAY_DEFERRED_LINE_ITEM) 114 DECODE(deferredPaymentDate, double)114 DECODE(deferredPaymentDate, WallTime) 115 115 #endif 116 116 #if defined(ApplePayLineItemAdditions_decode_members) -
trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm
r286454 r286560 61 61 #if HAVE(PASSKIT_RECURRING_SUMMARY_ITEM) || HAVE(PASSKIT_DEFERRED_SUMMARY_ITEM) 62 62 63 static NSDate *toDate( double date)63 static NSDate *toDate(WallTime date) 64 64 { 65 return [NSDate dateWithTimeIntervalSince1970: (date / 1000)];65 return [NSDate dateWithTimeIntervalSince1970:date.secondsSinceEpoch().value()]; 66 66 } 67 67 -
trunk/Source/WebCore/bindings/IDLTypes.h
r284857 r286560 33 33 #include <wtf/StdLibExtras.h> 34 34 #include <wtf/URL.h> 35 #include <wtf/WallTime.h> 35 36 36 37 #if ENABLE(WEBGL) … … 260 261 // Non-WebIDL extensions 261 262 262 struct IDLDate : IDLType< double> {263 using NullableType = double;264 static double nullValue() { return std::numeric_limits<double>::quiet_NaN(); }265 static bool isNullValue( double value) { return std::isnan(value); }266 static double extractValueFromNullable(double value) { return value; }263 struct IDLDate : IDLType<WallTime> { 264 using NullableType = WallTime; 265 static WallTime nullValue() { return WallTime::nan(); } 266 static bool isNullValue(WallTime value) { return std::isnan(value); } 267 static WallTime extractValueFromNullable(WallTime value) { return value; } 267 268 }; 268 269 -
trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp
r284095 r286560 102 102 } 103 103 if (keyPathElement == "lastModifiedDate") { 104 result = jsDate(lexicalGlobalObject, jsCast<JSFile*>(obj)->wrapped().lastModified());104 result = jsDate(lexicalGlobalObject, WallTime::fromRawSeconds(Seconds::fromMilliseconds(jsCast<JSFile*>(obj)->wrapped().lastModified()).value())); 105 105 return true; 106 106 } … … 178 178 // FIXME: This should probably be toJS<IDLDate>(...) as per: 179 179 // http://w3c.github.io/IndexedDB/#request-convert-a-key-to-a-value 180 RELEASE_AND_RETURN(scope, toJS<IDLNullable<IDLDate>>(lexicalGlobalObject, key->date()));180 RELEASE_AND_RETURN(scope, toJS<IDLNullable<IDLDate>>(lexicalGlobalObject, WallTime::fromRawSeconds(Seconds::fromMilliseconds(key->date()).value()))); 181 181 case IndexedDB::KeyType::Number: 182 182 return jsNumber(key->number()); … … 212 212 RETURN_IF_EXCEPTION(scope, { }); 213 213 if (!std::isnan(dateValue)) 214 return IDBKey::createDate(dateValue );214 return IDBKey::createDate(dateValue.secondsSinceEpoch().milliseconds()); 215 215 } 216 216 -
trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp
r274832 r286560 31 31 using namespace JSC; 32 32 33 JSValue jsDate(JSGlobalObject& lexicalGlobalObject, double value)33 JSValue jsDate(JSGlobalObject& lexicalGlobalObject, WallTime value) 34 34 { 35 return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value );35 return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value.secondsSinceEpoch().milliseconds()); 36 36 } 37 37 38 double valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value)38 WallTime valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value) 39 39 { 40 double milliseconds = std::numeric_limits<double>::quiet_NaN(); 41 40 42 auto& vm = lexicalGlobalObject.vm(); 41 43 if (value.inherits<DateInstance>(vm)) 42 return jsCast<DateInstance*>(value)->internalNumber(); 43 if (value.isNumber()) 44 return value.asNumber(); 45 if (value.isString()) 46 return vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject)); 47 return std::numeric_limits<double>::quiet_NaN(); 44 milliseconds = jsCast<DateInstance*>(value)->internalNumber(); 45 else if (value.isNumber()) 46 milliseconds = value.asNumber(); 47 else if (value.isString()) 48 milliseconds = vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject)); 49 50 return WallTime::fromRawSeconds(Seconds::fromMilliseconds(milliseconds).value()); 48 51 } 49 52 -
trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h
r273767 r286560 29 29 #include "JSDOMConvertBase.h" 30 30 #include <JavaScriptCore/JSGlobalObject.h> 31 #include <wtf/WallTime.h> 31 32 32 33 namespace WebCore { 33 34 34 JSC::JSValue jsDate(JSC::JSGlobalObject&, double value);35 double valueToDate(JSC::JSGlobalObject&, JSC::JSValue); // NaN if the value can't be converted to a date.35 JSC::JSValue jsDate(JSC::JSGlobalObject&, WallTime value); 36 WallTime valueToDate(JSC::JSGlobalObject&, JSC::JSValue); // NaN if the value can't be converted to a date. 36 37 37 38 template<> struct Converter<IDLDate> : DefaultConverter<IDLDate> { 38 static double convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)39 static WallTime convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) 39 40 { 40 41 return valueToDate(lexicalGlobalObject, value); … … 47 48 48 49 // FIXME: This should be taking a JSDOMGlobalObject and passing it to jsDate. 49 static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, double value)50 static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, WallTime value) 50 51 { 51 52 return jsDate(lexicalGlobalObject, value); -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp
r286413 r286560 128 128 } 129 129 130 double BaseDateAndTimeInputType::valueAsDate() const131 { 132 return valueAsDouble();133 } 134 135 ExceptionOr<void> BaseDateAndTimeInputType::setValueAsDate( double value) const136 { 137 ASSERT(element()); 138 element()->setValue(serializeWithMilliseconds(value ));130 WallTime BaseDateAndTimeInputType::valueAsDate() const 131 { 132 return WallTime::fromRawSeconds(Seconds::fromMilliseconds(valueAsDouble()).value()); 133 } 134 135 ExceptionOr<void> BaseDateAndTimeInputType::setValueAsDate(WallTime value) const 136 { 137 ASSERT(element()); 138 element()->setValue(serializeWithMilliseconds(value.secondsSinceEpoch().milliseconds())); 139 139 return { }; 140 140 } -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.h
r282242 r286560 103 103 String sanitizeValue(const String&) const final; 104 104 void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final; 105 double valueAsDate() const override;106 ExceptionOr<void> setValueAsDate( double) const override;105 WallTime valueAsDate() const override; 106 ExceptionOr<void> setValueAsDate(WallTime) const override; 107 107 double valueAsDouble() const final; 108 108 ExceptionOr<void> setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const final; -
trunk/Source/WebCore/html/DateTimeLocalInputType.cpp
r283851 r286560 63 63 } 64 64 65 double DateTimeLocalInputType::valueAsDate() const65 WallTime DateTimeLocalInputType::valueAsDate() const 66 66 { 67 67 // valueAsDate doesn't work for the datetime-local type according to the standard. 68 return DateComponents::invalidMilliseconds();68 return WallTime::nan(); 69 69 } 70 70 71 ExceptionOr<void> DateTimeLocalInputType::setValueAsDate( double value) const71 ExceptionOr<void> DateTimeLocalInputType::setValueAsDate(WallTime value) const 72 72 { 73 73 // valueAsDate doesn't work for the datetime-local type according to the standard. -
trunk/Source/WebCore/html/DateTimeLocalInputType.h
r282242 r286560 48 48 const AtomString& formControlType() const final; 49 49 DateComponentsType dateType() const final; 50 double valueAsDate() const final;51 ExceptionOr<void> setValueAsDate( double) const final;50 WallTime valueAsDate() const final; 51 ExceptionOr<void> setValueAsDate(WallTime) const final; 52 52 StepRange createStepRange(AnyStepHandling) const final; 53 53 std::optional<DateComponents> parseToDateComponents(StringView) const final; -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r286482 r286560 1109 1109 } 1110 1110 1111 double HTMLInputElement::valueAsDate() const1111 WallTime HTMLInputElement::valueAsDate() const 1112 1112 { 1113 1113 return m_inputType->valueAsDate(); 1114 1114 } 1115 1115 1116 ExceptionOr<void> HTMLInputElement::setValueAsDate( double value)1116 ExceptionOr<void> HTMLInputElement::setValueAsDate(WallTime value) 1117 1117 { 1118 1118 return m_inputType->setValueAsDate(value); -
trunk/Source/WebCore/html/HTMLInputElement.h
r286447 r286560 185 185 String visibleValue() const; 186 186 187 WEBCORE_EXPORT double valueAsDate() const;188 WEBCORE_EXPORT ExceptionOr<void> setValueAsDate( double);187 WEBCORE_EXPORT WallTime valueAsDate() const; 188 WEBCORE_EXPORT ExceptionOr<void> setValueAsDate(WallTime); 189 189 190 190 WEBCORE_EXPORT double valueAsNumber() const; -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r285655 r286560 1112 1112 } 1113 1113 1114 double HTMLMediaElement::getStartDate() const1114 WallTime HTMLMediaElement::getStartDate() const 1115 1115 { 1116 1116 if (!m_player) 1117 return std::numeric_limits<double>::quiet_NaN(); 1118 return m_player->getStartDate().toDouble(); 1117 return WallTime::nan(); 1118 1119 return WallTime::fromRawSeconds(m_player->getStartDate().toDouble()); 1119 1120 } 1120 1121 -
trunk/Source/WebCore/html/HTMLMediaElement.h
r285993 r286560 47 47 #include <wtf/LoggerHelper.h> 48 48 #include <wtf/Observer.h> 49 #include <wtf/WallTime.h> 49 50 #include <wtf/WeakPtr.h> 50 51 … … 243 244 double currentTimeForBindings() const { return currentTime(); } 244 245 WEBCORE_EXPORT ExceptionOr<void> setCurrentTimeForBindings(double); 245 WEBCORE_EXPORT double getStartDate() const;246 WEBCORE_EXPORT WallTime getStartDate() const; 246 247 WEBCORE_EXPORT double duration() const override; 247 248 WEBCORE_EXPORT bool paused() const override; -
trunk/Source/WebCore/html/InputType.cpp
r286447 r286560 205 205 } 206 206 207 double InputType::valueAsDate() const208 { 209 return DateComponents::invalidMilliseconds();210 } 211 212 ExceptionOr<void> InputType::setValueAsDate( double) const207 WallTime InputType::valueAsDate() const 208 { 209 return WallTime::nan(); 210 } 211 212 ExceptionOr<void> InputType::setValueAsDate(WallTime) const 213 213 { 214 214 return Exception { InvalidStateError }; -
trunk/Source/WebCore/html/InputType.h
r286447 r286560 221 221 virtual String fallbackValue() const; // Checked last, if both internal storage and value attribute are missing. 222 222 virtual String defaultValue() const; // Checked after even fallbackValue, only when the valueWithDefault function is called. 223 virtual double valueAsDate() const;224 virtual ExceptionOr<void> setValueAsDate( double) const;223 virtual WallTime valueAsDate() const; 224 virtual ExceptionOr<void> setValueAsDate(WallTime) const; 225 225 virtual double valueAsDouble() const; 226 226 virtual ExceptionOr<void> setValueAsDouble(double, TextFieldEventBehavior) const; -
trunk/Source/WebCore/html/MonthInputType.cpp
r283851 r286560 65 65 } 66 66 67 double MonthInputType::valueAsDate() const67 WallTime MonthInputType::valueAsDate() const 68 68 { 69 69 ASSERT(element()); 70 70 auto date = parseToDateComponents(element()->value()); 71 71 if (!date) 72 return DateComponents::invalidMilliseconds();72 return WallTime::nan(); 73 73 double msec = date->millisecondsSinceEpoch(); 74 74 ASSERT(std::isfinite(msec)); 75 return msec;75 return WallTime::fromRawSeconds(Seconds::fromMilliseconds(msec).value()); 76 76 } 77 77 -
trunk/Source/WebCore/html/MonthInputType.h
r282242 r286560 48 48 const AtomString& formControlType() const override; 49 49 DateComponentsType dateType() const override; 50 double valueAsDate() const override;50 WallTime valueAsDate() const override; 51 51 String serializeWithMilliseconds(double) const override; 52 52 Decimal parseToNumber(const String&, const Decimal&) const override; -
trunk/Source/WebKitLegacy/mac/ChangeLog
r286459 r286560 1 2021-12-06 Devin Rousso <drousso@apple.com> 2 3 Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates 4 https://bugs.webkit.org/show_bug.cgi?id=233781 5 6 Reviewed by Darin Adler. 7 8 JS `Date` is milliseconds-based, but some native dates (e.g. `NSDate`) are seconds-based. 9 `WallTime` will help avoid confusion since not a generic type (e.g. `double`) and instead 10 has explicitly defined conversion methods to seconds, milliseconds, etc.. 11 12 * DOM/DOMInternal.h: 13 (kit): 14 (core): 15 16 * DOM/DOMHTMLMediaElement.mm: 17 (-[DOMHTMLMediaElement getStartDate]): 18 1 19 2021-12-02 Myles C. Maxfield <mmaxfield@apple.com> 2 20 -
trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLMediaElement.mm
r260709 r286560 29 29 #import "DOMHTMLMediaElement.h" 30 30 31 #import "DOMInternal.h" 31 32 #import "DOMMediaErrorInternal.h" 32 33 #import "DOMNodeInternal.h" … … 314 315 { 315 316 WebCore::JSMainThreadNullState state; 316 return IMPL->getStartDate();317 return kit(IMPL->getStartDate()); 317 318 } 318 319 -
trunk/Source/WebKitLegacy/mac/DOM/DOMInternal.h
r204717 r286560 30 30 #import "DOMXPathNSResolver.h" 31 31 #import <wtf/Forward.h> 32 #import <wtf/WallTime.h> 32 33 33 34 namespace JSC { … … 78 79 WebCore::XPathNSResolver* core(DOMNativeXPathNSResolver *); 79 80 80 inline NSTimeInterval kit( double msSinceEpoch)81 inline NSTimeInterval kit(WallTime time) 81 82 { 82 return msSinceEpoch / 1000.0- NSTimeIntervalSince1970;83 return time.secondsSinceEpoch().value() - NSTimeIntervalSince1970; 83 84 } 84 85 85 inline double core(NSTimeInterval sec)86 inline WallTime core(NSTimeInterval sec) 86 87 { 87 return sec * 1000.0 + NSTimeIntervalSince1970;88 return WallTime::fromRawSeconds(sec + NSTimeIntervalSince1970); 88 89 }
Note:
See TracChangeset
for help on using the changeset viewer.