Improve serialization logic
[WebKit-https.git] / LayoutTests / fast / events / message-port-postMessage-recursive.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../resources/js-test-pre.js"></script>
5 <script>
6 description("Tests that recursive calls to MessagePort.postMessage() do not preempt timers.");
7 jsTestIsAsync = true;
8
9 function simulateSetImmediate()
10 {
11     var channel = new MessageChannel();
12     // Use a fifo linked list to call callbacks in the right order.
13     var head = {};
14     var tail = head;
15     channel['port1'].onmessage = function() {
16         if (head.next != null) {
17             head = head.next;
18             var cb = head.cb;
19             head.cb = null;
20             cb();
21         }
22     };
23     return function(cb) {
24         tail.next = {cb: cb};
25         tail = tail.next;
26         channel['port2'].postMessage(0);
27     };
28 }
29
30 window.setImmediate = simulateSetImmediate();
31
32 var shouldExit = false;
33
34 function iterate() {
35     if (shouldExit) {
36         testPassed("Timer has fired.");
37         finishJSTest();
38         return;
39     }
40     setImmediate(iterate);
41 }
42
43 setImmediate(iterate);
44 setTimeout(function() {
45     shouldExit = true;
46 }, 10);
47 </script>
48 <script src="../../resources/js-test-post.js"></script>
49 </body>
50 </html>