HTML5 window error feature tests

Feature tests for the enhanced error handling functionality available in HTML5: `window.onerror` with new additional parameters, and `window.addEventListener("error", fn, false);`.

by James Greene

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/json2/20121008/json2.js"></script>

JavaScript

/*
TODO:
   1. Add tests around this:
      "If script has muted errors, then set message to "Script error.", set location to the empty string, set line and col to 0, and set error object to null.
Let event be a new trusted ErrorEvent object that does not bubble but is cancelable, and which has the event name error."
*/

(function() {

        // Save the old `window.onerror` handler, if any
    var winOldOnError = window.onerror,
        // Feature test results
        featureTestResults = {
            // `window.onerror = fn;`
            onerror_fired: false,
            onerror_hasAnyArgs: false,
            onerror_hasMsgArg: false,
            onerror_hasFileArg: false,
            onerror_hasLineArg: false,
            onerror_hasColumnArg: false,
            onerror_hasErrorArg: false,
            onerror_argsContents: [],
            // `window.addEventListener("error", fn, false);`
            ErrorEvent_exists: typeof ErrorEvent !== "undefined",
            ErrorEvent_fired: false,
            ErrorEvent_hasAnyArgs: false,
            ErrorEvent_argIsNull: false,
            ErrorEvent_argIsError: false,
            ErrorEvent_argIsEvent: false,
            ErrorEvent_argIsErrorEvent: false,
            ErrorEvent_contents: null,
            // `window.event`?
            windowEvent_exists: "event" in window,
            windowEvent_hasErrorDuringCatch: false,
            windowEvent_hasErrorDuringFinally: false,
            windowEvent_hasErrorAfterFinally: false,
            windowEvent_hasErrorDuringUnhandled: false,
            windowEvent_hasErrorAfterUnhandled: false
        },
        metaError = function(error) {
            return error === null ? null : {
                name: error.name,
                message: error.message,
                stack: error.stack
            };
        },
        errorHandlerFn = function(errorEvent) {
            featureTestResults.ErrorEvent_fired = true;
            
            if (arguments.length) {
  ...