Bug 1426501 - Change nsIURIMutator to call set spec on cloned URI if available r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 08 Jan 2018 11:23:59 +0100
changeset 450021 a3baf4893b8db0c291002b62570c5fefaeb0b3b9
parent 450020 a1e8bf62f2da4499ac2da75ecf2e3c94f8b9009c
child 450022 ad96d6e27750f433d7326d2940e84783b616a5b7
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1426501
milestone59.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 1426501 - Change nsIURIMutator to call set spec on cloned URI if available r=mayhemer Calling SetSpec on an nsIURI object doesn't reinitialize the object, meaning it's not equivalent with creating a new URI with the same spec. While this might be counter-intuitive we want to preserve existing behaviour for the moment. This change makes BaseURIMutator::InitFromSpec call SetSpec on the existing cloned URI if available. Otherwise it creates a new one. MozReview-Commit-ID: LuHVRhBItiP
netwerk/base/nsIURIMutator.idl
netwerk/test/unit/test_URIs.js
netwerk/test/unit/test_URIs2.js
--- a/netwerk/base/nsIURIMutator.idl
+++ b/netwerk/base/nsIURIMutator.idl
@@ -61,18 +61,26 @@ protected:
       return NS_ERROR_FAILURE;
     }
     mURI = uri;
     return NS_OK;
   }
 
   MOZ_MUST_USE nsresult InitFromSpec(const nsACString& aSpec)
   {
-    RefPtr<T> uri = new T();
-    nsresult rv = uri->SetSpec(aSpec);
+    nsresult rv = NS_OK;
+    RefPtr<T> uri;
+    if (mURI) {
+      // This only works because all other Init methods create a new object
+      mURI.swap(uri);
+    } else {
+      uri = new T();
+    }
+
+    rv = uri->SetSpec(aSpec);
     if (NS_FAILED(rv)) {
       return rv;
     }
     mURI = uri;
     return NS_OK;
   }
 
   RefPtr<T> mURI;
--- a/netwerk/test/unit/test_URIs.js
+++ b/netwerk/test/unit/test_URIs.js
@@ -480,18 +480,21 @@ function do_test_mutate_ref(aTest, aSuff
 
   if (!aTest.relativeURI) {
     // TODO: These tests don't work as-is for relative URIs.
 
     // Now try setting .spec directly (including suffix) and then clearing .ref
     var specWithSuffix = aTest.spec + aSuffix;
     do_info("testing that setting spec to " +
             specWithSuffix + " and then clearing ref does what we expect");
-    testURI.spec = specWithSuffix;
-    testURI.ref = "";
+
+    testURI = testURI.mutate()
+                     .setSpec(specWithSuffix)
+                     .setRef("")
+                     .finalize();
     do_check_uri_eq(testURI, refURIWithoutSuffix);
     do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
 
     // XXX nsIJARURI throws an exception in SetPath(), so skip it for next part.
     if (!(testURI instanceof Ci.nsIJARURI)) {
       // Now try setting .pathQueryRef directly (including suffix) and then clearing .ref
       // (same as above, but with now with .pathQueryRef instead of .spec)
       testURI = NetUtil.newURI(aTest.spec);
--- a/netwerk/test/unit/test_URIs2.js
+++ b/netwerk/test/unit/test_URIs2.js
@@ -582,18 +582,20 @@ function do_test_mutate_ref(aTest, aSuff
 
   if (!aTest.relativeURI) {
     // TODO: These tests don't work as-is for relative URIs.
 
     // Now try setting .spec directly (including suffix) and then clearing .ref
     var specWithSuffix = aTest.spec + aSuffix;
     do_info("testing that setting spec to " +
             specWithSuffix + " and then clearing ref does what we expect");
-    testURI.spec = specWithSuffix;
-    testURI.ref = "";
+    testURI = testURI.mutate()
+                     .setSpec(specWithSuffix)
+                     .setRef("")
+                     .finalize();
     do_check_uri_eq(testURI, refURIWithoutSuffix);
     do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
 
     // XXX nsIJARURI throws an exception in SetPath(), so skip it for next part.
     if (!(testURI instanceof Ci.nsIJARURI)) {
       // Now try setting .pathQueryRef directly (including suffix) and then clearing .ref
       // (same as above, but with now with .pathQueryRef instead of .spec)
       testURI = NetUtil.newURI(aTest.spec);