Skip to content

Implement channel messaging (MessageChannel and MessagePort) #7457

Closed

Activity

  1. added
    A-content/dom
    B-interesting-project
    on Aug 30, 2015
  2. cbrewster commented on Apr 7, 2016

    @cbrewster
    Contributor

    I am working on this one

  3. jdm commented on Apr 7, 2016

    @jdm
    MemberAuthor

    @ConnorGBrewster This is something I would want to have significant upfront planning for before having someone implement it. I started a branch earlier this week for experimenting and discovered that the specification is significantly more intricate than I anticipated, making the implementation much more complex than I originally expected.

    The biggest issue is that the queued messages need to be able to be transferred between script event loops if the associated message port is transferred, as this means that postMessage can't just send a message to the current target script thread. Implementing the spec's concept of an additional task source per message port also conveniently map to our use of Select in ScriptThread, which can't deal with variable message sources.

  4. cbrewster commented on Apr 7, 2016

    @cbrewster
    Contributor

    @jdm ok that makes sense. I currently just have skeletons setup for the MessageChannel and MessagePort DOM structs with the WebIDL bindings. I haven't done any actual implementation yet, I will hold off on that until a plan is created.

  5. added
    E-very-complex
    on Apr 13, 2016
  6. KiChjang commented on Dec 11, 2016

    @KiChjang
    Contributor

    I was reading the spec for this, and I feel like we may have chalked up the difficulty a bit too much on this one. I have in mind a preliminary version that may work and it goes like this:

    1. We create and implement a new TaskSource called PortMessageQueue and make a new method in GlobalScope to return it. (Maybe have this TaskSource store the has-been-shipped flag and disabled flag as well?)
    2. Code in the MessagePort DOM APIs and fields according to its WebIDL file, and add in a field called entangled_port which is of type DOMRefCell<Option<JS<MessagePort>>>
    3. Create a new Runnable called PortMessageRunnable. This will be responsible for firing the event at the target MessagePort.

    The entanglement operation would simply be accepting a new MessagePort object and creating a new Rc pointing to it, and then assigning this new Rc to the other MessagePort object's entangled_port field. postMessage would use the entangled_port field to get the GlobalScope for the entangled MessagePort, and transitively the PortMessageQueue. At this point, we now just need to create the MessageEvent and then queue it.

    Am I missing something here? I'm going to try and code this in and see if there's anything that I'm missing.

  7. self-assigned this
    on Dec 11, 2016
  8. KiChjang commented on Dec 11, 2016

    @KiChjang
    Contributor

    Ah, of course I forgot -- the case where you need to transfer the MessagePort. In Gecko, they store an enum that represents the state of the MessagePort (i.e. whether it is being entangled or disentangled, or if it is closing, etc.). We could check for the state of the MessagePort in the methods postMessage and start, and when the port is in the disentangled or disentangling state, abort the algorithms completely, since they would be handled in a special way during transfer. Does that make sense?

    In short, most of the complexities dealing with transferring tasks should occur in the transfer method.

  9. KiChjang commented on Dec 12, 2016

    @KiChjang
    Contributor

    That still doesn't address the issue where PortMessageRunnable are not supposed to be dropped when there is no corresponding PortMessageQueue. Perhaps we'll need to have the constellation store them temporarily, until the corresponding ScriptThread enables its PortMessageQueue. This would mean each individual Runnable will need to have a FrameId and registered domain name of its destination ScriptThread.

    But if we're going down this route, we might as well let the constellation be the first point of contact for all PortMessageRunnables, so instead of sending them directly to the associated PortMessageQueue, we'd send them to the constellation and let it handle the arbitration. This would eliminate to have associated states with MessagePorts - all of that logic would be handled properly by the constellation.

  10. added a commit that references this issue on Apr 30, 2017
    bb8dc62
  11. added 2 commits that reference this issue on Oct 23, 2017
    a5bfa70
    e8208c3
  12. added a commit that references this issue on Nov 3, 2017
    bab54f2
  13. added a commit that references this issue on Nov 13, 2017
    142bf55
  14. 15 remaining items

  15. added 3 commits that reference this issue on Sep 4, 2019
    2c4c547
    774f243
    da3a2c5
  16. added 11 commits that reference this issue on Oct 16, 2019
    d2c2e8b
    0a50fbb
    50a3f15
    e865d18
    66ede52
    88c68b2
    fa1fb97
    986ef87
    7a66938
    c466b40
    a905916
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-content/domB-interesting-projectE-very-complex

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions