[ 
https://issues.apache.org/jira/browse/THRIFT-4010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15764231#comment-15764231
 ] 

ASF GitHub Bot commented on THRIFT-4010:
----------------------------------------

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…

    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 <[email protected]>
Date:   2016-12-20T13:19:43Z

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

----


> Q.fcall messing up with *this* pointer inside called function
> -------------------------------------------------------------
>
>                 Key: THRIFT-4010
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4010
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Compiler
>    Affects Versions: 0.9.3
>            Reporter: Bruno Fonseca
>             Fix For: 0.10.0
>
>
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to