Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5f29e0

Browse files
committed
JS: Simplify call graph metric
1 parent c8e5be7 commit c5f29e0

1 file changed

Lines changed: 1 addition & 126 deletions

File tree

javascript/ql/src/meta/analysis-quality/CallGraphQuality.qll

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -47,97 +47,6 @@ class RelevantFunction extends Function {
4747
}
4848
}
4949

50-
/**
51-
* Holds if `name` is a the name of an external module.
52-
*/
53-
predicate isExternalLibrary(string name) {
54-
// Mentioned in package.json
55-
any(Dependency dep).info(name, _) or
56-
// Node.js built-in
57-
name = "assert" or
58-
name = "async_hooks" or
59-
name = "child_process" or
60-
name = "cluster" or
61-
name = "crypto" or
62-
name = "dns" or
63-
name = "domain" or
64-
name = "events" or
65-
name = "fs" or
66-
name = "http" or
67-
name = "http2" or
68-
name = "https" or
69-
name = "inspector" or
70-
name = "net" or
71-
name = "os" or
72-
name = "path" or
73-
name = "perf_hooks" or
74-
name = "process" or
75-
name = "punycode" or
76-
name = "querystring" or
77-
name = "readline" or
78-
name = "repl" or
79-
name = "stream" or
80-
name = "string_decoder" or
81-
name = "timer" or
82-
name = "tls" or
83-
name = "trace_events" or
84-
name = "tty" or
85-
name = "dgram" or
86-
name = "url" or
87-
name = "util" or
88-
name = "v8" or
89-
name = "vm" or
90-
name = "worker_threads" or
91-
name = "zlib"
92-
}
93-
94-
/**
95-
* Holds if the global variable `name` is defined externally.
96-
*/
97-
predicate isExternalGlobal(string name) {
98-
exists(ExternalGlobalDecl decl | decl.getName() = name)
99-
or
100-
exists(Dependency dep |
101-
// If name is never assigned anywhere, and it coincides with a dependency,
102-
// it's most likely coming from there.
103-
dep.info(name, _) and
104-
not exists(Assignment assign | assign.getLhs().(GlobalVarAccess).getName() = name)
105-
)
106-
or
107-
name = "_"
108-
}
109-
110-
/**
111-
* Gets a node that was derived from an import of `moduleName`.
112-
*
113-
* This is a rough approximation as it follows all property reads, invocations,
114-
* and callbacks, so some of these might refer to internal objects.
115-
*
116-
* Additionally, we don't recognize when a project imports another file in the
117-
* same project using its module name (for example import "vscode" from inside the vscode project).
118-
*/
119-
SourceNode externalNode() {
120-
exists(string moduleName |
121-
result = moduleImport(moduleName) and
122-
isExternalLibrary(moduleName)
123-
)
124-
or
125-
exists(string name |
126-
result = globalVarRef(name) and
127-
isExternalGlobal(name)
128-
)
129-
or
130-
result = DOM::domValueRef()
131-
or
132-
result = jquery()
133-
or
134-
result = externalNode().getAPropertyRead()
135-
or
136-
result = externalNode().getAnInvocation()
137-
or
138-
result = externalNode().(InvokeNode).getCallback(_).getParameter(_)
139-
}
140-
14150
/**
14251
* Gets a data flow node that can be resolved to a function, usually a callback.
14352
*
@@ -192,49 +101,15 @@ class ResolvableCall extends RelevantInvoke {
192101
}
193102
}
194103

195-
/**
196-
* A call site that is believed to call an external function.
197-
*/
198-
class ExternalCall extends RelevantInvoke {
199-
ExternalCall() {
200-
not this instanceof ResolvableCall and // avoid double counting
201-
(
202-
// Call to modelled external library
203-
this = externalNode()
204-
or
205-
// 'require' call or similar
206-
this = moduleImport(_)
207-
or
208-
// Resolved to externs file
209-
exists(this.(InvokeNode).getACallee(1))
210-
or
211-
// Modelled as taint step but isn't from an NPM module, for example, `substring` or `push`.
212-
exists(TaintTracking::AdditionalTaintStep step |
213-
step.step(_, this)
214-
or
215-
step.step(this.getAnArgument(), _)
216-
)
217-
)
218-
}
219-
}
220-
221104
/**
222105
* A call site that could not be resolved.
223106
*/
224107
class UnresolvableCall extends RelevantInvoke {
225108
UnresolvableCall() {
226-
not this instanceof ResolvableCall and
227-
not this instanceof ExternalCall
109+
not this instanceof ResolvableCall
228110
}
229111
}
230112

231-
/**
232-
* A call that is believed to call a function within the same project.
233-
*/
234-
class NonExternalCall extends RelevantInvoke {
235-
NonExternalCall() { not this instanceof ExternalCall }
236-
}
237-
238113
/**
239114
* A function with at least one call site.
240115
*/

0 commit comments

Comments
 (0)