Bug 1350254 part 9. Switch URLSearchParams to [Serializable]. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 25 Jun 2019 06:48:53 +0000
changeset 543287 954a6de2b937021d511687a7d40d52910f82e3f4
parent 543286 e02c73e7bd4bed108e60527f81fb8af00e361bb6
child 543288 96e19ef1e1912213246913651e2686a6ebd55e54
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1350254
milestone69.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 1350254 part 9. Switch URLSearchParams to [Serializable]. r=baku Differential Revision: https://phabricator.services.mozilla.com/D35723
dom/base/StructuredCloneHolder.cpp
dom/url/URLSearchParams.cpp
dom/url/URLSearchParams.h
dom/webidl/URLSearchParams.webidl
--- a/dom/base/StructuredCloneHolder.cpp
+++ b/dom/base/StructuredCloneHolder.cpp
@@ -23,18 +23,16 @@
 #include "mozilla/dom/MessagePortBinding.h"
 #include "mozilla/dom/OffscreenCanvas.h"
 #include "mozilla/dom/OffscreenCanvasBinding.h"
 #include "mozilla/dom/PMessagePort.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/StructuredCloneTester.h"
 #include "mozilla/dom/StructuredCloneTesterBinding.h"
 #include "mozilla/dom/ToJSValue.h"
-#include "mozilla/dom/URLSearchParams.h"
-#include "mozilla/dom/URLSearchParamsBinding.h"
 #include "mozilla/dom/WebIDLSerializable.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "MultipartBlobImpl.h"
 #include "nsQueryObject.h"
 
@@ -343,32 +341,16 @@ JSObject* StructuredCloneHolder::ReadFul
   }
 
   WebIDLDeserializer deserializer =
       LookupDeserializer(StructuredCloneTags(aTag));
   if (deserializer) {
     return deserializer(aCx, global, aReader);
   }
 
-  if (aTag == SCTAG_DOM_URLSEARCHPARAMS) {
-    // Prevent the return value from being trashed by a GC during ~nsRefPtr.
-    JS::Rooted<JSObject*> result(aCx);
-    {
-      if (aTag == SCTAG_DOM_URLSEARCHPARAMS) {
-        RefPtr<URLSearchParams> usp = new URLSearchParams(global);
-        if (!usp->ReadStructuredClone(aReader)) {
-          result = nullptr;
-        } else {
-          result = usp->WrapObject(aCx, nullptr);
-        }
-      }
-    }
-    return result;
-  }
-
   if (aTag == SCTAG_DOM_NULL_PRINCIPAL || aTag == SCTAG_DOM_SYSTEM_PRINCIPAL ||
       aTag == SCTAG_DOM_CONTENT_PRINCIPAL ||
       aTag == SCTAG_DOM_EXPANDED_PRINCIPAL) {
     JSPrincipals* prin;
     if (!nsJSPrincipals::ReadKnownPrincipalType(aCx, aReader, aTag, &prin)) {
       return nullptr;
     }
     // nsJSPrincipals::ReadKnownPrincipalType addrefs for us, but because of the
@@ -435,25 +417,16 @@ bool StructuredCloneHolder::WriteFullySe
     return xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
   }
 
   const DOMJSClass* domClass = GetDOMClass(obj);
   if (domClass && domClass->mSerializer) {
     return domClass->mSerializer(aCx, aWriter, obj);
   }
 
-  // Handle URLSearchParams cloning
-  {
-    URLSearchParams* usp = nullptr;
-    if (NS_SUCCEEDED(UNWRAP_OBJECT(URLSearchParams, &obj, usp))) {
-      return JS_WriteUint32Pair(aWriter, SCTAG_DOM_URLSEARCHPARAMS, 0) &&
-             usp->WriteStructuredClone(aWriter);
-    }
-  }
-
 #ifdef MOZ_WEBRTC
   {
     // Handle WebRTC Certificate cloning
     RTCCertificate* cert = nullptr;
     if (NS_SUCCEEDED(UNWRAP_OBJECT(RTCCertificate, &obj, cert))) {
       MOZ_ASSERT(NS_IsMainThread());
       return JS_WriteUint32Pair(aWriter, SCTAG_DOM_RTC_CERTIFICATE, 0) &&
              cert->WriteStructuredClone(aWriter);
--- a/dom/url/URLSearchParams.cpp
+++ b/dom/url/URLSearchParams.cpp
@@ -484,22 +484,29 @@ bool URLParams::ReadStructuredClone(JSSt
       return false;
     }
     Append(key, value);
   }
   return true;
 }
 
 bool URLSearchParams::WriteStructuredClone(
-    JSStructuredCloneWriter* aWriter) const {
+    JSContext* aCx, JSStructuredCloneWriter* aWriter) const {
   return mParams->WriteStructuredClone(aWriter);
 }
 
-bool URLSearchParams::ReadStructuredClone(JSStructuredCloneReader* aReader) {
-  return mParams->ReadStructuredClone(aReader);
+// static
+already_AddRefed<URLSearchParams> URLSearchParams::ReadStructuredClone(
+    JSContext* aCx, nsIGlobalObject* aGlobal,
+    JSStructuredCloneReader* aReader) {
+  RefPtr<URLSearchParams> params = new URLSearchParams(aGlobal);
+  if (!params->mParams->ReadStructuredClone(aReader)) {
+    return nullptr;
+  }
+  return params.forget();
 }
 
 // contentTypeWithCharset can be set to the contentType or
 // contentType+charset based on what the spec says.
 // See: https://fetch.spec.whatwg.org/#concept-bodyinit-extract
 nsresult URLSearchParams::GetSendInfo(nsIInputStream** aBody,
                                       uint64_t* aContentLength,
                                       nsACString& aContentTypeWithCharset,
--- a/dom/url/URLSearchParams.h
+++ b/dom/url/URLSearchParams.h
@@ -10,16 +10,18 @@
 #include "js/StructuredClone.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/ErrorResult.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 #include "nsISupports.h"
 #include "nsIInputStream.h"
 
+class nsIGlobalObject;
+
 namespace mozilla {
 namespace dom {
 
 class URLSearchParams;
 class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString;
 
 class URLSearchParamsObserver : public nsISupports {
  public:
@@ -138,19 +140,22 @@ class URLSearchParams final : public nsI
   uint32_t GetIterableLength() const;
   const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
   const nsAString& GetValueAtIndex(uint32_t aIndex) const;
 
   void Sort(ErrorResult& aRv);
 
   void Stringify(nsString& aRetval) const { Serialize(aRetval); }
 
-  bool ReadStructuredClone(JSStructuredCloneReader* aReader);
+  static already_AddRefed<URLSearchParams> ReadStructuredClone(
+      JSContext* aCx, nsIGlobalObject* aGlobal,
+      JSStructuredCloneReader* aReader);
 
-  bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;
+  bool WriteStructuredClone(JSContext* aCx,
+                            JSStructuredCloneWriter* aWriter) const;
 
   nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
                        nsACString& aContentTypeWithCharset,
                        nsACString& aCharset) const;
 
  private:
   void AppendInternal(const nsAString& aName, const nsAString& aValue);
 
--- a/dom/webidl/URLSearchParams.webidl
+++ b/dom/webidl/URLSearchParams.webidl
@@ -9,17 +9,18 @@
  * 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 record<USVString, USVString> or USVString) init = ""),
- Exposed=(Window,Worker,WorkerDebugger)]
+ Exposed=(Window,Worker,WorkerDebugger),
+ Serializable]
 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);