You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by brunomacf <gi...@git.apache.org> on 2016/12/20 13:39:24 UTC

[GitHub] thrift pull request #1143: THRIFT-4010 Q.fcall messing up with *this* pointe...

GitHub user brunomacf opened a pull request:

    https://github.com/apache/thrift/pull/1143

    THRIFT-4010 Q.fcall messing up with *this* pointer inside called func\u2026

    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.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nosebit/thrift THRIFT-4010

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/1143.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1143
    
----
commit 32a456b25c77f0be41df679834a2ec1ce2420d65
Author: Bruno Fonseca <br...@gmail.com>
Date:   2016-12-20T13:19:43Z

    THRIFT-4010 Q.fcall messing up with *this* pointer inside called function
    Client: js
    Patch: Bruno Fonseca

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request #1143: THRIFT-4010 Q.fcall messing up with *this* pointe...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/thrift/pull/1143


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---