Skip to content

Implement worker modules

Josh Matthews edited this page Feb 17, 2020 · 1 revision

Background information: Major browsers support worker JavaScript modules which support more complex JS module integration than classic Web Workers. Servo is a new, experimental browser that supports Web Workers and non-worker JS module scripts; the goal of this project is implement support for worker module scripts.

Tracking issue: (please ask questions in these issues)

Useful references:

Initial steps:

  • email the mozilla.dev.servo mailing list (be sure to subscribe to it first!) introducing your group and asking any necessary questions
  • restructure worker creation to avoid synchronously waiting for an initial worker script
    • in run_worker_scope in components/script/dom/dedicatedworkerglobalscope.rs, extract the RequestBuilder creation and load_whole_resource call into a separate function called fetch_a_classic_worker_script
    • add a ScriptLoaded variant to WorkerScriptMessage in components/script/dom/abstractworker.rs which stores a Result<(Url, String), String> value
    • update DedicatedWorkerGlobalScope::handle_script_event to deal with the new event type - move the scope.execute_script call out of run_worker_scope when a script loaded successfully, and move the error handling out of the return value of load_whole_resource when an error is passed instead
    • make the new fetch_a_classic_worker_script function queue a ScriptLoaded event when either an error occurs or the script loads successfully

Subsequent steps:

  • create initial failing test results for worker module automated tests
  • implement the unimplemented! worker branch in ModuleOwner::finish_module_load:
    • duplicate whatever code is necessary from the Window branch to add is_top_level handling for worker modules that calls a method on the DedicatedWorkerGlobalScope that queues the ScriptLoaded event
    • once that works as expected, refactor both branches to share as much code as possible without duplication
  • verify that the automated tests are producing more reasonable successful results and update the test expectations again
Clone this wiki locally