Closed Bug 426417 Opened 18 years ago Closed 18 years ago

Design issue: breaking out of nsIEventQueue::eventLoop impossible from Javascript

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: m.cicciotti, Unassigned)

Details

User-Agent: Opera/9.26 (Windows NT 5.1; U; it) Build Identifier: The nsIEventQueue interface is nearly unusable from Javascript. The only way to create a modal event loop from Javascript is to use nsIEventQueue::eventLoop, which cannot be interrupted in any reliable way. Calling nsIThread::interrupt on the current thread is unreliable, as the interrupt can only be set once and it could be consumed by any wait, not just nsIEventQueue::eventLoop's CV wait. Delaying the call to nsIThread::interrupt with an XPCOM proxy object, in order for the call to be the only event in the queue, is ultimately futile, as the destructor for proxy calls will post a synchronous event to the queue, swallowing the interrupt nsIEventQueue::eventLoop will even inexplicably keep waiting for new events after nsIEventQueue::stopAcceptingEvents has been called on the queue, despite the queue being empty and marked as forever empty Reproducible: Always Steps to Reproduce: 1. create a new queue with nsIEventQueueService::pushThreadEventQueue 2. write a function that calls nsIThread::interrupt on the current thread, and wrap it into an nsIRunnable object's run method 3. call the object's nsIRunnable::run asynchronously through a proxy object (INVOKE_ASYNC | FORCE_PROXY_CREATION) on the queue created at point 1 4. invoke the queue's nsIEventQueue::eventLoop Actual Results: The thread is stuck inside nsIEventQueue::eventLoop Expected Results: nsIEventQueue::eventLoop is interrupted, the thread runs normally Queues should implement a new interface with a method acting exactly like nsIEventQueue::eventLoop, and a new method that causes the event loop created by the former method to abort. This would let scripts use an equivalent of the typical C++ code: while(!done && event = queue->waitForEvent()) queue->handleEvent(event); (nsIEventQueue::waitForEvent and nsIEventQueue::handleEvent are, naturally, [noscript])
At point 2 in the steps to reproduce, you can replace nsIEventQueue::stopAcceptingEvents for nsIThread::interrupt, for one more futile attempt to interrupt the event loop
nsIEventQueue and eventqueueservice have been completely altered in Firefox 3/Gecko 1.9. INVALID.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.