wala / JS_WALA

WALA analyses and tools that are implemented in JavaScript
Eclipse Public License 1.0
82 stars 11 forks source link

Handle node.js module scope #2

Open msridhar opened 10 years ago

msridhar commented 10 years ago

Consider normalizing the following node.js code:

var fs = require("fs");

The normalized code tries to read require from the global object, but in node, require is declared in the so-called "module" scope. Hence, the normalized code fails with a ReferenceError. I wonder if we can handle this?

msridhar commented 10 years ago

@xiemaisi any thoughts?

msridhar commented 10 years ago

One thought: it looks like module, which refers to the current module object, is a property of the global object in node. So maybe we could special-case accesses to certain "global" variables known to be properties of module, like require, and rewrite those as accessing properties of __global['module']?

xiemaisi commented 10 years ago

I haven't looked into normalising node.js code yet. As you suggest, the rewriting of global variable references would have to be changed to take module into account, but I'm unclear about the details.