Bug 1132655. Don't allow conversions from DOMString to const XPCOM string references, since it's meant to be an outparam only. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 12 Feb 2015 18:39:26 -0500
changeset 228913 ae4d683969e37bd7d651c347e1ccadceca4e1653
parent 228912 340f5b53053644af97ce12e7e03a57fa9cf2fe9f
child 228914 0792fde211c625b7093e60f4e811fd3d3d224112
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs1132655
milestone38.0a1
Bug 1132655. Don't allow conversions from DOMString to const XPCOM string references, since it's meant to be an outparam only. r=smaug
dom/bindings/DOMString.h
dom/html/HTMLTrackElement.h
dom/workers/ServiceWorkerClients.cpp
dom/workers/WorkerScope.h
--- a/dom/bindings/DOMString.h
+++ b/dom/bindings/DOMString.h
@@ -50,16 +50,21 @@ public:
                "Shouldn't have both present!");
   }
 
   operator nsString&()
   {
     return AsAString();
   }
 
+  // It doesn't make any sense to convert a DOMString to a const nsString or
+  // nsAString reference; this class is meant for outparams only.
+  operator const nsString&() = delete;
+  operator const nsAString&() = delete;
+
   nsString& AsAString()
   {
     MOZ_ASSERT(!mStringBuffer, "We already have a stringbuffer?");
     MOZ_ASSERT(!mIsNull, "We're already set as null");
     if (!mString) {
       mString.emplace();
     }
     return *mString;
--- a/dom/html/HTMLTrackElement.h
+++ b/dom/html/HTMLTrackElement.h
@@ -92,17 +92,17 @@ public:
 
   virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE;
 
   // For Track, ItemValue reflects the src attribute
   virtual void GetItemValueText(nsAString& aText) MOZ_OVERRIDE
   {
     DOMString value;
     GetSrc(value);
-    aText = value;
+    value.ToString(aText);
   }
   virtual void SetItemValueText(const nsAString& aText) MOZ_OVERRIDE
   {
     ErrorResult rv;
     SetSrc(aText, rv);
   }
 
   // Override ParseAttribute() to convert kind strings to enum values.
--- a/dom/workers/ServiceWorkerClients.cpp
+++ b/dom/workers/ServiceWorkerClients.cpp
@@ -245,17 +245,17 @@ public:
 
 already_AddRefed<Promise>
 ServiceWorkerClients::GetServiced(ErrorResult& aRv)
 {
   WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
   MOZ_ASSERT(workerPrivate);
   workerPrivate->AssertIsOnWorkerThread();
 
-  DOMString scope;
+  nsString scope;
   mWorkerScope->GetScope(scope);
 
   nsRefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   nsRefPtr<PromiseHolder> promiseHolder = new PromiseHolder(workerPrivate,
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -198,19 +198,19 @@ public:
 
   ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
 
   virtual bool
   WrapGlobalObject(JSContext* aCx,
                    JS::MutableHandle<JSObject*> aReflector) MOZ_OVERRIDE;
 
   void
-  GetScope(DOMString& aScope) const
+  GetScope(nsString& aScope) const
   {
-    aScope.AsAString() = mScope;
+    aScope = mScope;
   }
 
   void
   Close() const
   {
     // no-op close.
   }