thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (THRIFT-4403) thrift.js: Incorrect usage of 'this' in TWebSocketTransport.__onOpen
Date Mon, 04 Dec 2017 14:51:00 GMT


ASF GitHub Bot commented on THRIFT-4403:

Github user bananer commented on a diff in the pull request:
    --- Diff: lib/js/src/thrift.js ---
    @@ -599,8 +599,8 @@ Thrift.TWebSocketTransport.prototype = {
               //If the user made calls before the connection was fully
               //open, send them now
               this.send_pending.forEach(function(elem) {
    -             this.socket.send(elem.buf);
    -             this.callbacks.push((function() {
    +             self.socket.send(elem.buf);
    --- End diff --
    In short, `this` inside of a `function()` in JavaScript is not transferred reliably from
outer scopes. Try setting a breakpoint at this line and you will see that `self` and `this`
are different things here.
    It's a bit of a race condition to have this block actually execute, but calling a service
method right after opening the transport crashed here repeatedly in firefox.
    Long version:

> thrift.js: Incorrect usage of 'this' in TWebSocketTransport.__onOpen
> --------------------------------------------------------------------
>                 Key: THRIFT-4403
>                 URL:
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Library
>            Reporter: Philip Frank
> Inside the forEach callback 'this' will be the global object, not the transport object,
as the implementation seems to assume.

This message was sent by Atlassian JIRA

View raw message