Skip to content

Commit 20cae30

Browse files
authored
Merge pull request github#3054 from erik-krogh/NoDeferred
Approved by asgerf
2 parents 4d6aa20 + 799c3eb commit 20cae30

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

javascript/ql/src/Statements/UseOfReturnlessFunction.ql

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ predicate benignContext(Expr e) {
7272
or
7373
// arguments to Promise.resolve (and promise library variants) are benign.
7474
e = any(PromiseCreationCall promise).getValue().asExpr()
75+
or
76+
// arguments to other (unknown) promise creations.
77+
e = any(DataFlow::CallNode call | call.getCalleeName() = "resolve").getAnArgument().asExpr()
7578
}
7679

7780
predicate oneshotClosure(DataFlow::CallNode call) {
@@ -153,56 +156,6 @@ predicate hasNonVoidReturnType(Function f) {
153156
exists(TypeAnnotation type | type = f.getReturnTypeAnnotation() | not type.isVoid())
154157
}
155158

156-
/**
157-
* Provides classes for working with various Deferred implementations.
158-
* It is a heuristic. The heuristic assume that a class is a promise defintion
159-
* if the class is called "Deferred" and the method `resolve` is called on an instance.
160-
*
161-
* Removes some false positives in the js/use-of-returnless-function query.
162-
*/
163-
module Deferred {
164-
/**
165-
* An instance of a `Deferred` class.
166-
* For example the result from `new Deferred()` or `new $.Deferred()`.
167-
*/
168-
class DeferredInstance extends DataFlow::NewNode {
169-
// Describes both `new Deferred()`, `new $.Deferred` and other variants.
170-
DeferredInstance() { this.getCalleeName() = "Deferred" }
171-
172-
private DataFlow::SourceNode ref(DataFlow::TypeTracker t) {
173-
t.start() and
174-
result = this
175-
or
176-
exists(DataFlow::TypeTracker t2 | result = ref(t2).track(t2, t))
177-
}
178-
179-
DataFlow::SourceNode ref() { result = ref(DataFlow::TypeTracker::end()) }
180-
}
181-
182-
/**
183-
* A promise object created by a Deferred constructor
184-
*/
185-
private class DeferredPromiseDefinition extends PromiseDefinition, DeferredInstance {
186-
DeferredPromiseDefinition() {
187-
// hardening of the "Deferred" heuristic: a method call to `resolve`.
188-
exists(ref().getAMethodCall("resolve"))
189-
}
190-
191-
override DataFlow::FunctionNode getExecutor() { result = getCallback(0) }
192-
}
193-
194-
/**
195-
* A resolved promise created by a `new Deferred().resolve()` call.
196-
*/
197-
class ResolvedDeferredPromiseDefinition extends PromiseCreationCall {
198-
ResolvedDeferredPromiseDefinition() {
199-
this = any(DeferredPromiseDefinition def).ref().getAMethodCall("resolve")
200-
}
201-
202-
override DataFlow::Node getValue() { result = getArgument(0) }
203-
}
204-
}
205-
206159
from DataFlow::CallNode call, Function func, string name, string msg
207160
where
208161
(

0 commit comments

Comments
 (0)