Title: [210946] trunk
Revision
210946
Author
[email protected]
Date
2017-01-19 17:35:58 -0800 (Thu, 19 Jan 2017)

Log Message

Construct URLSearchParams from array or object
https://bugs.webkit.org/show_bug.cgi?id=166973

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/url/urlsearchparams-constructor-expected.txt:

Source/WebCore:

Covered by newly passing web platform tests.

* html/URLSearchParams.cpp:
(WebCore::URLSearchParams::URLSearchParams):
(WebCore::URLSearchParams::create):
(WebCore::URLSearchParams::get):
(WebCore::URLSearchParams::has):
(WebCore::URLSearchParams::sort):
(WebCore::URLSearchParams::set):
(WebCore::URLSearchParams::getAll):
(WebCore::URLSearchParams::remove):
(WebCore::URLSearchParams::Iterator::next):
* html/URLSearchParams.h:
(WebCore::URLSearchParams::create):
(WebCore::URLSearchParams::pairs):
(WebCore::URLSearchParams::operator const Vector<std::pair<String, String>>&): Deleted.
* html/URLSearchParams.idl:
* platform/URLParser.cpp:
(WebCore::URLParser::serialize):
* platform/URLParser.h:

Source/WebKit2:

* NetworkProcess/capture/NetworkCaptureManager.cpp:
(WebKit::NetworkCapture::Manager::fuzzyMatchURLs):
Change std::pair's first/second to WTF::KeyValuePair's key/value.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (210945 => 210946)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-01-20 01:35:58 UTC (rev 210946)
@@ -1,3 +1,12 @@
+2017-01-19  Alex Christensen  <[email protected]>
+
+        Construct URLSearchParams from array or object
+        https://bugs.webkit.org/show_bug.cgi?id=166973
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/url/urlsearchparams-constructor-expected.txt:
+
 2017-01-18  Alex Christensen  <[email protected]>
 
         Implement URLSearchParams's sort()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-constructor-expected.txt (210945 => 210946)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-constructor-expected.txt	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-constructor-expected.txt	2017-01-20 01:35:58 UTC (rev 210946)
@@ -1,9 +1,9 @@
 
 PASS Basic URLSearchParams construction 
 PASS URLSearchParams constructor, no arguments 
-FAIL URLSearchParams constructor, DOMException.prototype as argument Can only call DOMException.toString on instances of DOMException
+FAIL URLSearchParams constructor, DOMException.prototype as argument assert_equals: expected "Error=" but got "INDEX_SIZE_ERR=1&DOMSTRING_SIZE_ERR=2&HIERARCHY_REQUEST_ERR=3&WRONG_DOCUMENT_ERR=4&INVALID_CHARACTER_ERR=5&NO_DATA_ALLOWED_ERR=6&NO_MODIFICATION_ALLOWED_ERR=7&NOT_FOUND_ERR=8&NOT_SUPPORTED_ERR=9&INUSE_ATTRIBUTE_ERR=10&INVALID_STATE_ERR=11&SYNTAX_ERR=12&INVALID_MODIFICATION_ERR=13&NAMESPACE_ERR=14&INVALID_ACCESS_ERR=15&VALIDATION_ERR=16&TYPE_MISMATCH_ERR=17&SECURITY_ERR=18&NETWORK_ERR=19&ABORT_ERR=20&URL_MISMATCH_ERR=21&QUOTA_EXCEEDED_ERR=22&TIMEOUT_ERR=23&INVALID_NODE_TYPE_ERR=24&DATA_CLONE_ERR=25"
 PASS URLSearchParams constructor, empty string as argument 
-FAIL URLSearchParams constructor, {} as argument assert_equals: expected "" but got "%5Bobject+Object%5D="
+PASS URLSearchParams constructor, {} as argument 
 PASS URLSearchParams constructor, string. 
 PASS URLSearchParams constructor, object. 
 PASS Parse + 
