A new layer of code was added to support message passing between the core browser (running in the mozilla thread) and the mocha thread. The ET (EventTransfer) layer handles the passing of messages between the two threads. Code to send events from the mozilla thread to the mocha thread is in the file et_mocha.c. Code to send events from the mocha thread to the mozilla thread is in the file et_moz.c.
To avoid deadlocks between the threads, the mocha thread is allowed to block waiting for the mozilla thread in order to execute an action. By contrast, the mozilla thread is not allowed to block waiting for the mocha thread for any reason. When a running script calls window.open(), the mocha thread sends a message to the mozilla thread and then calls wait() until the mozilla thread creates a new window and sends back a handle to the window. In contrast, when an HTML document is being laid out in the mozilla thread and a script is encountered, layout is blocked. A message is sent instructing the mocha thread to evaluate the script, and the mozilla thread returns to its main event loop. When the mocha thread has finished evaluating the script, it sends a message to the mozilla thread, which unblocks layout and continues processing the document.