Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4010

Q.fcall messing up with *this* pointer inside called function

VotersStop watchingWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.3
    • 0.11.0
    • Node.js - Compiler
    • None

    Description

      Example: I define a basic service

      ```
      namespace js Auth

      service AuthSrv {
      string signin(
      1:string email,
      2:string password
      )
      }
      ```

      And set up a Auth es6 class that gonna handle the requests like this:

      ```
      module.exports = class AuthSrv {
      constructor()

      { this.db = ......... }

      async signin(email, password) {
      try

      { let user = await this.db.findOne(....) }

      ....
      }
      }
      ```

      and instantiate a thrift server like this:

      ```
      let server = thrift.createServer(AuthProcessor, new AuthSrv());
      ```

      In this scenario, i'm getting that this pointer is *undefined* when signin function is called. Looking at thrift generated code for the processor i saw this line:

      ```
      if (this._handler.signin.length === 2) {
      Q.fcall(this._handler.signin, args.email, args.password)
      .then(.....)
      }
      ```

      If i change the fcall to:

      ```
      if (this._handler.signin.length === 2) {
      Q.fcall(this._handler.signin.bind(this._handler), args.email, args.password)
      .then(.....)
      }
      ```

      everything works like a charm and this pointer is correctly assinged inside signin function call.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            brunomacf Bruno Fonseca
            brunomacf Bruno Fonseca
            Votes:
            0 Vote for this issue
            Watchers:
            3 Stop watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment