Bug 1096263 - XMLHttpRequest.send({}) should not throw. r=bz, a=lmandel
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 11 Nov 2014 05:35:00 -0500
changeset 226034 9e57cec588a9
parent 226033 43fd2720be09
child 226035 0197e9eb324f
push id4118
push userryanvm@gmail.com
push date2014-11-12 21:56 +0000
treeherdermozilla-beta@0197e9eb324f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lmandel
bugs1096263
milestone34.0
Bug 1096263 - XMLHttpRequest.send({}) should not throw. r=bz, a=lmandel
content/base/src/nsXMLHttpRequest.h
dom/bindings/Bindings.conf
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -423,57 +423,72 @@ private:
   nsresult Send(const RequestBody& aBody)
   {
     return Send(Nullable<RequestBody>(aBody));
   }
 
   bool IsDeniedCrossSiteRequest();
 
 public:
-  void Send(ErrorResult& aRv)
+  void Send(JSContext* /*aCx*/, ErrorResult& aRv)
   {
     aRv = Send(Nullable<RequestBody>());
   }
-  void Send(const mozilla::dom::ArrayBuffer& aArrayBuffer, ErrorResult& aRv)
+  void Send(JSContext* /*aCx*/,
+            const mozilla::dom::ArrayBuffer& aArrayBuffer,
+            ErrorResult& aRv)
   {
     aRv = Send(RequestBody(&aArrayBuffer));
   }
-  void Send(const mozilla::dom::ArrayBufferView& aArrayBufferView,
+  void Send(JSContext* /*aCx*/,
+            const mozilla::dom::ArrayBufferView& aArrayBufferView,
             ErrorResult& aRv)
   {
     aRv = Send(RequestBody(&aArrayBufferView));
   }
-  void Send(nsIDOMBlob* aBlob, ErrorResult& aRv)
+  void Send(JSContext* /*aCx*/, nsIDOMBlob* aBlob, ErrorResult& aRv)
   {
     NS_ASSERTION(aBlob, "Null should go to string version");
     aRv = Send(RequestBody(aBlob));
   }
-  void Send(nsIDocument& aDoc, ErrorResult& aRv)
+  void Send(JSContext* /*aCx*/, nsIDocument& aDoc, ErrorResult& aRv)
   {
     aRv = Send(RequestBody(&aDoc));
   }
-  void Send(const nsAString& aString, ErrorResult& aRv)
+  void Send(JSContext* aCx, const nsAString& aString, ErrorResult& aRv)
   {
     if (DOMStringIsNull(aString)) {
-      Send(aRv);
+      Send(aCx, aRv);
     }
     else {
       aRv = Send(RequestBody(aString));
     }
   }
-  void Send(nsFormData& aFormData, ErrorResult& aRv)
+  void Send(JSContext* /*aCx*/, nsFormData& aFormData, ErrorResult& aRv)
   {
     aRv = Send(RequestBody(aFormData));
   }
-  void Send(nsIInputStream* aStream, ErrorResult& aRv)
+  void Send(JSContext* aCx, nsIInputStream* aStream, ErrorResult& aRv)
   {
     NS_ASSERTION(aStream, "Null should go to string version");
     nsCOMPtr<nsIXPConnectWrappedJS> wjs = do_QueryInterface(aStream);
     if (wjs) {
-      aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+      JSObject* data = wjs->GetJSObject();
+      if (!data) {
+        aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+        return;
+      }
+      JS::Rooted<JS::Value> dataAsValue(aCx, JS::ObjectValue(*data));
+      nsAutoString dataAsString;
+      if (ConvertJSValueToString(aCx, dataAsValue, mozilla::dom::eNull,
+                                 mozilla::dom::eNull, dataAsString)) {
+        Send(aCx, dataAsString, aRv);
+      } else {
+        aRv.Throw(NS_ERROR_FAILURE);
+      }
       return;
     }
     aRv = Send(RequestBody(aStream));
   }
   void SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
 
   void Abort();
 
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1648,17 +1648,17 @@ DOMInterfaces = {
     'headerFile': 'mozilla/dom/workers/bindings/Navigator.h',
     'workers': True,
     'implicitJSContext': ['getDataStores'],
 },
 
 'XMLHttpRequest': [
 {
     'nativeType': 'nsXMLHttpRequest',
-    'implicitJSContext': [ 'constructor', ],
+    'implicitJSContext': [ 'constructor', 'send'],
     'resultNotAddRefed': [ 'upload', 'responseXML' ]
 },
 {
     'workers': True,
     # XXXkhuey responseXML returns Document? which boils down to a JSObject*
     # on a worker, and nsRefPtr<JSObject> fails in the expected way. channel is
     # similar.  This is ugly but it's all going away soon anyways.
     'resultNotAddRefed': [