@@ -15,8 +15,8 @@
 PASS Parse %e2%8e%84 
 PASS Parse 💩 
 PASS Parse %f0%9f%92%a9 
-FAIL Construct with object with + assert_array_equals: property 0, expected " " but got "[object Object]"
-FAIL Construct with object with two keys assert_array_equals: property 0, expected "c" but got "[object Object]"
-FAIL Construct with array with two keys assert_array_equals: property 0, expected "c" but got "c,x,a,?"
-FAIL Custom [Symbol.iterator] assert_equals: expected (string) "b" but got (object) null
+FAIL Construct with object with + assert_array_equals: property 0, expected " " but got "+"
+PASS Construct with object with two keys 
+PASS Construct with array with two keys 
+PASS Custom [Symbol.iterator] 
 

Modified: trunk/Source/WebCore/ChangeLog (210945 => 210946)


--- trunk/Source/WebCore/ChangeLog	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/ChangeLog	2017-01-20 01:35:58 UTC (rev 210946)
@@ -1,3 +1,31 @@
+2017-01-19  Alex Christensen  <[email protected]>
+
+        Construct URLSearchParams from array or object
+        https://bugs.webkit.org/show_bug.cgi?id=166973
+
+        Reviewed by Sam Weinig.
+
+        Covered by newly passing web platform tests.
+
+        * html/URLSearchParams.cpp:
+        (WebCore::URLSearchParams::URLSearchParams):
+        (WebCore::URLSearchParams::create):
+        (WebCore::URLSearchParams::get):
+        (WebCore::URLSearchParams::has):
+        (WebCore::URLSearchParams::sort):
+        (WebCore::URLSearchParams::set):
+        (WebCore::URLSearchParams::getAll):
+        (WebCore::URLSearchParams::remove):
+        (WebCore::URLSearchParams::Iterator::next):
+        * html/URLSearchParams.h:
+        (WebCore::URLSearchParams::create):
+        (WebCore::URLSearchParams::pairs):
+        (WebCore::URLSearchParams::operator const Vector<std::pair<String, String>>&): Deleted.
+        * html/URLSearchParams.idl:
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::serialize):
+        * platform/URLParser.h:
+
 2017-01-19  Jer Noble  <[email protected]>
 
         CRASH at WebCore::TrackListBase::remove

Modified: trunk/Source/WebCore/html/URLSearchParams.cpp (210945 => 210946)


--- trunk/Source/WebCore/html/URLSearchParams.cpp	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/html/URLSearchParams.cpp	2017-01-20 01:35:58 UTC (rev 210946)
@@ -26,6 +26,7 @@
 #include "URLSearchParams.h"
 
 #include "DOMURL.h"
