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 21:39:19 UTC
[jira] [Commented] (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=14098990#comment-14098990 ]
Chris Thompson commented on THRIFT-1840:
----------------------------------------
This issue still exists in the latest Git revision. A require of any thrift compiled library causes global scope pollution.
For example:
{code:javascript}
NotFoundException = module.exports.NotFoundException = function(args) {
Thrift.TException.call(this, "NotFoundException")
this.name = "NotFoundException"
this.message = null;
if (args) {
if (args.message !== undefined) {
this.message = args.message;
}
}
};
{code}
When this is required, it'll conflict with any existing "NotFoundException" variable and as a global it'll take precedence.
{code:javascript}
var NotFoundException = function () { console.log('not found!'); };
// NotFoundException();
// 'not found!'
var Service = require('./gen-nodejs/service_types');
// NotFoundException()
// undefined
{code}
Requiring the types library just hid my local variable.
I'm building an independent node module that exports functions to query a Thrift service. When the main application requires in my node module, the global namespace of the main application gets polluted also because my module required the thrift module.
A fix for the compiler to make sure that a 'var' keyword is added should be a very high priority and a very simple fix.
> 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
>
>
> 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)