Bug 959684 - Implement URLSearchParams stringifier. r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 15 Jan 2014 09:50:18 -0500
changeset 163593 bbc8cfceed0767238ff0279297150b3f0789aa40
parent 163592 b5fd65e0f0d68d33706b5b1a0a043c57063e7637
child 163594 81e542a2ab7099e28d1971c137184f51c769c3c9
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs959684
milestone29.0a1
Bug 959684 - Implement URLSearchParams stringifier. r=ehsan
dom/base/URLSearchParams.cpp
dom/base/URLSearchParams.h
dom/base/test/test_urlSearchParams.html
dom/webidl/URLSearchParams.webidl
dom/workers/test/urlSearchParams_worker.js
toolkit/components/places/tests/cpp/mock_Link.h
--- a/dom/base/URLSearchParams.cpp
+++ b/dom/base/URLSearchParams.cpp
@@ -343,17 +343,17 @@ public:
       }
 
       ++p;
     }
   }
 };
 
 void
-URLSearchParams::Serialize(nsAString& aValue)
+URLSearchParams::Serialize(nsAString& aValue) const
 {
   MOZ_ASSERT(mValid);
 
   SerializeData data;
   mSearchParams.EnumerateRead(SerializeEnumerator, &data);
   aValue.Assign(data.mValue);
 }
 
--- a/dom/base/URLSearchParams.h
+++ b/dom/base/URLSearchParams.h
@@ -66,32 +66,38 @@ public:
 
   void Invalidate();
 
   bool IsValid() const
   {
     return mValid;
   }
 
-  void Serialize(nsAString& aValue);
+  void Serialize(nsAString& aValue) const;
 
   void Get(const nsAString& aName, nsString& aRetval);
 
   void GetAll(const nsAString& aName, nsTArray<nsString >& aRetval);
 
   void Set(const nsAString& aName, const nsAString& aValue);
 
   void Append(const nsAString& aName, const nsAString& aValue);
 
   bool Has(const nsAString& aName);
 
   void Delete(const nsAString& aName);
 
   uint32_t Size();
 
+  void Stringify(nsString& aRetval)
+  {
+    Validate();
+    Serialize(aRetval);
+  }
+
 private:
   void AppendInternal(const nsAString& aName, const nsAString& aValue);
 
   void DeleteAll();
 
   void DecodeString(const nsACString& aInput, nsACString& aOutput);
 
   void NotifyObserver();
--- a/dom/base/test/test_urlSearchParams.html
+++ b/dom/base/test/test_urlSearchParams.html
@@ -40,16 +40,18 @@ https://bugzilla.mozilla.org/show_bug.cg
     is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
     is(u.size, 1, 'URLSearchParams.size()');
 
     u.set('foo', 'bar2');
     is(u.get('foo'), 'bar2', 'URLSearchParams.get(foo)');
     is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
     is(u.size, 1, 'URLSearchParams.size()');
 
+    is(u + "", "foo=bar2", "stringifier");
+
     u.delete('foo');
     is(u.size, 0, 'URLSearchParams.size()');
 
     runTest();
   }
 
   function testCopyURLSearchParams() {
     var u = new URLSearchParams();
--- a/dom/webidl/URLSearchParams.webidl
+++ b/dom/webidl/URLSearchParams.webidl
@@ -11,16 +11,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 DOMString init = ""),
  Constructor(URLSearchParams init)]
 interface URLSearchParams {
+  void append(DOMString name, DOMString value);
+  void delete(DOMString name);
   DOMString? get(DOMString name);
   sequence<DOMString> getAll(DOMString name);
+  boolean has(DOMString name);
   void set(DOMString name, DOMString value);
-  void append(DOMString name, DOMString value);
-  boolean has(DOMString name);
-  void delete(DOMString name);
   readonly attribute unsigned long size;
+  stringifier;
 };
--- a/dom/workers/test/urlSearchParams_worker.js
+++ b/dom/workers/test/urlSearchParams_worker.js
@@ -37,16 +37,18 @@ onmessage = function() {
     is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
     is(u.size, 1, 'URLSearchParams.size()');
 
     u.set('foo', 'bar2');
     is(u.get('foo'), 'bar2', 'URLSearchParams.get(foo)');
     is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
     is(u.size, 1, 'URLSearchParams.size()');
 
+    is(u + "", "foo=bar2", "stringify");
+
     u.delete('foo');
     is(u.size, 0, 'URLSearchParams.size()');
 
     runTest();
   }
 
   function testCopyURLSearchParams() {
     var u = new URLSearchParams();
--- a/toolkit/components/places/tests/cpp/mock_Link.h
+++ b/toolkit/components/places/tests/cpp/mock_Link.h
@@ -172,17 +172,17 @@ URLSearchParams::CopyFromURLSearchParams
 
 void
 URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
 {
   NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
 }
 
 void
-URLSearchParams::Serialize(nsAString& aValue)
+URLSearchParams::Serialize(nsAString& aValue) const
 {
   NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize");
 }
 
 void
 URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
 {
   NS_NOTREACHED("Unexpected call to URLSearchParams::Get");