You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/language/learn-ql/javascript/introduce-libraries-js.rst
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -682,28 +682,28 @@ You can add custom type inference rules by defining new subclasses of ``DataFlow
682
682
Call graph
683
683
~~~~~~~~~~
684
684
685
-
The library ``semmle.javascript.dataflow.CallGraph`` implements a simple `call graph <http://en.wikipedia.org/wiki/Call_graph>`__ construction algorithm to statically approximate the possible call targets of function calls and ``new`` expressions. Due to the dynamically typed nature of JavaScript and its support for higher-order functions and reflective language features, building static call graphs is quite difficult. Simple call graph algorithms tend to be incomplete, that is, they often fail to resolve all possible call targets. More sophisticated algorithms can suffer from the opposite problem of imprecision, that is, they may infer many spurious call targets.
685
+
The JavaScript library implements a simple `call graph <http://en.wikipedia.org/wiki/Call_graph>`__ construction algorithm to statically approximate the possible call targets of function calls and ``new`` expressions. Due to the dynamically typed nature of JavaScript and its support for higher-order functions and reflective language features, building static call graphs is quite difficult. Simple call graph algorithms tend to be incomplete, that is, they often fail to resolve all possible call targets. More sophisticated algorithms can suffer from the opposite problem of imprecision, that is, they may infer many spurious call targets.
686
686
687
-
The library provides a QL class `CallSite<https://help.semmle.com/qldoc/javascript/semmle/javascript/dataflow/CallGraph.qll/type.CallGraph$CallSite.html>`__, which extends `InvokeExpr <https://help.semmle.com/qldoc/javascript/semmle/javascript/Expr.qll/type.Expr$InvokeExpr.html>`__ with a member predicate ``getACallee()`` that computes possible callees of the given call site, that is, functions that may at runtime be invoked by this expression.
687
+
The call graph is represented by the member predicate ``getACallee()`` of class `DataFlow::InvokeNode<https://help.semmle.com/qldoc/javascript/semmle/javascript/dataflow/Nodes.qll/type.Nodes$InvokeNode.html>`__, which computes possible callees of the given invocation, that is, functions that may at runtime be invoked by this expression.
688
688
689
-
Furthermore, there are three member predicates that indicate the quality of the callee information for this call site:
689
+
Furthermore, there are three member predicates that indicate the quality of the callee information for this invocation:
690
690
691
-
- ``CallSite.isImprecise()``: holds for call sites where the call graph builder might infer spurious call targets.
692
-
- ``CallSite.isIncomplete()``: holds for call sites where the call graph builder might fail to infer possible call targets.
693
-
- ``CallSite.isUncertain()``: holds if either ``isImprecise()`` or ``isUncertain()`` holds.
691
+
- ``DataFlow::InvokeNode.isImprecise()``: holds for invocations where the call graph builder might infer spurious call targets.
692
+
- ``DataFlow::InvokeNode.isIncomplete()``: holds for invocations where the call graph builder might fail to infer possible call targets.
693
+
- ``DataFlow::InvokeNode.isUncertain()``: holds if either ``isImprecise()`` or ``isUncertain()`` holds.
694
694
695
-
As an example of a call-graph-based query, here is a query to find call sites for which the call graph builder could not find any callees, despite the analysis being complete for this call site:
695
+
As an example of a call-graph-based query, here is a query to find invocations for which the call graph builder could not find any callees, despite the analysis being complete for this invocation:
696
696
697
697
.. code-block:: ql
698
698
699
699
import javascript
700
700
701
-
from CallSite cs
702
-
where not cs.isIncomplete() and
703
-
not exists(cs.getACallee())
704
-
select cs, "Unable to find a callee for this call site."
701
+
from DataFlow::InvokeNode invk
702
+
where not invk.isIncomplete() and
703
+
not exists(invk.getACallee())
704
+
select invk, "Unable to find a callee for this invocation."
705
705
706
-
➤ `See this in the query console <https://lgtm.com/query/1506065666123/>`__
706
+
➤ `See this in the query console <https://lgtm.com/query/3260345690335671362/>`__
707
707
708
708
Inter-procedural data flow
709
709
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1031,4 +1031,4 @@ What next?
1031
1031
1032
1032
- Learn about the QL standard libraries used to write queries for TypeScript in :doc:`Introducing the TypeScript libraries <introduce-libraries-ts>`.
1033
1033
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/ql-spec/language.html>`__.
1034
-
- Learn more about the query console in `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.
1034
+
- Learn more about the query console in `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.
0 commit comments