To understand the code in libmocha, you should be reasonably familiar with the JavaScript API.
The libmocha files are responsible for reflecting client-specific objects into the JavaScript world. For example, when the user opens a new window, libmocha creates a new object to represent the window. When that window loads an HTML document, libmocha creates new objects to represent the various forms, links, and other objects on the page. These new objects are window-specific and are hooked up by libmocha as children of the containing window.
Some objects in the client-side JavaScript world are unique: only one copy is created for the entire Navigator session instead of one per window. The navigator object is the best known example of such an object.
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.