+#include "ExceptionCode.h"
 #include "URLParser.h"
 
 namespace WebCore {
@@ -36,16 +37,34 @@
 {
 }
 
-URLSearchParams::URLSearchParams(const Vector<std::pair<String, String>>& pairs)
+URLSearchParams::URLSearchParams(const Vector<WTF::KeyValuePair<String, String>>& pairs)
     : m_pairs(pairs)
 {
 }
 
+ExceptionOr<Ref<URLSearchParams>> URLSearchParams::create(Variant<Vector<Vector<String>>, Vector<WTF::KeyValuePair<String, String>>, String>&& variant)
+{
+    auto visitor = WTF::makeVisitor([&](const Vector<Vector<String>>& vector) -> ExceptionOr<Ref<URLSearchParams>> {
+        Vector<WTF::KeyValuePair<String, String>> pairs;
+        for (const auto& pair : vector) {
+            if (pair.size() != 2)
+                return Exception { TypeError };
+            pairs.append({pair[0], pair[1]});
+        }
+        return adoptRef(*new URLSearchParams(WTFMove(pairs)));
+    }, [&](const Vector<WTF::KeyValuePair<String, String>>& pairs) {
+        return adoptRef(*new URLSearchParams(pairs));
+    }, [&](const String& string) {
+        return adoptRef(*new URLSearchParams(string, nullptr));
+    });
+    return WTF::visit(visitor, variant);
+}
+
 String URLSearchParams::get(const String& name) const
 {
     for (const auto& pair : m_pairs) {
-        if (pair.first == name)
-            return pair.second;
+        if (pair.key == name)
+            return pair.value;
     }
     return String();
 }
@@ -53,7 +72,7 @@
 bool URLSearchParams::has(const String& name) const
 {
     for (const auto& pair : m_pairs) {
-        if (pair.first == name)
+        if (pair.key == name)
             return true;
     }
     return false;
@@ -61,8 +80,8 @@
 
 void URLSearchParams::sort()
 {
-    std::stable_sort(m_pairs.begin(), m_pairs.end(), [] (const std::pair<String, String>& a, const std::pair<String, String>& b) {
-        return WTF::codePointCompareLessThan(a.first, b.first);
+    std::stable_sort(m_pairs.begin(), m_pairs.end(), [] (const auto& a, const auto& b) {
+        return WTF::codePointCompareLessThan(a.key, b.key);
     });
     updateURL();
 }
@@ -70,14 +89,13 @@
 void URLSearchParams::set(const String& name, const String& value)
 {
     for (auto& pair : m_pairs) {
-        if (pair.first != name)
+        if (pair.key != name)
             continue;
-        if (pair.second != value)
-            pair.second = value;
+        if (pair.value != value)
+            pair.value = value;
         bool skippedFirstMatch = false;
         m_pairs.removeAllMatching([&] (const auto& pair) {
-            bool nameMatches = pair.first == name;
-            if (nameMatches) {
+            if (pair.key == name) {
                 if (skippedFirstMatch)
                     return true;
                 skippedFirstMatch = true;
@@ -102,8 +120,8 @@
     Vector<String> values;
     values.reserveInitialCapacity(m_pairs.size());
     for (const auto& pair : m_pairs) {
-        if (pair.first == name)
-            values.uncheckedAppend(pair.second);
+        if (pair.key == name)
+            values.uncheckedAppend(pair.value);
     }
     return values;
 }
@@ -110,7 +128,7 @@
 
 void URLSearchParams::remove(const String& name)
 {
-    if (m_pairs.removeAllMatching([&] (const auto& pair) { return pair.first == name; }))
+    if (m_pairs.removeAllMatching([&] (const auto& pair) { return pair.key == name; }))
         updateURL();
 }
 
@@ -139,7 +157,7 @@
         return std::nullopt;
 
     auto& pair = pairs[m_index++];
-    return WTF::KeyValuePair<String, String> { pair.first, pair.second };
+    return WTF::KeyValuePair<String, String> { pair.key, pair.value };
 }
 
 URLSearchParams::Iterator::Iterator(URLSearchParams& params)

Modified: trunk/Source/WebCore/html/URLSearchParams.h (210945 => 210946)


--- trunk/Source/WebCore/html/URLSearchParams.h	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/html/URLSearchParams.h	2017-01-20 01:35:58 UTC (rev 210946)
@@ -33,8 +33,11 @@
 
 class URLSearchParams : public RefCounted<URLSearchParams> {
 public:
-    using StringOrURLSearchParams = WTF::Variant<String, RefPtr<URLSearchParams>>;
-    static Ref<URLSearchParams> create(const StringOrURLSearchParams&, DOMURL* associatedURL = nullptr);
+    static ExceptionOr<Ref<URLSearchParams>> create(Variant<Vector<Vector<String>>, Vector<WTF::KeyValuePair<String, String>>, String>&&);
+    static Ref<URLSearchParams> create(const String& string, DOMURL* associatedURL)
+    {
+        return adoptRef(*new URLSearchParams(string, associatedURL));
+    }
 
     void associatedURLDestroyed() { m_associatedURL = nullptr; }
     void append(const String& name, const String& value);
@@ -44,8 +47,6 @@
     bool has(const String& name) const;
     void set(const String& name, const String& value);
     String toString() const;
-    const Vector<std::pair<String, String>>& pairs() const { return m_pairs; }
-    operator const Vector<std::pair<String, String>>&() { return m_pairs; }
     void updateFromAssociatedURL();
     void sort();
 
@@ -61,22 +62,13 @@
     Iterator createIterator() { return Iterator { *this }; }
 
 private:
+    const Vector<WTF::KeyValuePair<String, String>>& pairs() const { return m_pairs; }
     URLSearchParams(const String&, DOMURL*);
-    explicit URLSearchParams(const Vector<std::pair<String, String>>&);
+    URLSearchParams(const Vector<WTF::KeyValuePair<String, String>>&);
     void updateURL();
 
     DOMURL* m_associatedURL { nullptr };
-    Vector<std::pair<String, String>> m_pairs;
+    Vector<WTF::KeyValuePair<String, String>> m_pairs;
 };
 
-inline Ref<URLSearchParams> URLSearchParams::create(const StringOrURLSearchParams& variant, DOMURL* associatedURL)
-{
-    auto visitor = WTF::makeVisitor([&](const String& string) {
-        return adoptRef(*new URLSearchParams(string, associatedURL));
-    }, [&](const RefPtr<URLSearchParams>& params) {
-        return adoptRef(*new URLSearchParams(static_cast<const Vector<std::pair<String, String>>&>(*params)));
-    });
-    return WTF::visit(visitor, variant);
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/URLSearchParams.idl (210945 => 210946)


--- trunk/Source/WebCore/html/URLSearchParams.idl	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/html/URLSearchParams.idl	2017-01-20 01:35:58 UTC (rev 210946)
@@ -24,7 +24,8 @@
  */
 
 [
-    Constructor(optional (USVString or URLSearchParams) init = ""),
+    Constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = ""),
+    ConstructorMayThrowException,
     Exposed=(Window,Worker),
     ImplementationLacksVTable,
 ] interface URLSearchParams {

Modified: trunk/Source/WebCore/platform/URLParser.cpp (210945 => 210946)


--- trunk/Source/WebCore/platform/URLParser.cpp	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2017-01-20 01:35:58 UTC (rev 210946)
@@ -2717,7 +2717,7 @@
             auto name = formURLDecode(bytes.substring(0, valueStart));
             auto value = formURLDecode(bytes.substring(valueStart + 1));
             if (name && value)
-                output.append(std::make_pair(name.value().replace('+', 0x20), value.value().replace('+', 0x20)));
+                output.append({name.value().replace('+', 0x20), value.value().replace('+', 0x20)});
         }
     }
     return output;
@@ -2750,9 +2750,9 @@
     for (auto& tuple : tuples) {
         if (!output.isEmpty())
             output.append('&');
-        serializeURLEncodedForm(tuple.first, output);
+        serializeURLEncodedForm(tuple.key, output);
         output.append('=');
-        serializeURLEncodedForm(tuple.second, output);
+        serializeURLEncodedForm(tuple.value, output);
     }
     return String::adopt(WTFMove(output));
 }

Modified: trunk/Source/WebCore/platform/URLParser.h (210945 => 210946)


--- trunk/Source/WebCore/platform/URLParser.h	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebCore/platform/URLParser.h	2017-01-20 01:35:58 UTC (rev 210946)
@@ -46,7 +46,7 @@
     WEBCORE_EXPORT static bool enabled();
     WEBCORE_EXPORT static void setEnabled(bool);
     
-    typedef Vector<std::pair<String, String>> URLEncodedForm;
+    typedef Vector<WTF::KeyValuePair<String, String>> URLEncodedForm;
     WEBCORE_EXPORT static URLEncodedForm parseURLEncodedForm(StringView);
     static String serialize(const URLEncodedForm&);
 

Modified: trunk/Source/WebKit2/ChangeLog (210945 => 210946)


--- trunk/Source/WebKit2/ChangeLog	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-20 01:35:58 UTC (rev 210946)
@@ -1,3 +1,14 @@
+2017-01-19  Alex Christensen  <[email protected]>
+
+        Construct URLSearchParams from array or object
+        https://bugs.webkit.org/show_bug.cgi?id=166973
+
+        Reviewed by Sam Weinig.
+
+        * NetworkProcess/capture/NetworkCaptureManager.cpp:
+        (WebKit::NetworkCapture::Manager::fuzzyMatchURLs):
+        Change std::pair's first/second to WTF::KeyValuePair's key/value.
+
 2017-01-19  Andy Estes  <[email protected]>
 
         [iOS] Move the PDF password view into its own class for possible reuse

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp (210945 => 210946)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp	2017-01-20 01:09:20 UTC (rev 210945)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp	2017-01-20 01:35:58 UTC (rev 210946)
@@ -286,14 +286,14 @@
     auto resourceParameter = std::begin(resourceParameters);
 
     for (; requestParameter != std::end(requestParameters) && resourceParameter != std::end(resourceParameters); ++requestParameter, ++resourceParameter) {
-        if (requestParameter->first == resourceParameter->first) {
+        if (requestParameter->key == resourceParameter->key) {
 #if ENABLE(WTF_CAPTURE_INTERNAL_DEBUGGING)
-            if (requestParameter->second == resourceParameter->second)
+            if (requestParameter->value == resourceParameter->value)
                 DEBUG_LOG("Matching parameter names and values: \"" STRING_SPECIFIER "\" = \"" STRING_SPECIFIER "\"", DEBUG_STR(requestParameter->first), DEBUG_STR(requestParameter->second));
             else
                 DEBUG_LOG("Mismatching parameter values: \"" STRING_SPECIFIER "\" = \"" STRING_SPECIFIER "\" vs. \"" STRING_SPECIFIER "\"", DEBUG_STR(requestParameter->first), DEBUG_STR(requestParameter->second), DEBUG_STR(resourceParameter->second));
 #endif
-            score += (requestParameter->second == resourceParameter->second) ? kParameterMatchScore : kParameterMismatchScore;
+            score += (requestParameter->value == resourceParameter->value) ? kParameterMatchScore : kParameterMismatchScore;
             DEBUG_LOG("Score = %d", score);
         } else {
             DEBUG_LOG("Mismatching parameter names: " STRING_SPECIFIER ", " STRING_SPECIFIER, DEBUG_STR(requestParameter->first), DEBUG_STR(resourceParameter->first));
@@ -300,7 +300,7 @@
 
             const auto scanForwardForMatch = [this, &score, kParameterMatchScore, kParameterMismatchScore, kParameterMissingScore](const auto& fixedIter, auto& scanningIter, const auto& scannerEnd) {
                 auto scanner = scanningIter;
-                while (scanner != scannerEnd && scanner->first != fixedIter->first)
+                while (scanner != scannerEnd && scanner->key != fixedIter->key)
                     ++scanner;
                 if (scanner == scannerEnd)
                     return false;
@@ -313,7 +313,7 @@
                 else
                     DEBUG_LOG("Mismatching parameter values: \"" STRING_SPECIFIER "\" = \"" STRING_SPECIFIER "\" vs. \"" STRING_SPECIFIER "\"", DEBUG_STR(fixedIter->first), DEBUG_STR(fixedIter->second), DEBUG_STR(scanner->second));
 #endif
-                score += (fixedIter->second == scanner->second) ? kParameterMatchScore : kParameterMismatchScore;
+                score += (fixedIter->value == scanner->value) ? kParameterMatchScore : kParameterMismatchScore;
                 DEBUG_LOG("Score = %d", score);
                 scanningIter = scanner;
                 return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to