-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Dedicated worker constructor should check response status #39413
Description
servo/components/script/dom/dedicatedworkerglobalscope.rs
Lines 507 to 530 in bbceb0f
| let (metadata, bytes) = match load_whole_resource( | |
| request, | |
| &global_scope.resource_threads().sender(), | |
| global_scope, | |
| &DedicatedWorkerCspProcessor { | |
| parent_event_loop_sender: parent_event_loop_sender.clone(), | |
| pipeline_id, | |
| }, | |
| CanGc::note(), | |
| ) { | |
| Err(e) => { | |
| error!("error loading script {} ({:?})", serialized_worker_url, e); | |
| parent_event_loop_sender | |
| .send(CommonScriptMsg::Task( | |
| WorkerEvent, | |
| Box::new(SimpleWorkerErrorHandler::new(worker)), | |
| Some(pipeline_id), | |
| TaskSourceName::DOMManipulation, | |
| )) | |
| .unwrap(); | |
| scope.clear_js_runtime(); | |
| return; | |
| }, | |
| Ok((metadata, bytes)) => (metadata, bytes), |
This code fetches a worker script, and dispatches an error event if the fetch is blocked for any reason. However, a fetch can be successful while still returning a response that is unusable (such as a 404 response), and we need to check that we can actually use the response before trying to execute it as a script.
Per https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-script, we need to implement step 2.2, and it should trigger step 1 of https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model:concept-script-error-to-rethrow . We will need to extract the error implementation from the current code (linked above) so it's shared by both cases.
Fixing this should also fix #22991, which is an extremely frequent intermittent test failure. Try running it in a debug build before and after making this change to see the difference (./mach test-wpt /workers/constructors/Worker/Worker-constructor.html --no-pause-after-test).