Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9256

Errors in subscribed event callbacks prevent other subscribed callbacks from being invoked

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • cordova-js
    • None

    Description

      Let's say I register two callbacks for the "deviceReady" event before the event fires. If the first callback hits an error, the second callback will not be invoked

      document.addEventListener("deviceready", function () { throw new Error("oops"); });
      document.addeventListener("deviceready", function () { /*never hit*/ });
      

      This behavior differs if the events were registered after the event was fired.

      I think the following code should handle callbacks that fail:

      https://github.com/apache/cordova-js/blob/master/src/common/channel.js#L213

      for (var i = 0; i < toCall.length; ++i) {
        toCall[i].apply(this, fireArgs);
      }
      

      Should be something like:

      var errors = [];
      for (var i = 0; i < toCall.length; ++i) {
        try {
          toCall[i].apply(this, fireArgs);
        } catch (e) {
          errors.push(e);
        }
      }
      for (var j = 0; j < errors.length; ++j) {
        (function (arg) {
          setTimeout(function () { throw errors[arg]; });
        })(j);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            swexler Steven Wexler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: