Bug 1098145 - Fix BrowserElement::Download crash. r=smaug
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Fri, 21 Nov 2014 18:56:28 +0800
changeset 216856 389b2964076b92d62bed117d3b819f92450c5a83
parent 216855 0a6a9c3a6184f618867c342f1a2ae9cc93f6aba8
child 216857 174be68ce4ee992452d272ce23a045a40b65f61e
push id27866
push userkwierso@gmail.com
push dateFri, 21 Nov 2014 23:04:21 +0000
treeherderautoland@b612d5a501f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1098145
milestone36.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 1098145 - Fix BrowserElement::Download crash. r=smaug
dom/html/nsBrowserElement.cpp
--- a/dom/html/nsBrowserElement.cpp
+++ b/dom/html/nsBrowserElement.cpp
@@ -336,20 +336,23 @@ already_AddRefed<DOMRequest>
 nsBrowserElement::Download(const nsAString& aUrl,
                            const BrowserElementDownloadOptions& aOptions,
                            ErrorResult& aRv)
 {
   NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
   NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
 
   nsCOMPtr<nsIDOMDOMRequest> req;
+  nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(mBrowserElementAPI);
+  MOZ_ASSERT(wrappedObj, "Failed to get wrapped JS from XPCOM component.");
   AutoJSAPI jsapi;
-  jsapi.Init();
-  JS::Rooted<JS::Value> options(jsapi.cx());
-  if (!ToJSValue(jsapi.cx(), aOptions, &options)) {
+  jsapi.Init(wrappedObj->GetJSObject());
+  JSContext* cx = jsapi.cx();
+  JS::Rooted<JS::Value> options(cx);
+  if (!ToJSValue(cx, aOptions, &options)) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return nullptr;
   }
   nsresult rv = mBrowserElementAPI->Download(aUrl, options, getter_AddRefs(req));
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;