installWebGpuAdapterInfoShim function

void installWebGpuAdapterInfoShim()

Implementation

void installWebGpuAdapterInfoShim() {
  try {
    final g = globalContext;
    final ga = g.getProperty<JSObject?>('GPUAdapter'.toJS);
    if (ga == null || ga.isUndefinedOrNull) return;
    final proto = ga.getProperty<JSObject?>('prototype'.toJS);
    if (proto == null || proto.isUndefinedOrNull) return;
    if (proto.has('info')) return;
    final functionCtor = g.getProperty<JSFunction>('Function'.toJS);
    final install = functionCtor.callAsConstructorVarArgs<JSFunction>(
        ['proto'.toJS, _kAdapterInfoShimSource.toJS]);
    install.callAsFunction(null, proto);
  } catch (_) {
    // A browser that refuses the property leaves the glue exactly as it was.
  }
}