Bug 842081 - Workers: Transferable Objects should work if they are TypedArrays, r=sfink
☠☠ backed out by 262daca03163 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 27 Feb 2013 06:54:00 -0800
changeset 164666 e7d649603075c8142770527b383bd2ede5541491
parent 164665 8febf2f0e35dcc341b8acea6ae882a338144cc72
child 164667 048984fc3cd11817b17d7da6b4ce9702248cf25b
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs842081
milestone27.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 842081 - Workers: Transferable Objects should work if they are TypedArrays, r=sfink
dom/workers/test/test_transferable.html
dom/workers/test/transferable_worker.js
--- a/dom/workers/test/test_transferable.html
+++ b/dom/workers/test/test_transferable.html
@@ -17,30 +17,35 @@ Tests of DOM Worker transferable objects
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 <script class="testbody" language="javascript">
 
   function test1(sizes) {
     if (!sizes.length) {
-      SimpleTest.finish();
+      runTests();
       return;
     }
 
     var size = sizes.pop();
 
     var worker = new Worker("transferable_worker.js");
     worker.onmessage = function(event) {
       ok(event.data.status, event.data.event);
       if (!event.data.status) {
-        SimpleTest.finish();
+        runTests();
         return;
       }
 
+      if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
+        ok(event.data.notEmpty.byteLength != 0,
+           "P: NotEmpty object received: " + event.data.notEmpty.byteLength);
+      }
+
       if (!event.data.last)
         return;
 
       test1(sizes);
     }
     worker.onerror = function(event) {
       ok(false, "No errors!");
     }
@@ -55,21 +60,64 @@ Tests of DOM Worker transferable objects
     try {
       ab = new ArrayBuffer(size);
       worker.postMessage(42,[ab, ab]);
       ok(false, "P: PostMessage - Exception for duplicate");
     } catch(e) {
       ok(true, "P: PostMessage - Exception for duplicate");
     }
 
-    ab = new ArrayBuffer(size);
+    var ab = new ArrayBuffer(size);
     ok(ab.byteLength == size, "P: The size is: " + size + " == " + ab.byteLength);
     worker.postMessage({ data: 0, timeout: 0, ab: ab, cb: ab, size: size }, [ab]);
     ok(ab.byteLength == 0, "P: PostMessage - The size is: 0 == " + ab.byteLength)
   }
 
-  test1([1024 * 1024 * 32, 128, 4]);
+  function test2() {
+    var worker = new Worker("transferable_worker.js");
+    worker.onmessage = function(event) {
+      ok(event.data.status, event.data.event);
+      if (!event.data.status) {
+        runTests();
+        return;
+      }
+
+      if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
+        ok(event.data.notEmpty.byteLength != 0,
+           "P: NotEmpty object received: " + event.data.notEmpty.byteLength);
+      }
+
+      if (event.data.last) {
+        runTests();
+      }
+    }
+    worker.onerror = function(event) {
+      ok(false, "No errors!");
+    }
+
+    var f = new Float32Array([0,1,2,3]);
+    ok(f.byteLength != 0, "P: The size is: " + f.byteLength + " is not 0");
+    worker.postMessage({ event: "P: postMessage with Float32Array", status: true,
+                         size: 4, notEmpty: f, bc: [ f, f, { dd: f } ] }, [f.buffer]);
+    ok(f.byteLength == 0, "P: The size is: " + f.byteLength + " is 0");
+  }
+
+  var tests = [
+    function() { test1([1024 * 1024 * 32, 128, 4]); },
+    test2
+  ];
+  function runTests() {
+    if (!tests.length) {
+      SimpleTest.finish();
+      return;
+    }
+
+    var test = tests.shift();
+    test();
+  }
+
   SimpleTest.waitForExplicitFinish();
+  runTests();
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/workers/test/transferable_worker.js
+++ b/dom/workers/test/transferable_worker.js
@@ -1,33 +1,23 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 onmessage = function(event) {
-  if (event.data.data == 0) {
-    ab = new ArrayBuffer(event.data.size);
-    postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength,
-                  status: ab.byteLength == event.data.size, last: false });
+  if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
+    postMessage({ event: "W: NotEmpty object received: " + event.data.notEmpty.byteLength,
+                  status: event.data.notEmpty.byteLength != 0, last: false });
+  }
 
-    postMessage({ event: "W: postMessage with arrayBuffer", status: true,
-                  ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]);
-
-    postMessage({ event: "W: The size is: 0 == " + ab.byteLength,
-                  status: ab.byteLength == 0, last: false });
-
-    postMessage({ event: "last one!", status: true, last: true });
+  var ab = new ArrayBuffer(event.data.size);
+  postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength,
+                status: ab.byteLength == event.data.size, last: false });
 
-  } else {
-    var worker = new Worker('sync_worker.js');
-    worker.onmessage = function(event) {
-      postMessage(event.data);
-    }
-    worker.onsyncmessage = function(event) {
-      var v = postSyncMessage(event.data, null, 500);
-      event.reply(v);
-    }
+  postMessage({ event: "W: postMessage with arrayBuffer", status: true,
+                notEmpty: ab, ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]);
 
-    --event.data.data;
-    worker.postMessage(event.data);
-  }
+  postMessage({ event: "W: The size is: 0 == " + ab.byteLength,
+                status: ab.byteLength == 0, last: false });
+
+  postMessage({ event: "W: last one!", status: true, last: true });
 }