OLD | NEW |
1 // Useful utilities for worker tests | 1 // Useful utilities for worker tests |
2 | 2 |
3 function log(message) | 3 function log(message) |
4 { | 4 { |
5 document.getElementById("result").innerHTML += message + "<br>"; | 5 document.getElementById("result").innerHTML += message + "<br>"; |
6 } | 6 } |
7 | 7 |
8 function gc(forceAlloc) | |
9 { | |
10 if (typeof GCController !== "undefined") | |
11 GCController.collect(); | |
12 | |
13 if (typeof GCController == "undefined" || forceAlloc) { | |
14 function gcRec(n) { | |
15 if (n < 1) | |
16 return {}; | |
17 var temp = {i: "ab" + i + (i / 100000)}; | |
18 temp += "foo"; | |
19 gcRec(n-1); | |
20 } | |
21 for (var i = 0; i < 1000; i++) | |
22 gcRec(10) | |
23 } | |
24 } | |
25 | |
26 function waitUntilWorkerThreadsExit(callback) | 8 function waitUntilWorkerThreadsExit(callback) |
27 { | 9 { |
28 waitUntilThreadCountMatches(callback, 0); | 10 waitUntilThreadCountMatches(callback, 0); |
29 } | 11 } |
30 | 12 |
31 function waitUntilThreadCountMatches(callback, count) | 13 function waitUntilThreadCountMatches(callback, count) |
32 { | 14 { |
33 // When running in a browser, just wait for one second then call the callbac
k. | 15 // When running in a browser, just wait for one second then call the callbac
k. |
34 if (!window.testRunner) { | 16 if (!window.testRunner) { |
35 setTimeout(function() { gc(true); callback(); }, 1000); | 17 setTimeout(function() { gc(); callback(); }, 1000); |
36 return; | 18 return; |
37 } | 19 } |
38 | 20 |
39 if (internals.workerThreadCount == count) { | 21 if (internals.workerThreadCount == count) { |
40 // Worker threads have exited. | 22 // Worker threads have exited. |
41 callback(); | 23 callback(); |
42 } else { | 24 } else { |
43 // Poll until worker threads have been GC'd/exited. | 25 // Poll until worker threads have been GC'd/exited. |
44 // Force a GC with a bunch of allocations to try to scramble the stack a
nd force worker objects to be collected. | 26 // Force a GC with a bunch of allocations to try to scramble the stack a
nd force worker objects to be collected. |
45 gc(true); | 27 gc(true); |
(...skipping 15 matching lines...) Expand all Loading... |
61 debug('<br><span class="pass">TEST COMPLETE</span>'); | 43 debug('<br><span class="pass">TEST COMPLETE</span>'); |
62 else | 44 else |
63 log("DONE"); | 45 log("DONE"); |
64 | 46 |
65 // Call notifyDone via the queue so any pending console messages/exceptions
are written out first. | 47 // Call notifyDone via the queue so any pending console messages/exceptions
are written out first. |
66 setTimeout(function() { | 48 setTimeout(function() { |
67 if (window.testRunner) | 49 if (window.testRunner) |
68 testRunner.notifyDone(); | 50 testRunner.notifyDone(); |
69 }, 0); | 51 }, 0); |
70 } | 52 } |
OLD | NEW |