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