- Revision
- 273767
- Author
- [email protected]
- Date
- 2021-03-02 15:47:36 -0800 (Tue, 02 Mar 2021)
Log Message
Allow IDL `Date` to be parsed from a string in addition to a number and actual JS `Date`
https://bugs.webkit.org/show_bug.cgi?id=222605
<rdar://problem/74502335>
Reviewed by Yusuke Suzuki.
JS `Date` can be stringified into JSON, but cannot be parsed back into a JS `Date` without
additional logic since the stringified value is indistinguishable from a regular string.
Source/_javascript_Core:
* runtime/JSDateMath.h:
Export `DateCache::parseDate` so it can be used in WebCore bindings code.
Source/WebCore:
* bindings/js/JSDOMConvertDate.h:
(WebCore::Converter<IDLDate>::convert):
Pass the `JSGlobalObject` instead of the `VM`.
* bindings/js/JSDOMConvertDate.cpp:
(WebCore::valueToDate):
Check if `value.isString()` and if so use `DateCache::parseDate` (same as JS `Date.parse`).
* bindings/js/IDBBindingUtilities.cpp:
(WebCore::createIDBKeyFromValue):
Pass the `JSGlobalObject` instead of the `VM`. Should have no behavioral change since the
`valueToDate` call is already guarded by a `value.inherits<DateInstance>(vm)` check.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (273766 => 273767)
--- trunk/Source/_javascript_Core/ChangeLog 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-03-02 23:47:36 UTC (rev 273767)
@@ -1,3 +1,17 @@
+2021-03-02 Devin Rousso <[email protected]>
+
+ Allow IDL `Date` to be parsed from a string in addition to a number and actual JS `Date`
+ https://bugs.webkit.org/show_bug.cgi?id=222605
+ <rdar://problem/74502335>
+
+ Reviewed by Yusuke Suzuki.
+
+ JS `Date` can be stringified into JSON, but cannot be parsed back into a JS `Date` without
+ additional logic since the stringified value is indistinguishable from a regular string.
+
+ * runtime/JSDateMath.h:
+ Export `DateCache::parseDate` so it can be used in WebCore bindings code.
+
2021-03-02 Yusuke Suzuki <[email protected]>
[JSC] Optimize getEnumerableLength
Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.h (273766 => 273767)
--- trunk/Source/_javascript_Core/runtime/JSDateMath.h 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.h 2021-03-02 23:47:36 UTC (rev 273767)
@@ -83,7 +83,7 @@
void msToGregorianDateTime(double millisecondsFromEpoch, WTF::TimeType outputTimeType, GregorianDateTime&);
double gregorianDateTimeToMS(const GregorianDateTime&, double milliseconds, WTF::TimeType inputTimeType);
- double parseDate(JSGlobalObject*, VM&, const WTF::String&);
+ JS_EXPORT_PRIVATE double parseDate(JSGlobalObject*, VM&, const WTF::String&);
private:
void timeZoneCacheSlow();
Modified: trunk/Source/WebCore/ChangeLog (273766 => 273767)
--- trunk/Source/WebCore/ChangeLog 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/WebCore/ChangeLog 2021-03-02 23:47:36 UTC (rev 273767)
@@ -1,3 +1,27 @@
+2021-03-02 Devin Rousso <[email protected]>
+
+ Allow IDL `Date` to be parsed from a string in addition to a number and actual JS `Date`
+ https://bugs.webkit.org/show_bug.cgi?id=222605
+ <rdar://problem/74502335>
+
+ Reviewed by Yusuke Suzuki.
+
+ JS `Date` can be stringified into JSON, but cannot be parsed back into a JS `Date` without
+ additional logic since the stringified value is indistinguishable from a regular string.
+
+ * bindings/js/JSDOMConvertDate.h:
+ (WebCore::Converter<IDLDate>::convert):
+ Pass the `JSGlobalObject` instead of the `VM`.
+
+ * bindings/js/JSDOMConvertDate.cpp:
+ (WebCore::valueToDate):
+ Check if `value.isString()` and if so use `DateCache::parseDate` (same as JS `Date.parse`).
+
+ * bindings/js/IDBBindingUtilities.cpp:
+ (WebCore::createIDBKeyFromValue):
+ Pass the `JSGlobalObject` instead of the `VM`. Should have no behavioral change since the
+ `valueToDate` call is already guarded by a `value.inherits<DateInstance>(vm)` check.
+
2021-03-02 Said Abou-Hallawa <[email protected]>
The layout of SVGImage should force the layout for its clients
Modified: trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp (273766 => 273767)
--- trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp 2021-03-02 23:47:36 UTC (rev 273767)
@@ -204,7 +204,8 @@
}
if (value.inherits<DateInstance>(vm)) {
- auto dateValue = valueToDate(vm, value);
+ auto dateValue = valueToDate(lexicalGlobalObject, value);
+ RETURN_IF_EXCEPTION(scope, { });
if (!std::isnan(dateValue))
return IDBKey::createDate(dateValue);
}
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp (273766 => 273767)
--- trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertDate.cpp 2021-03-02 23:47:36 UTC (rev 273767)
@@ -36,13 +36,16 @@
return DateInstance::create(lexicalGlobalObject.vm(), lexicalGlobalObject.dateStructure(), value);
}
-double valueToDate(VM& vm, JSValue value)
+double valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value)
{
+ auto& vm = lexicalGlobalObject.vm();
+ if (value.inherits<DateInstance>(vm))
+ return jsCast<DateInstance*>(value)->internalNumber();
if (value.isNumber())
return value.asNumber();
- if (!value.inherits<DateInstance>(vm))
- return std::numeric_limits<double>::quiet_NaN();
- return jsCast<DateInstance*>(value)->internalNumber();
+ if (value.isString())
+ return vm.dateCache.parseDate(&lexicalGlobalObject, vm, value.getString(&lexicalGlobalObject));
+ return std::numeric_limits<double>::quiet_NaN();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h (273766 => 273767)
--- trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h 2021-03-02 23:33:43 UTC (rev 273766)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertDate.h 2021-03-02 23:47:36 UTC (rev 273767)
@@ -32,12 +32,12 @@
namespace WebCore {
JSC::JSValue jsDate(JSC::JSGlobalObject&, double value);
-double valueToDate(JSC::VM&, JSC::JSValue); // NaN if the value can't be converted to a date.
+double 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)
{
- return valueToDate(lexicalGlobalObject.vm(), value);
+ return valueToDate(lexicalGlobalObject, value);
}
};