You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Chris Thompson (JIRA)" <ji...@apache.org> on 2014/08/15 23:43:19 UTC

[jira] [Comment Edited] (THRIFT-1840) Thrift Generated Code Causes Global Variable Leaks

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

Chris Thompson edited comment on THRIFT-1840 at 8/15/14 9:43 PM:
-----------------------------------------------------------------

For anyone else that runs into this issue, I attached a "fix_globals.js" node app that'll look in your gen-nodejs directory and insert 'var ' statements and add "use strict" to the top to notify you of any other bad behavior.

Note that by adding the var statements, if a thrift file requires in dependencies like this:

{code:javascript}
var common_ttypes = require('./common_types')
{code}

Those types won't be exposed globally anymore like they used to be, so you'll have to manually require the types that you need to use (as it should be).


was (Author: chris.thompson):
For anyone else that runs into this issue, this is a quick node hack that'll look in your gen-nodejs directory and insert 'var ' statements and add "use strict" to the top to notify you of any other bad behavior.

Note that by adding the var statements, if a thrift file requires in dependencies like this:

var common_ttypes = require('./common_types')

Those types won't be exposed globally anymore like they used to be, so you'll have to manually require the types that you need to use (as it should be).

> Thrift Generated Code Causes Global Variable Leaks
> --------------------------------------------------
>
>                 Key: THRIFT-1840
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1840
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Compiler
>    Affects Versions: 0.9
>            Reporter: Russell Bradberry
>              Labels: javascript, node
>         Attachments: 0001-THRIFT-1840-fix-for-global-variable-leak.patch, fix_globals.js
>
>
> When compiling for NodeJS, the compiler creates globally scoped variables which is considered a bad practice as it can create unintended consequences. It also causes many testing frameworks to fail.
> the output looks something like this:
> {code}
> User = module.exports.User = function(args) {
> {code}
> when it should be
> {code}
> var User = module.exports.User = function(args) {
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)