@@ -24,7 +24,7 @@ module Koa {
24
24
25
25
HeaderDefinition ( ) {
26
26
// ctx.set('Cache-Control', 'no-cache');
27
- this .calls ( rh .getAResponseOrContextExpr ( ) . flow ( ) , "set" )
27
+ this .calls ( rh .getAResponseOrContextNode ( ) , "set" )
28
28
or
29
29
// ctx.response.header('Cache-Control', 'no-cache')
30
30
this .calls ( rh .getAResponseNode ( ) , "header" )
@@ -40,10 +40,17 @@ module Koa {
40
40
/**
41
41
* Gets the parameter of the route handler that contains the context object.
42
42
*/
43
- Parameter getContextParameter ( ) {
44
- result = this .getAFunctionValue ( ) .getFunction ( ) . getParameter ( 0 )
43
+ DataFlow :: ParameterNode getContextParameter ( ) {
44
+ result = this .getAFunctionValue ( ) .getParameter ( 0 )
45
45
}
46
46
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
+
47
54
/**
48
55
* Gets an expression that contains the "context" object of
49
56
* a route handler invocation.
@@ -52,26 +59,42 @@ module Koa {
52
59
* `this` or `ctx`, given as the first and only argument to the
53
60
* route handler.
54
61
*/
55
- Expr getAContextExpr ( ) { result .( ContextExpr ) .getRouteHandler ( ) = this }
62
+ DataFlow :: Node getAContextNode ( ) { result .( ContextNode ) .getRouteHandler ( ) = this }
56
63
57
64
/**
65
+ * DEPRECATED: Use `getAResponseOrContextNode` instead.
58
66
* Gets an expression that contains the context or response
59
67
* object of a route handler invocation.
60
68
*/
61
- Expr getAResponseOrContextExpr ( ) {
62
- // TODO: DataFlow::Node
69
+ deprecated Expr getAResponseOrContextExpr ( ) {
63
70
result = this .getAResponseNode ( ) .asExpr ( ) or result = this .getAContextExpr ( )
64
71
}
65
72
66
73
/**
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.
67
83
* Gets an expression that contains the context or request
68
84
* object of a route handler invocation.
69
85
*/
70
- Expr getARequestOrContextExpr ( ) {
71
- // TODO: DataFlow::Node
86
+ deprecated Expr getARequestOrContextExpr ( ) {
72
87
result = this .getARequestNode ( ) .asExpr ( ) or result = this .getAContextExpr ( )
73
88
}
74
89
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
+
75
98
/**
76
99
* Gets a reference to a request parameter defined by this route handler.
77
100
*/
@@ -110,7 +133,7 @@ module Koa {
110
133
RouteHandler rh ;
111
134
112
135
ContextSource ( ) {
113
- this = DataFlow :: parameterNode ( rh .getContextParameter ( ) )
136
+ this = rh .getContextParameter ( )
114
137
or
115
138
this .( DataFlow:: ThisNode ) .getBinder ( ) = rh
116
139
}
@@ -206,10 +229,10 @@ module Koa {
206
229
* A Koa request source, that is, an access to the `request` property
207
230
* of a context object.
208
231
*/
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 ;
211
234
212
- RequestSource ( ) { this . asExpr ( ) . ( PropAccess ) .accesses ( ctx , "request" ) }
235
+ RequestSource ( ) { super .accesses ( ctx , "request" ) }
213
236
214
237
/**
215
238
* Gets the route handler that provides this response.
@@ -241,24 +264,37 @@ module Koa {
241
264
* A Koa response source, that is, an access to the `response` property
242
265
* of a context object.
243
266
*/
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 ;
246
269
247
- ResponseSource ( ) { this . asExpr ( ) . ( PropAccess ) .accesses ( ctx , "response" ) }
270
+ ResponseSource ( ) { super .accesses ( ctx , "response" ) }
248
271
249
272
/**
250
273
* Gets the route handler that provides this response.
251
274
*/
252
275
override RouteHandler getRouteHandler ( ) { result = ctx .getRouteHandler ( ) }
253
276
}
254
277
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
+
255
291
/**
256
292
* An expression that may hold a Koa context object.
257
293
*/
258
- class ContextExpr extends Expr {
294
+ class ContextNode extends DataFlow :: Node {
259
295
ContextSource src ;
260
296
261
- ContextExpr ( ) { src .ref ( ) .flowsTo ( DataFlow :: valueNode ( this ) ) }
297
+ ContextNode ( ) { src .ref ( ) .flowsTo ( this ) }
262
298
263
299
/**
264
300
* Gets the route handler that provides this response.
@@ -310,11 +346,11 @@ module Koa {
310
346
kind = "parameter" and
311
347
this = rh .getARequestParameterAccess ( )
312
348
or
313
- exists ( Expr e | rh .getARequestOrContextExpr ( ) = e |
349
+ exists ( DataFlow :: Node e | rh .getARequestOrContextNode ( ) = e |
314
350
// `ctx.request.url`, `ctx.request.originalUrl`, or `ctx.request.href`
315
351
exists ( string propName |
316
352
kind = "url" and
317
- this .asExpr ( ) . ( PropAccess ) .accesses ( e , propName )
353
+ this .( DataFlow :: PropRead ) .accesses ( e , propName )
318
354
|
319
355
propName = "url"
320
356
or
@@ -325,19 +361,19 @@ module Koa {
325
361
or
326
362
// params, when handler is registered by `koa-router` or similar.
327
363
kind = "parameter" and
328
- this .asExpr ( ) . ( PropAccess ) .accesses ( e , "params" )
364
+ this .( DataFlow :: PropRead ) .accesses ( e , "params" )
329
365
or
330
366
// `ctx.request.body`
331
- e . flow ( ) instanceof RequestNode and
367
+ e instanceof RequestNode and
332
368
kind = "body" and
333
- this .asExpr ( ) . ( PropAccess ) .accesses ( e , "body" )
369
+ this .( DataFlow :: PropRead ) .accesses ( e , "body" )
334
370
or
335
371
// `ctx.cookies.get(<name>)`
336
- exists ( PropAccess cookies |
337
- e instanceof ContextExpr and
372
+ exists ( DataFlow :: PropRead cookies |
373
+ e instanceof ContextNode and
338
374
kind = "cookie" and
339
375
cookies .accesses ( e , "cookies" ) and
340
- this = cookies .flow ( ) . ( DataFlow :: SourceNode ) . getAMethodCall ( "get" )
376
+ this = cookies .getAMethodCall ( "get" )
341
377
)
342
378
or
343
379
exists ( RequestHeaderAccess access | access = this |
@@ -356,9 +392,9 @@ module Koa {
356
392
357
393
private DataFlow:: Node getAQueryParameterAccess ( RouteHandler rh ) {
358
394
// `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 ( )
362
398
)
363
399
}
364
400
@@ -369,18 +405,18 @@ module Koa {
369
405
RouteHandler rh ;
370
406
371
407
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 |
374
410
// `ctx.request.header.<name>`, `ctx.request.headers.<name>`
375
411
headers .accesses ( e , propName ) and
376
- this = headers .flow ( ) . ( DataFlow :: SourceNode ) . getAPropertyRead ( )
412
+ this = headers .getAPropertyRead ( )
377
413
|
378
414
propName = "header" or
379
415
propName = "headers"
380
416
)
381
417
or
382
418
// `ctx.request.get(<name>)`
383
- this .asExpr ( ) . ( MethodCallExpr ) .calls ( e , "get" )
419
+ this .( DataFlow :: MethodCallNode ) .calls ( e , "get" )
384
420
)
385
421
}
386
422
@@ -427,9 +463,7 @@ module Koa {
427
463
RouteHandler rh ;
428
464
429
465
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 ) )
433
467
}
434
468
435
469
override RouteHandler getRouteHandler ( ) { result = rh }
@@ -438,12 +472,10 @@ module Koa {
438
472
/**
439
473
* An invocation of the `redirect` method of an HTTP response object.
440
474
*/
441
- private class RedirectInvocation extends HTTP:: RedirectInvocation , DataFlow:: MethodCallNode {
475
+ private class RedirectInvocation extends HTTP:: RedirectInvocation instanceof DataFlow:: MethodCallNode {
442
476
RouteHandler rh ;
443
477
444
- RedirectInvocation ( ) {
445
- this .asExpr ( ) .( MethodCallExpr ) .calls ( rh .getAResponseOrContextExpr ( ) , "redirect" )
446
- } // TODO: Improve this.
478
+ RedirectInvocation ( ) { super .calls ( rh .getAResponseOrContextNode ( ) , "redirect" ) }
447
479
448
480
override DataFlow:: Node getUrlArgument ( ) { result = this .getArgument ( 0 ) }
449
481
0 commit comments