servo/servo — pull request #4057 by jdm (2014-11-21 15:14:38+00:00)
Title: Enable refcounting arbitrary DOM types

This replaces the specialized TrustedXHRAddress and TrustedWorkerAddress code that was for the same purpose. A non-zero refcount pins the given DOM object's reflector and prevents it from being GCed even there are no other outstanding references visible to SpiderMonkey. This will enable us to implement asynchronous operations that refer to particular DOM objects (such as "queue a task to fire a simple event named load at the iframe element" from the spec) safely and conveniently, and paves the way for things like asynchronous network responses.

Some concerns about the resulting size of XHR progress messages have been expressed, but I believe optimizations to reduce that can be implemented in subsequent PRs.

r? @Ms2ger - note in particular the changes to the worker lifetime code. I couldn't figure out how to achieve an identical lifetime to the previous addref/release pairing, and I also was having trouble figuring out why the existing setup was safe. The new implementation now holds the main script task Worker object alive via the TrustedWorkerAddress field in the dedicated worker global scope, which is a significant difference.