wrapJSExceptions<T> function

T wrapJSExceptions<T>(
  1. T callback()
)

Runs callback, wrapping any primitive JS objects it throws so they don't crash when caught by Dart code.

This works around a bug in Dart where primitive types such as strings thrown by JS will cause Dart code that catches them to crash in strict mode specifically. For safety, all calls to callbacks passed in from an external JS context should be wrapped in this function.

This function will rethrow the original error if it's run from a non-JS platform.

Implementation

T wrapJSExceptions<T>(T Function() callback) => throw '';