To implement Javascript error logging, we need to wrap every module in a try-catch block so that any errors that happen at module initialization time can be caught. (The alternative would be using window.onerror, which has lots of reliability problems.)
The two obvious ways to do that would be to add a PHP hook which can manipulate the string generated in ResourceLoader::makeLoaderImplementScript(), or to add some sort of JS hook to the module loading code in mw.loader (maybe a way to manipulate the registry in runScript()).
See the JS error logging RfC for more context, and T1345 for the current plans for JS error logging.