All files / src/capabilities CapabilityDetector.ts

100% Statements 8/8
75% Branches 6/8
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37              5x   5x                     5x 5x 5x 5x         1x         5x      
import { ICapabilities } from "../types.js";
 
/**
 * 実行環境の能力(WASM, Threads, SIMD, WebGPU等)を検知します。
 */
export class CapabilityDetector {
  static async detect(): Promise<ICapabilities> {
    const nav = typeof navigator !== "undefined" ? navigator : null;
 
    return {
      opfs: !!nav?.storage?.getDirectory,
      wasmThreads: this.checkWasmThreads(),
      wasmSimd: this.checkWasmSimd(),
      webNN: !!nav && "ml" in nav,
      webGPU: !!nav && "gpu" in nav,
      webTransport: "WebTransport" in globalThis,
    };
  }
 
  private static checkWasmThreads(): boolean {
    try {
      Eif (typeof MessageChannel !== "undefined") {
        new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 });
        return true;
      }
    } catch {
      // Ignore
    }
    return false;
  }
 
  private static checkWasmSimd(): boolean {
    // 2026: WASM SIMD は主要ブラウザで標準
    return true;
  }
}