thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Geyer (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Deleted] (THRIFT-4174) js:jquery option generates broken code for async mode
Date Sat, 15 Apr 2017 22:19:42 GMT

     [ https://issues.apache.org/jira/browse/THRIFT-4174?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jens Geyer updated THRIFT-4174:
-------------------------------
    Comment: was deleted

(was: Workaround: Don't use the {{jquery}} option. Code works fine without it even if jQuery
is used.)

> 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);}},
hence the callback function is already lost at that stage. This value of {{true}} is then
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)

Mime
View raw message