Bug 842081 - Workers: Transferable Objects should work if they are TypedArrays, r=sfink

--HG--
extra : rebase_source : 890a08f42a011381af23a197d0e1f73d2ec66632
This commit is contained in:
Andrea Marchesini 2013-10-15 23:48:38 -07:00
Родитель 63e2453e93
Коммит 28eb8d7130
2 изменённых файлов: 67 добавлений и 29 удалений

Просмотреть файл

@ -22,7 +22,7 @@ Tests of DOM Worker transferable objects
function test1(sizes) {
if (!sizes.length) {
SimpleTest.finish();
runTests();
return;
}
@ -32,10 +32,15 @@ Tests of DOM Worker transferable objects
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;
@ -60,14 +65,57 @@ Tests of DOM Worker transferable objects
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>

Просмотреть файл

@ -4,30 +4,20 @@
*/
onmessage = function(event) {
if (event.data.data == 0) {
ab = new ArrayBuffer(event.data.size);
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 });
}
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 });
postMessage({ event: "W: postMessage with arrayBuffer", status: true,
ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]);
notEmpty: ab, 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 });
} 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);
}
--event.data.data;
worker.postMessage(event.data);
}
postMessage({ event: "W: last one!", status: true, last: true });
}