installEarlyWebErrorHandlers function

void installEarlyWebErrorHandlers()

Installs the apply-once window JS-error listeners. The consumer main() calls this at boot-step-3 (only under Path A′). Idempotent: a second call is a no-op.

Implementation

void installEarlyWebErrorHandlers() {
  if (_webErrorListenersInstalled) {
    return;
  }
  _webErrorListenersInstalled = true;

  // 'error': synchronous JS errors reaching `window.onerror`.
  web.window.addEventListener(
    'error',
    ((web.ErrorEvent event) {
      _handleErrorEvent(event);
    }).toJS,
  );

  // 'unhandledrejection': rejected Promises with no handler.
  web.window.addEventListener(
    'unhandledrejection',
    ((web.PromiseRejectionEvent event) {
      _handleRejectionEvent(event);
    }).toJS,
  );
}