Module script::script_thread
source Β· Expand description
The script thread is the thread that owns the DOM in memory, runs JavaScript, and triggers layout. Itβs in charge of processing events for all same-origin pages in a frame tree, and manages the entire lifetime of pages in the frame tree from initial request to teardown.
Page loads follow a two-step process. When a request for a new page load is received, the network request is initiated and the relevant data pertaining to the new page is stashed. While the non-blocking request is ongoing, the script thread is free to process further events, noting when they pertain to ongoing loads (such as resizes/viewport adjustments). When the initial response is received for an ongoing load, the second phase starts - the frame tree entry is created, along with the Window and Document objects, and the appropriate parser takes over the response body. Once parsing is complete, the document lifecycle for loading a page runs its course and the script thread returns to processing events in the main event loop.
Structs§
- BHMExit
Signal π - InProgress
Load πA document load that is in the process of fetching the requested resource. Contains data that will need to be present when the document and frame tree entry are created, but is only easily available at initiation of the load and on a push basis (so some data will be updated according to future resize events, viewport changes, etc.) - Encapsulates internal communication of main thread messages within the script thread.
- Script
Memory πFailsafe In the event of thread panic, all data on the stack runs its destructor. However, there are no reachable, owning pointers to the DOM memory, so it never gets freed by default when the script thread fails. The ScriptMemoryFailsafe uses the destructor bomb pattern to forcibly tear down the JS realms for pages associated with the failing ScriptThread. - Encapsulates internal communication of shared messages within the script thread.
Enums§
- Messages used to control the script event loop.
- Mixed
Message π
Constants§
- SCRIP
T_ πTHREA D_ ROOT
Functions§
- interrupt_
callback π β - Safety
- with_
script_ πthread