Repository: dotnet/runtime
File: src/native/corehost/browserhost/loader/assets.ts (TypeScript)

Code before:

// in order to prevent net::ERR_INSUFFICIENT_RESOURCES if we start downloading too many files at same time on a device with low resources
async function loadResourceThrottle(asset: AssetEntryInternal): Promise<Response> {
    while (throttlingPCS) {
        await throttlingPCS.promise;
    }
    try {
        ++currentParallelDownloads;
        if (currentParallelDownloads == loaderConfig.maxParallelDownloads) {
            dotnetLogger.debug("Throttling further parallel downloads");
            throttlingPCS = createPromiseCompletionSource<void>();
        }
        const responsePromise = loadResourceFetch(asset);
        const response = await responsePromise;
        dotnetAssert.check(response, "Bad response in loadResourceThrottle");

        asset.buffer = await response.arrayBuffer();
        return response;
    } finally {
        --currentParallelDownloads;
        if (throttlingPCS && currentParallelDownloads == loaderConfig.maxParallelDownloads! - 1) {
            dotnetLogger.debug("Resuming more parallel downloads");
            const oldThrottlingPCS = throttlingPCS;
            throttlingPCS = undefined;
            oldThrottlingPCS.resolve();
        }
    }
}

async function loadResourceFetch(asset: AssetEntryInternal): Promise<Response> {
    if (asset.buffer) {
        return <Response><any>{
            ok: true,
            headers: {
                length: 0,
                get: () => null
            },
            url: asset.resolvedUrl,
            arrayBuffer: () => Promise.resolve(asset.buffer!),
            json: () => {
                throw new Error("NotImplementedException");
            },
            text: () => {
                throw new Error("NotImplementedException");
            }
        };
    }
    if (asset.pendingDownload) {
        return asset.pendingDownload.response;
    }
    if (typeof loadBootResourceCallback === "function") {

Review comment (suggestion):
The comparison operator should use strict equality (===) instead of loose equality (==) to follow JavaScript best practices and avoid potential type coercion issues.

Code after:
            } as any;
        }
        return response;
    }
}

// in order to prevent net::ERR_INSUFFICIENT_RESOURCES if we start downloading too many files at same time on a device with low resources
async function loadResourceThrottle(asset: AssetEntryInternal): Promise<Response> {
    while (throttlingPCS) {
        await throttlingPCS.promise;
    }
    try {
        ++currentParallelDownloads;
        if (currentParallelDownloads === loaderConfig.maxParallelDownloads) {
            dotnetLogger.debug("Throttling further parallel downloads");
            throttlingPCS = createPromiseCompletionSource<void>();
        }
        const responsePromise = loadResourceFetch(asset);
        const response = await responsePromise;
        dotnetAssert.check(response, "Bad response in loadResourceThrottle");

        asset.buffer = await response.arrayBuffer();
        return response;
    } finally {
        --currentParallelDownloads;
        if (throttlingPCS && currentParallelDownloads == loaderConfig.maxParallelDownloads! - 1) {
            dotnetLogger.debug("Resuming more parallel downloads");
            const oldThrottlingPCS = throttlingPCS;
            throttlingPCS = undefined;
            oldThrottlingPCS.resolve();
        }
    }
}

async function loadResourceFetch(asset: AssetEntryInternal): Promise<Response> {
    if (asset.buffer) {
        return <Response><any>{
            ok: true,
            headers: {
                length: 0,
                get: () => null
            },
            url: asset.resolvedUrl,
            arrayBuffer: () => Promise.resolve(asset.buffer!),
            json: () => {
                throw new Error("NotImplementedException");
            },
            text: () => {
                throw new Error("NotImplementedException");
            }
        };