-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstatic.js
47 lines (37 loc) · 1.13 KB
/
static.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
static
Static analysis algorithm for the 'hybrid' JDCE tool.
Statically analyze the source, then returns a list of functions to remove.
Static analysis tool copied & adapted from https://github.com/abort/javascript-call-graph
*/
const Graph = require('../graph'),
GraphTools = require('../graph_tools'),
static_analyzer = require('./static/static');
module.exports = function()
{
this.run = function(settings, callback)
{
let called_functions = static_analyzer(settings.scripts, settings.html_file);
// called_functions contains an array with the following object:
// {caller: {file, start, end}, called: {file, start, end} }
called_functions.forEach(function(funcs)
{
try
{
let called = GraphTools.find_node(funcs.called, settings.nodes)
if( funcs.caller.start == null && funcs.caller.end == null )
{
caller = settings.base_node;
}else{
caller = GraphTools.find_node(funcs.caller, settings.nodes);
}
GraphTools.mark( caller, called, settings.fingerprint );
}catch(e)
{
settings.error_handler('static', e);
callback(false);
}
});
callback(true);
};
};