You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2017/04/15 21:58:41 UTC

[jira] [Created] (THRIFT-4174) js:jquery option generates broken code for async mode

Jens Geyer created THRIFT-4174:
----------------------------------

             Summary: js:jquery option generates broken code for async mode
                 Key: THRIFT-4174
                 URL: https://issues.apache.org/jira/browse/THRIFT-4174
             Project: Thrift
          Issue Type: Bug
          Components: JavaScript - Compiler
            Reporter: Jens Geyer


The {{js:jquery}} option produces code that calls {{flush()}} in an incorect way which essentially prevents it from working. The code works fine in synchronous mode, but not when called with a callback.

{code}
SampleSvc.SampleClient.prototype.Bar = function(sText, callback) {
  if (callback === undefined) {
    this.send_Bar(sText);
    return this.recv_Bar();
  } else {
    var postData = this.send_Bar(sText, true);
    return this.output.getTransport()
      .jqRequest(this, postData, arguments, this.recv_Bar);
  }
};

SampleSvc.SampleClient.prototype.send_Bar = function(sText, callback) {
  this.output.writeMessageBegin('Bar', Thrift.MessageType.CALL, this.seqid);
  var args = new SampleSvc.Sample_Bar_args();
  args.sText = sText;
  args.write(this.output);
  this.output.writeMessageEnd();
  return this.output.getTransport().flush(callback);
};
{code}

Note that true instead of the callback func is passed to {{this.send_Bar(sText, true);}}. This value is the passed to {{return this.output.getTransport().flush(callback);}}. It get's even more wrong if we look at what flush() really expects: 

{code}
    /**
     * Sends the current XRH request if the transport was created with a URL 
     * and the async parameter is false. If the transport was not created with
     * a URL, or the async parameter is True and no callback is provided, or 
     * the URL is an empty string, the current send buffer is returned.
     * @param {object} async - If true the current send buffer is returned.
     * @param {object} callback - Optional async completion callback 
     * @returns {undefined|string} Nothing or the current send buffer.
     * @throws {string} If XHR fails.
     */
    flush: function(async, callback) {
        var self = this;
        if ((async && !callback) || this.url === undefined || this.url === '') {
            return this.send_buf;
        }

     // ... more code ...
{code}




--
This message was sent by Atlassian JIRA
(v6.3.15#6346)