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

Cordova file plugin onEvent(such as onload) should be invoked with _realReader as this

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • cordova-plugin-file
    • Android, ios, Browser

    Description

      When `FileReader` add onEvent listener such as `onload`, it will add the listener to inner `_realReader` , but when it invoke the listener, it use the FileReader as `this`.

      1. When add onload listener in application code.

      ```javascript
      var fileReader = new FileReader();
      fileReader.onload = function() {};
      ```

      it will call `www/FileReader.js defineEvent`

      ```javascript
      function defineEvent(eventName) {
      utils.defineGetterSetter(FileReader.prototype, eventName, function()

      { return this._realReader[eventName] || null; }

      , function(value)

      { this._realReader[eventName] = value; }

      );
      }
      ```

      the listener is added to `this._realReader`.

      And when the listener is triggered for example in `readSuccessCallback`
      it will invoke the method with `this`.
      ```javascript
      this.onload(new ProgressEvent("load",

      {target:this}

      ));
      ```

      in the normal senario, it will ok, but when it work with some polyfilles such as `zone.js of angular4`, it will fail because `zone.js` have some special handling which require the `this` object be the same when add listener and invoke listener.

      https://github.com/angular/zone.js/issues/868

      Attachments

        Activity

          People

            Unassigned Unassigned
            jialipassion Jia Li
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: