occ/TraceKit — pull request #37 by pieter (2013-02-26 10:37:12+00:00)
Title: Only install global error handler if we have at least one subscriber

This changes TraceKit to only install a window.onerror handler if we get a subscriber.

Even though the onerror handler is always necessary when catching exceptions for IE, there's no need for the handler if there are no exception handlers, since the exception would be ignored anyway.

Catching exceptions in development mode can be very annoying and can mess up debugging by changing backtraces to point to the last point where an exception has been rethrown, for example. For this reason, it's often easiest to not have any global exception handlers while debugging.

The way TraceKit was set up, this basically meant you were forced not to load in TraceKit code during debugging. This also then means that you'll get a lot of extra code in your production builds that you haven't tested in development.

With this change, TraceKit can still be loaded in development builds. If no subscriber is registered for handling exceptions, no global error handler will be installed, so debug builds can continue to work as normal.

Refers to #21 and #14.