[
https://issues.apache.org/jira/browse/THRIFT-2939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14272887#comment-14272887
]
ASF GitHub Bot commented on THRIFT-2939:
----------------------------------------
GitHub user radekg opened a pull request:
https://github.com/apache/thrift/pull/353
THRIFT-2939: Js on par with nodejs
The generated code for regular JS differs from NodeJS code. NodeJS uses
direct return values from `read<Type>()` while regular JS code expects a value
from `read<Type>()` to be an object with `.value` property.
This makes it impossible to share generated code between browser JS and
NodeJS. The fix is rather simple:
- do not append `.value` in generated code while accessing values read from
protocol / transport
- do not return an object with the value property from read, return result
read
I am not sure why such difference. Both environment implementations take an
input, which is a protocol, and execute the same read methods. There is no need
to have an additional complexity in regular JS.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/radekg/thrift js-on-par-with-nodejs
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/353.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 #353
----
commit 8c94a6e62690a87cb2150bb07d21708fd7941e46
Author: radekg <[email protected]>
Date: 2015-01-01T19:35:01Z
Initialise tpos and tstack in the Protocol constructor so writing to a
protocol without a message does not fail.
commit 4cfe690bc0d0bde0eab01212d5cffb636afa19b0
Author: radekg <[email protected]>
Date: 2015-01-11T10:51:40Z
Merge remote-tracking branch 'upstream/master'
commit a8e5b1c73de2b90044b7dac5ec004867eada2ab4
Author: radekg <[email protected]>
Date: 2015-01-11T12:25:08Z
Make the generated JS code on par with nodejs - no .value in generated code
and simple types returned from appropriate read. Makes the generated code
portable.
----
> JavaScript generated code for Node and browser is different
> -----------------------------------------------------------
>
> Key: THRIFT-2939
> URL: https://issues.apache.org/jira/browse/THRIFT-2939
> Project: Thrift
> Issue Type: Improvement
> Components: JavaScript - Compiler, JavaScript - Library
> Affects Versions: 0.9.2
> Reporter: Radoslaw Gruchalski
> Labels: javascript, patch
>
> The generated code for regular JS differs from NodeJS code. NodeJS uses
> direct return values from {{read<Type>()}} while regular JS code expects a
> value from {{read<Type>()}} to be an object with {{.value}} property.
> This makes it impossible to share generated code between browser JS and
> NodeJS. The fix is rather simple:
> - do not append {{.value}} in generated code while accessing values read from
> protocol / transport
> - do not return an object with the value property from {{read}}, return
> result read
> I am not sure why such difference. Both environment implementations take an
> input, which is a protocol, and execute the same read methods. There is no
> need to have an additional complexity in regular JS.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)