This isn’t directly a coding question, but answers to this will help in coding a Firefox addon.
- Is all JS addon code executed on main thread?
- Assuming question to above is ‘yes’, could the addon code be executed by different JS runtimes on the main thread?
- Assuming answer to #2 is ‘no’, are there multiple JS ‘execution contexts’ within the same JS runtime? If ‘yes’, could the addon code be executed by different execution contexts within the same JS runtime?
I could be way off in my above questions, but I am seeing a strange behavior in my addon that is causing parts of my addon code to hang (when a modal dialog is up, am not able to receive data on socket #1), but other parts continue working (am able to read data from socket #2). I am not able to explain the behavior.
Yes. AFAIK the only exception to this rule is code you run via web workers or ChromeWorker. There were plans to run extensions based on the Add-on SDK in a different process, I’m not sure whether this is still the goal.
Theoretically – yes. E.g. an extension could come with a binary XPCOM component containing a different JavaScript engine. Or there is the Zaphod extension coming with a JavaScript-based JavaScript engine. But that doesn’t really matter to your code running in the regular SpiderMonkey engine.
JavaScript execution is based on event queues – the browser will take an event from the queue (could be for example a DOM event, a timeout, a network event) and process it which will run corresponding JavaScript code. No other events can be processed until this JavaScript code finishes.
However, JavaScript code doesn’t continue to run when a modal dialog is open or a synchronous
XMLHttpRequestis performed – yet events still need to be processed. This is solved by modal dialogs andXMLHttpRequestdoing event processing while they are active (they spin their own event loop).So far the basics. Data coming in on a socket is a regular event – and it should work regardless of whether it is being processed by the main event loop or by the modal dialog’s loop.