Repository: servo/servo
File: components/script/dom/worklet.rs (Rust)

Code before:
        let global = global_scope.upcast::<GlobalScope>();
        let resource_fetcher = self.global_init.resource_threads.sender();
        let request = RequestBuilder::new(None, script_url, global.get_referrer())
            .destination(Destination::Script)
            .mode(RequestMode::CorsMode)
            .credentials_mode(credentials.convert())
            .policy_container(policy_container)
            .origin(origin);

        let script = load_whole_resource(
            request,
            &resource_fetcher,
            global,
            &WorkletCspProcessor {},
            can_gc,
        )
        .ok()
        .and_then(|(_, bytes)| String::from_utf8(bytes).ok());

        // Step 4.
        // NOTE: the spec parses and executes the script in separate steps,
        // but our JS API doesn't separate these, so we do the steps out of order.
        // Also, the spec currently doesn't allow exceptions to be propagated
        // to the main script thread.
        // https://github.com/w3c/css-houdini-drafts/issues/407
        let ok = script
            .map(|s| global_scope.evaluate_js(&s, can_gc).is_ok())
            .unwrap_or(false);

        if !ok {
            // Step 3.
            debug!("Failed to load script.");
            let old_counter = pending_tasks_struct.set_counter_to(-1);
            if old_counter > 0 {
                self.run_in_script_thread(promise.reject_task(Error::Abort));
            }
        } else {
            // Step 5.
            debug!("Finished adding script.");
            let old_counter = pending_tasks_struct.decrement_counter_by(1);
            if old_counter == 1 {
                debug!("Resolving promise.");
                let msg = MainThreadScriptMsg::WorkletLoaded(pipeline_id);
                self.global_init
                    .to_script_thread_sender
                    .send(msg)
                    .expect("Worklet thread outlived script thread.");
                self.run_in_script_thread(promise.resolve_task(()));
            }
        }
    }

Review comment (suggestion):
There is `Result::is_ok_and` as well: 

```suggestion
        let ok = script.is_ok_and(|s| global_scope.evaluate_js(&s, can_gc));
```


Code after:
        let global = global_scope.upcast::<GlobalScope>();
        let resource_fetcher = self.global_init.resource_threads.sender();
        let request = RequestBuilder::new(None, script_url, global.get_referrer())
            .destination(Destination::Script)
            .mode(RequestMode::CorsMode)
            .credentials_mode(credentials.convert())
            .policy_container(policy_container)
            .origin(origin);

        let script = load_whole_resource(
            request,
            &resource_fetcher,
            global,
            &WorkletCspProcessor {},
            can_gc,
        )
        .ok()
        .and_then(|(_, bytes)| String::from_utf8(bytes).ok());

        // Step 4.
        // NOTE: the spec parses and executes the script in separate steps,
        // but our JS API doesn't separate these, so we do the steps out of order.
        // Also, the spec currently doesn't allow exceptions to be propagated
        // to the main script thread.
        // https://github.com/w3c/css-houdini-drafts/issues/407
        let ok = script.is_some_and(|s| global_scope.evaluate_js(&s, can_gc).is_ok());

        if !ok {
            // Step 3.
            debug!("Failed to load script.");
            let old_counter = pending_tasks_struct.set_counter_to(-1);
            if old_counter > 0 {
                self.run_in_script_thread(promise.reject_task(Error::Abort));
            }
        } else {
            // Step 5.
            debug!("Finished adding script.");
            let old_counter = pending_tasks_struct.decrement_counter_by(1);
            if old_counter == 1 {
                debug!("Resolving promise.");
                let msg = MainThreadScriptMsg::WorkletLoaded(pipeline_id);
                self.global_init
                    .to_script_thread_sender
                    .send(msg)
                    .expect("Worklet thread outlived script thread.");
                self.run_in_script_thread(promise.resolve_task(()));
            }
        }
    }

    /// Perform a task.