Bug 1127206 - Don't try to do binding UnwrapArgImpl on worker threads. It can't do anything useful there. r=peterv, a=abillings
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 30 Jan 2015 13:54:43 -0500
changeset 243628 63e9ce6a9a45
parent 243627 89994d9c2522
child 243629 08954688351c
push id4420
push userryanvm@gmail.com
push date2015-02-02 16:43 +0000
treeherdermozilla-beta@e98376bbdf79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv, abillings
bugs1127206
milestone36.0
Bug 1127206 - Don't try to do binding UnwrapArgImpl on worker threads. It can't do anything useful there. r=peterv, a=abillings
dom/base/File.cpp
dom/bindings/BindingUtils.cpp
dom/bindings/test/mochitest.ini
dom/bindings/test/test_worker_UnwrapArg.html
--- a/dom/base/File.cpp
+++ b/dom/base/File.cpp
@@ -621,17 +621,17 @@ File::Constructor(
 }
 
 /* static */ already_AddRefed<File>
 File::Constructor(const GlobalObject& aGlobal,
                   File& aData,
                   const ChromeFilePropertyBag& aBag,
                   ErrorResult& aRv)
 {
-  if (!nsContentUtils::IsCallerChrome()) {
+  if (!nsContentUtils::ThreadsafeIsCallerChrome()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl(EmptyString());
   impl->InitializeChromeFile(aData, aBag, aRv);
   if (aRv.Failed()) {
     return nullptr;
@@ -643,16 +643,17 @@ File::Constructor(const GlobalObject& aG
 }
 
 /* static */ already_AddRefed<File>
 File::Constructor(const GlobalObject& aGlobal,
                   nsIFile* aData,
                   const ChromeFilePropertyBag& aBag,
                   ErrorResult& aRv)
 {
+  MOZ_ASSERT(NS_IsMainThread());
   if (!nsContentUtils::IsCallerChrome()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
 
   nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl(EmptyString());
@@ -667,17 +668,17 @@ File::Constructor(const GlobalObject& aG
 }
 
 /* static */ already_AddRefed<File>
 File::Constructor(const GlobalObject& aGlobal,
                   const nsAString& aData,
                   const ChromeFilePropertyBag& aBag,
                   ErrorResult& aRv)
 {
-  if (!nsContentUtils::IsCallerChrome()) {
+  if (!nsContentUtils::ThreadsafeIsCallerChrome()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
 
   nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl(EmptyString());
   impl->InitializeChromeFile(window, aData, aBag, aRv);
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2633,16 +2633,20 @@ CallerSubsumes(JSObject *aObject)
   return nsContentUtils::SubjectPrincipal()->Subsumes(objPrin);
 }
 
 nsresult
 UnwrapArgImpl(JS::Handle<JSObject*> src,
               const nsIID &iid,
               void **ppArg)
 {
+    if (!NS_IsMainThread()) {
+      return NS_ERROR_NOT_AVAILABLE;
+    }
+
     nsISupports *iface = xpc::UnwrapReflectorToISupports(src);
     if (iface) {
         if (NS_FAILED(iface->QueryInterface(iid, ppArg))) {
             return NS_ERROR_XPC_BAD_CONVERT_JS;
         }
 
         return NS_OK;
     }
--- a/dom/bindings/test/mochitest.ini
+++ b/dom/bindings/test/mochitest.ini
@@ -48,8 +48,9 @@ skip-if = debug == false
 skip-if = debug == false
 [test_sequence_wrapping.html]
 [test_setWithNamedGetterNoNamedSetter.html]
 [test_throwing_method_noDCE.html]
 [test_treat_non_object_as_null.html]
 [test_traceProtos.html]
 [test_sequence_detection.html]
 skip-if = debug == false
+[test_worker_UnwrapArg.html]
new file mode 100644
--- /dev/null
+++ b/dom/bindings/test/test_worker_UnwrapArg.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1127206
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1127206</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1127206 **/
+  SimpleTest.waitForExplicitFinish();
+  var blob = new Blob([
+    `try { new File({}); }
+     catch (e) {
+       postMessage("throwing on random object");
+     }
+     try { new File(new Blob(["abc"])); }
+     catch (e)  {
+       postMessage("throwing on Blob");
+     }
+     try { new File("abc"); }
+     catch (e) {
+       postMessage("throwing on string");
+     }
+     postMessage('finishTest')`]);
+  var url = URL.createObjectURL(blob);
+  var w = new Worker(url);
+  var expectedResults = [
+    "throwing on random object",
+    "throwing on Blob",
+    "throwing on string",
+  ];
+  var curIndex = 0;
+  w.onmessage = function(e) {
+    if (curIndex == expectedResults.length) {
+      is(e.data, "finishTest", "What message is this?");
+      SimpleTest.finish();
+    } else {
+      is(e.data, expectedResults[curIndex],
+         "Message " + (curIndex+1) + " should be correct");
+      ++curIndex;
+    }
+  }
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1127206">Mozilla Bug 1127206</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>