Bug 1331580 - Construct URLSearchParams from record<>, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 02 Mar 2017 21:48:51 +0100
changeset 394715 ee9c3cd7d55f2a00d416dee71ca3938926850739
parent 394714 f24dc887296771ed1d36f96caaed0e326c6f3d25
child 394716 77bb2c4461a3f8a6ea3dbb773ad4b2c343054d55
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1331580
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1331580 - Construct URLSearchParams from record<>, r=qdot
dom/url/URLSearchParams.cpp
dom/url/URLSearchParams.h
dom/webidl/URLSearchParams.webidl
testing/web-platform/meta/url/urlsearchparams-constructor.html.ini
--- a/dom/url/URLSearchParams.cpp
+++ b/dom/url/URLSearchParams.cpp
@@ -322,17 +322,17 @@ URLSearchParams::~URLSearchParams()
 JSObject*
 URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return URLSearchParamsBinding::Wrap(aCx, this, aGivenProto);
 }
 
 /* static */ already_AddRefed<URLSearchParams>
 URLSearchParams::Constructor(const GlobalObject& aGlobal,
-                             const USVStringSequenceSequenceOrUSVString& aInit,
+                             const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& aInit,
                              ErrorResult& aRv)
 {
   RefPtr<URLSearchParams> sp =
     new URLSearchParams(aGlobal.GetAsSupports(), nullptr);
 
   if (aInit.IsUSVString()) {
     NS_ConvertUTF16toUTF8 input(aInit.GetAsUSVString());
     if (StringBeginsWith(input, NS_LITERAL_CSTRING("?"))) {
@@ -346,16 +346,22 @@ URLSearchParams::Constructor(const Globa
     for (uint32_t i = 0; i < list.Length(); ++i) {
       const Sequence<nsString>& item = list[i];
       if (item.Length() != 2) {
         aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
         return nullptr;
       }
       sp->Append(item[0], item[1]);
     }
+  } else if (aInit.IsUSVStringUSVStringRecord()) {
+    const Record<nsString, nsString>& record =
+      aInit.GetAsUSVStringUSVStringRecord();
+    for (auto& entry : record.Entries()) {
+      sp->Append(entry.mKey, entry.mValue);
+    }
   } else {
     MOZ_CRASH("This should not happen.");
   }
 
   return sp.forget();
 }
 
 void
--- a/dom/url/URLSearchParams.h
+++ b/dom/url/URLSearchParams.h
@@ -15,17 +15,17 @@
 #include "nsISupports.h"
 #include "nsIUnicodeDecoder.h"
 #include "nsIXMLHttpRequest.h"
 
 namespace mozilla {
 namespace dom {
 
 class URLSearchParams;
-class USVStringSequenceSequenceOrUSVString;
+class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString;
 
 class URLSearchParamsObserver : public nsISupports
 {
 public:
   virtual ~URLSearchParamsObserver() {}
 
   virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0;
 };
@@ -145,17 +145,17 @@ public:
     return mParent;
   }
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   static already_AddRefed<URLSearchParams>
   Constructor(const GlobalObject& aGlobal,
-              const USVStringSequenceSequenceOrUSVString& aInit,
+              const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& aInit,
               ErrorResult& aRv);
 
   void ParseInput(const nsACString& aInput);
 
   void Serialize(nsAString& aValue) const;
 
   void Get(const nsAString& aName, nsString& aRetval);
 
--- a/dom/webidl/URLSearchParams.webidl
+++ b/dom/webidl/URLSearchParams.webidl
@@ -8,17 +8,17 @@
  *
  * To the extent possible under law, the editors have waived all copyright
  * and related or neighboring rights to this work. In addition, as of 17
  * February 2013, the editors have made this specification available under
  * the Open Web Foundation Agreement Version 1.0, which is available at
  * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
  */
 
-[Constructor(optional (sequence<sequence<USVString>> or USVString) init = ""),
+[Constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = ""),
  Exposed=(Window,Worker,WorkerDebugger,System)]
 interface URLSearchParams {
   void append(USVString name, USVString value);
   void delete(USVString name);
   USVString? get(USVString name);
   sequence<USVString> getAll(USVString name);
   boolean has(USVString name);
   void set(USVString name, USVString value);
--- a/testing/web-platform/meta/url/urlsearchparams-constructor.html.ini
+++ b/testing/web-platform/meta/url/urlsearchparams-constructor.html.ini
@@ -1,17 +1,5 @@
 [urlsearchparams-constructor.html]
   type: testharness
-  [URLSearchParams constructor, empty.]
-    expected: FAIL
-
   [URLSearchParams constructor, DOMException.prototype as argument]
     expected: FAIL
 
-  [URLSearchParams constructor, {} as argument]
-    expected: FAIL
-
-  [Construct with object with +]
-    expected: FAIL
-
-  [Construct with object with two keys]
-    expected: FAIL
-