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

Code before:
    response.Headers(can_gc).set_guard(Guard::Immutable);

    // Step 2. Let requestObject be the result of invoking the initial value of Request as constructor
    //         with input and init as arguments. If this throws an exception, reject p with it and return p.
    let request_object = match Request::Constructor(global, None, can_gc, input, init) {
        Err(e) => {
            response.error_stream(e.clone(), can_gc);
            promise.reject_error(e, can_gc);
            return promise;
        },
        Ok(r) => r,
    };
    // Step 3. Let request be requestObject’s request.
    let request = request_object.get_request();
    let timing_type = request.timing_type();

    // Step 4. If requestObject’s signal is aborted, then:
    let signal = request_object.Signal();
    if signal.aborted() {
        // Step 4.1. Abort the fetch() call with p, request, null, and requestObject’s signal’s abort reason.
        rooted!(in(*cx) let mut abort_reason = UndefinedValue());
        signal.Reason(cx, abort_reason.handle_mut());
        abort_fetch_call(
            promise.clone(),
            &request_object,
            Some(&response),
            abort_reason.handle(),
            global,
            cx,
            can_gc,
        );
        // Step 4.2. Return p.
        return promise;
    }

    // Step 5. Let globalObject be request’s client’s global object.
    // NOTE:   We already get the global object as an argument
    let mut request_init = request_init_from_request(request);
    request_init.policy_container =
        RequestPolicyContainer::PolicyContainer(global.policy_container());

    // Step 6. If globalObject is a ServiceWorkerGlobalScope object, then set request’s
    //         service-workers mode to "none".
    if global.is::<ServiceWorkerGlobalScope>() {
        request_init.service_workers_mode = ServiceWorkersMode::None;
    }

    // Step 8. Let relevantRealm be this’s relevant realm.
    //
    // Is `comp` as argument


Review comment (suggestion):
This was only for testing to see if it works. It should actually be `None`, but wasn't sure yet. Since many of the tests don't run, will keep this here for now.

Code after:
    response.Headers(can_gc).set_guard(Guard::Immutable);

    // Step 2. Let requestObject be the result of invoking the initial value of Request as constructor
    //         with input and init as arguments. If this throws an exception, reject p with it and return p.
    let request_object = match Request::Constructor(global, None, can_gc, input, init) {
        Err(e) => {
            response.error_stream(e.clone(), can_gc);
            promise.reject_error(e, can_gc);
            return promise;
        },
        Ok(r) => r,
    };
    // Step 3. Let request be requestObject’s request.
    let request = request_object.get_request();
    let timing_type = request.timing_type();
    let request_id = request.id;

    // Step 4. If requestObject’s signal is aborted, then:
    let signal = request_object.Signal();
    if signal.aborted() {
        // Step 4.1. Abort the fetch() call with p, request, null, and requestObject’s signal’s abort reason.
        rooted!(in(*cx) let mut abort_reason = UndefinedValue());
        signal.Reason(cx, abort_reason.handle_mut());
        abort_fetch_call(
            promise.clone(),
            &request_object,
            None,
            abort_reason.handle(),
            global,
            cx,
            can_gc,
        );
        // Step 4.2. Return p.
        return promise;
    }

    // Step 5. Let globalObject be request’s client’s global object.
    // NOTE:   We already get the global object as an argument
    let mut request_init = request_init_from_request(request);
    request_init.policy_container =
        RequestPolicyContainer::PolicyContainer(global.policy_container());

    // Step 6. If globalObject is a ServiceWorkerGlobalScope object, then set request’s
    //         service-workers mode to "none".
    if global.is::<ServiceWorkerGlobalScope>() {
        request_init.service_workers_mode = ServiceWorkersMode::None;
    }

    // Step 8. Let relevantRealm be this’s relevant realm.
    //
    // Is `comp` as argument