@@ -24,7 +24,7 @@ module Koa {
2424
2525 HeaderDefinition ( ) {
2626 // ctx.set('Cache-Control', 'no-cache');
27- this .calls ( rh .getAResponseOrContextExpr ( ) . flow ( ) , "set" )
27+ this .calls ( rh .getAResponseOrContextNode ( ) , "set" )
2828 or
2929 // ctx.response.header('Cache-Control', 'no-cache')
3030 this .calls ( rh .getAResponseNode ( ) , "header" )
@@ -40,10 +40,17 @@ module Koa {
4040 /**
4141 * Gets the parameter of the route handler that contains the context object.
4242 */
43- Parameter getContextParameter ( ) {
44- result = this .getAFunctionValue ( ) .getFunction ( ) . getParameter ( 0 )
43+ DataFlow :: ParameterNode getContextParameter ( ) {
44+ result = this .getAFunctionValue ( ) .getParameter ( 0 )
4545 }
4646
47+ /**
48+ * DEPRECATED: Use `getAContextNode` instead.
49+ * Gets an expression that contains the "context" object of
50+ * a route handler invocation.
51+ */
52+ deprecated Expr getAContextExpr ( ) { result .( ContextExpr ) .getRouteHandler ( ) = this }
53+
4754 /**
4855 * Gets an expression that contains the "context" object of
4956 * a route handler invocation.
@@ -52,26 +59,42 @@ module Koa {
5259 * `this` or `ctx`, given as the first and only argument to the
5360 * route handler.
5461 */
55- Expr getAContextExpr ( ) { result .( ContextExpr ) .getRouteHandler ( ) = this }
62+ DataFlow :: Node getAContextNode ( ) { result .( ContextNode ) .getRouteHandler ( ) = this }
5663
5764 /**
65+ * DEPRECATED: Use `getAResponseOrContextNode` instead.
5866 * Gets an expression that contains the context or response
5967 * object of a route handler invocation.
6068 */
61- Expr getAResponseOrContextExpr ( ) {
62- // TODO: DataFlow::Node
69+ deprecated Expr getAResponseOrContextExpr ( ) {
6370 result = this .getAResponseNode ( ) .asExpr ( ) or result = this .getAContextExpr ( )
6471 }
6572
6673 /**
74+ * Gets an expression that contains the context or response
75+ * object of a route handler invocation.
76+ */
77+ DataFlow:: Node getAResponseOrContextNode ( ) {
78+ result = this .getAResponseNode ( ) or result = this .getAContextNode ( )
79+ }
80+
81+ /**
82+ * DEPRECATED: Use `getARequestOrContextNode` instead.
6783 * Gets an expression that contains the context or request
6884 * object of a route handler invocation.
6985 */
70- Expr getARequestOrContextExpr ( ) {
71- // TODO: DataFlow::Node
86+ deprecated Expr getARequestOrContextExpr ( ) {
7287 result = this .getARequestNode ( ) .asExpr ( ) or result = this .getAContextExpr ( )
7388 }
7489
90+ /**
91+ * Gets an expression that contains the context or request
92+ * object of a route handler invocation.
93+ */
94+ DataFlow:: Node getARequestOrContextNode ( ) {
95+ result = this .getARequestNode ( ) or result = this .getAContextNode ( )
96+ }
97+
7598 /**
7699 * Gets a reference to a request parameter defined by this route handler.
77100 */
@@ -110,7 +133,7 @@ module Koa {
110133 RouteHandler rh ;
111134
112135 ContextSource ( ) {
113- this = DataFlow :: parameterNode ( rh .getContextParameter ( ) )
136+ this = rh .getContextParameter ( )
114137 or
115138 this .( DataFlow:: ThisNode ) .getBinder ( ) = rh
116139 }
@@ -206,10 +229,10 @@ module Koa {
206229 * A Koa request source, that is, an access to the `request` property
207230 * of a context object.
208231 */
209- private class RequestSource extends HTTP:: Servers:: RequestSource {
210- ContextExpr ctx ;
232+ private class RequestSource extends HTTP:: Servers:: RequestSource instanceof DataFlow :: PropRead {
233+ ContextNode ctx ;
211234
212- RequestSource ( ) { this . asExpr ( ) . ( PropAccess ) .accesses ( ctx , "request" ) }
235+ RequestSource ( ) { super .accesses ( ctx , "request" ) }
213236
214237 /**
215238 * Gets the route handler that provides this response.
@@ -241,24 +264,37 @@ module Koa {
241264 * A Koa response source, that is, an access to the `response` property
242265 * of a context object.
243266 */
244- private class ResponseSource extends HTTP:: Servers:: ResponseSource {
245- ContextExpr ctx ;
267+ private class ResponseSource extends HTTP:: Servers:: ResponseSource instanceof DataFlow :: PropRead {
268+ ContextNode ctx ;
246269
247- ResponseSource ( ) { this . asExpr ( ) . ( PropAccess ) .accesses ( ctx , "response" ) }
270+ ResponseSource ( ) { super .accesses ( ctx , "response" ) }
248271
249272 /**
250273 * Gets the route handler that provides this response.
251274 */
252275 override RouteHandler getRouteHandler ( ) { result = ctx .getRouteHandler ( ) }
253276 }
254277
278+ /**
279+ * DEPRECATED: Use `ContextNode` instead.
280+ * An expression that may hold a Koa context object.
281+ */
282+ deprecated class ContextExpr extends Expr {
283+ ContextNode node ;
284+
285+ ContextExpr ( ) { node .asExpr ( ) = this }
286+
287+ /** Gets the route handler that provides this response. */
288+ deprecated RouteHandler getRouteHandler ( ) { result = node .getRouteHandler ( ) }
289+ }
290+
255291 /**
256292 * An expression that may hold a Koa context object.
257293 */
258- class ContextExpr extends Expr {
294+ class ContextNode extends DataFlow :: Node {
259295 ContextSource src ;
260296
261- ContextExpr ( ) { src .ref ( ) .flowsTo ( DataFlow :: valueNode ( this ) ) }
297+ ContextNode ( ) { src .ref ( ) .flowsTo ( this ) }
262298
263299 /**
264300 * Gets the route handler that provides this response.
@@ -310,11 +346,11 @@ module Koa {
310346 kind = "parameter" and
311347 this = rh .getARequestParameterAccess ( )
312348 or
313- exists ( Expr e | rh .getARequestOrContextExpr ( ) = e |
349+ exists ( DataFlow :: Node e | rh .getARequestOrContextNode ( ) = e |
314350 // `ctx.request.url`, `ctx.request.originalUrl`, or `ctx.request.href`
315351 exists ( string propName |
316352 kind = "url" and
317- this .asExpr ( ) . ( PropAccess ) .accesses ( e , propName )
353+ this .( DataFlow :: PropRead ) .accesses ( e , propName )
318354 |
319355 propName = "url"
320356 or
@@ -325,19 +361,19 @@ module Koa {
325361 or
326362 // params, when handler is registered by `koa-router` or similar.
327363 kind = "parameter" and
328- this .asExpr ( ) . ( PropAccess ) .accesses ( e , "params" )
364+ this .( DataFlow :: PropRead ) .accesses ( e , "params" )
329365 or
330366 // `ctx.request.body`
331- e . flow ( ) instanceof RequestNode and
367+ e instanceof RequestNode and
332368 kind = "body" and
333- this .asExpr ( ) . ( PropAccess ) .accesses ( e , "body" )
369+ this .( DataFlow :: PropRead ) .accesses ( e , "body" )
334370 or
335371 // `ctx.cookies.get(<name>)`
336- exists ( PropAccess cookies |
337- e instanceof ContextExpr and
372+ exists ( DataFlow :: PropRead cookies |
373+ e instanceof ContextNode and
338374 kind = "cookie" and
339375 cookies .accesses ( e , "cookies" ) and
340- this = cookies .flow ( ) . ( DataFlow :: SourceNode ) . getAMethodCall ( "get" )
376+ this = cookies .getAMethodCall ( "get" )
341377 )
342378 or
343379 exists ( RequestHeaderAccess access | access = this |
@@ -356,9 +392,9 @@ module Koa {
356392
357393 private DataFlow:: Node getAQueryParameterAccess ( RouteHandler rh ) {
358394 // `ctx.query.name` or `ctx.request.query.name`
359- exists ( PropAccess q |
360- q .accesses ( rh .getARequestOrContextExpr ( ) , "query" ) and
361- result = q .flow ( ) . ( DataFlow :: SourceNode ) . getAPropertyRead ( )
395+ exists ( DataFlow :: PropRead q |
396+ q .accesses ( rh .getARequestOrContextNode ( ) , "query" ) and
397+ result = q .getAPropertyRead ( )
362398 )
363399 }
364400
@@ -369,18 +405,18 @@ module Koa {
369405 RouteHandler rh ;
370406
371407 RequestHeaderAccess ( ) {
372- exists ( Expr e | e = rh .getARequestOrContextExpr ( ) |
373- exists ( string propName , PropAccess headers |
408+ exists ( DataFlow :: Node e | e = rh .getARequestOrContextNode ( ) |
409+ exists ( string propName , DataFlow :: PropRead headers |
374410 // `ctx.request.header.<name>`, `ctx.request.headers.<name>`
375411 headers .accesses ( e , propName ) and
376- this = headers .flow ( ) . ( DataFlow :: SourceNode ) . getAPropertyRead ( )
412+ this = headers .getAPropertyRead ( )
377413 |
378414 propName = "header" or
379415 propName = "headers"
380416 )
381417 or
382418 // `ctx.request.get(<name>)`
383- this .asExpr ( ) . ( MethodCallExpr ) .calls ( e , "get" )
419+ this .( DataFlow :: MethodCallNode ) .calls ( e , "get" )
384420 )
385421 }
386422
@@ -427,9 +463,7 @@ module Koa {
427463 RouteHandler rh ;
428464
429465 ResponseSendArgument ( ) {
430- exists ( DataFlow:: PropWrite pwn |
431- pwn .writes ( DataFlow:: valueNode ( rh .getAResponseOrContextExpr ( ) ) , "body" , this )
432- )
466+ exists ( DataFlow:: PropWrite pwn | pwn .writes ( rh .getAResponseOrContextNode ( ) , "body" , this ) )
433467 }
434468
435469 override RouteHandler getRouteHandler ( ) { result = rh }
@@ -438,12 +472,10 @@ module Koa {
438472 /**
439473 * An invocation of the `redirect` method of an HTTP response object.
440474 */
441- private class RedirectInvocation extends HTTP:: RedirectInvocation , DataFlow:: MethodCallNode {
475+ private class RedirectInvocation extends HTTP:: RedirectInvocation instanceof DataFlow:: MethodCallNode {
442476 RouteHandler rh ;
443477
444- RedirectInvocation ( ) {
445- this .asExpr ( ) .( MethodCallExpr ) .calls ( rh .getAResponseOrContextExpr ( ) , "redirect" )
446- } // TODO: Improve this.
478+ RedirectInvocation ( ) { super .calls ( rh .getAResponseOrContextNode ( ) , "redirect" ) }
447479
448480 override DataFlow:: Node getUrlArgument ( ) { result = this .getArgument ( 0 ) }
449481
0 commit comments