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

Code before:
        BrowserHost_InitializeCoreCLR();
    }

    await assembliesPromise;
    await runtimeModuleReady;
}

async function loadJSModule(asset: JsAsset): Promise<JsModuleExports> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    if (!asset.resolvedUrl) throw new Error("Invalid config, resources is not set");
    return await import(/* webpackIgnore: true */ asset.resolvedUrl);
}

function fetchWasm(asset: WasmAsset): Promise<Response> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    if (!asset.resolvedUrl) throw new Error("Invalid config, resources is not set");
    wasmBinaryPromise = fetchLike(asset.resolvedUrl);
    return wasmBinaryPromise;
}

export async function instantiateWasm(imports: WebAssembly.Imports, successCallback: InstantiateWasmSuccessCallback): Promise<void> {
    const res = await WebAssembly.instantiateStreaming(wasmBinaryPromise, imports);
    successCallback(res.instance, res.module);
}

async function fetchIcu(asset: IcuAsset): Promise<void> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    const bytes = await fetchBytes(asset);
    await nativeModulePromiseController.promise;
    dotnetBrowserHostExports.loadIcuData(bytes);
}

async function fetchDll(asset: AssemblyAsset): Promise<void> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    const bytes = await fetchBytes(asset);
    await nativeModulePromiseController.promise;

    dotnetBrowserHostExports.registerDllBytes(bytes, asset);
}

async function fetchVfs(asset: AssemblyAsset): Promise<void> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);

Review comment (bug):
`instantiateWasm` uses `WebAssembly.instantiateStreaming()` with `wasmBinaryPromise` which returns a mock Response object in Node.js (lines 132-144). `instantiateStreaming` requires a real Response with proper streaming support, but the mock object only provides `arrayBuffer()`. This will likely fail in Node.js environments. Consider checking `ENVIRONMENT_IS_NODE` and using `WebAssembly.instantiate()` with an ArrayBuffer instead.
```suggestion
    let res;
    if (ENVIRONMENT_IS_NODE) {
        const response = await wasmBinaryPromise;
        const bytes = await response.arrayBuffer();
        res = await WebAssembly.instantiate(bytes, imports);
    } else {
        res = await WebAssembly.instantiateStreaming(wasmBinaryPromise, imports);
    }
```

Code after:
    if (!downloadOnly) {
        BrowserHost_InitializeCoreCLR();
    }

    await assembliesPromise;
    await runtimeModuleReady;
}

async function loadJSModule(asset: JsAsset): Promise<JsModuleExports> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    if (!asset.resolvedUrl) throw new Error("Invalid config, resources is not set");
    return await import(/* webpackIgnore: true */ asset.resolvedUrl);
}

function fetchWasm(asset: WasmAsset): Promise<Response> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    if (!asset.resolvedUrl) throw new Error("Invalid config, resources is not set");
    wasmBinaryPromise = fetchLike(asset.resolvedUrl);
    return wasmBinaryPromise;
}

export async function instantiateWasm(imports: WebAssembly.Imports, successCallback: InstantiateWasmSuccessCallback): Promise<void> {
    if (wasmBinaryPromise instanceof globalThis.Response === false || !WebAssembly.instantiateStreaming) {
        const res = await wasmBinaryPromise;
        const data = await res.arrayBuffer();
        const module = await WebAssembly.compile(data);
        const instance = await WebAssembly.instantiate(module, imports);
        successCallback(instance, module);
    } else {
        const res = await WebAssembly.instantiateStreaming(wasmBinaryPromise, imports);
        successCallback(res.instance, res.module);
    }
}

async function fetchIcu(asset: IcuAsset): Promise<void> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }
    const bytes = await fetchBytes(asset);
    await nativeModulePromiseController.promise;
    dotnetBrowserHostExports.loadIcuData(bytes);
}

async function fetchDll(asset: AssemblyAsset): Promise<void> {
    if (asset.name && !asset.resolvedUrl) {
        asset.resolvedUrl = locateFile(asset.name);
    }