@@ -298,6 +298,7 @@ module Express {
298
298
}
299
299
300
300
/**
301
+ * DEPRECATED: Use `RouteHandlerNode` instead.
301
302
* An expression used as an Express route handler, such as `submitHandler` below:
302
303
* ```
303
304
* app.post('/submit', submitHandler)
@@ -306,12 +307,56 @@ module Express {
306
307
* Unlike `RouterHandler`, this is the argument passed to a setup, as opposed to
307
308
* a function that flows into such an argument.
308
309
*/
309
- class RouteHandlerExpr extends Expr {
310
- // TODO: DataFlow::Node
310
+ deprecated class RouteHandlerExpr extends Expr {
311
+ RouteHandlerNode node ;
312
+
313
+ RouteHandlerExpr ( ) { this .flow ( ) = node }
314
+
315
+ /** Gets the setup call that registers this route handler. */
316
+ deprecated RouteSetup getSetup ( ) { result = node .getSetup ( ) }
317
+
318
+ /** Gets the function body of this handler, if it is defined locally. */
319
+ deprecated RouteHandler getBody ( ) { result = node .getBody ( ) }
320
+
321
+ /** Holds if this is not followed by more handlers. */
322
+ deprecated predicate isLastHandler ( ) { node .isLastHandler ( ) }
323
+
324
+ /** Gets a route handler that immediately precedes this in the route stack. */
325
+ deprecated Express:: RouteHandlerExpr getPreviousMiddleware ( ) {
326
+ result = node .getPreviousMiddleware ( ) .asExpr ( )
327
+ }
328
+
329
+ /** Gets a route handler that may follow immediately after this one in its route stack. */
330
+ deprecated Express:: RouteHandlerExpr getNextMiddleware ( ) {
331
+ result = node .getNextMiddleware ( ) .asExpr ( )
332
+ }
333
+
334
+ /**
335
+ * Gets a route handler that precedes this one (not necessarily immediately), may handle
336
+ * same request method, and matches on the same path or a prefix.
337
+ */
338
+ deprecated Express:: RouteHandlerExpr getAMatchingAncestor ( ) {
339
+ result = node .getAMatchingAncestor ( ) .asExpr ( )
340
+ }
341
+
342
+ /** Gets the router being registered as a sub-router here, if any. */
343
+ deprecated RouterDefinition getAsSubRouter ( ) { result = node .getAsSubRouter ( ) }
344
+ }
345
+
346
+ /**
347
+ * An expression used as an Express route handler, such as `submitHandler` below:
348
+ * ```
349
+ * app.post('/submit', submitHandler)
350
+ * ```
351
+ *
352
+ * Unlike `RouterHandler`, this is the argument passed to a setup, as opposed to
353
+ * a function that flows into such an argument.
354
+ */
355
+ class RouteHandlerNode extends DataFlow:: Node {
311
356
RouteSetup setup ;
312
357
int index ;
313
358
314
- RouteHandlerExpr ( ) { this = setup .getRouteHandlerNode ( index ) . asExpr ( ) }
359
+ RouteHandlerNode ( ) { this = setup .getRouteHandlerNode ( index ) }
315
360
316
361
/**
317
362
* Gets the setup call that registers this route handler.
@@ -322,7 +367,7 @@ module Express {
322
367
* Gets the function body of this handler, if it is defined locally.
323
368
*/
324
369
RouteHandler getBody ( ) {
325
- exists ( DataFlow:: SourceNode source | source = this .flow ( ) . getALocalSource ( ) |
370
+ exists ( DataFlow:: SourceNode source | source = this .getALocalSource ( ) |
326
371
result = source
327
372
or
328
373
DataFlow:: functionOneWayForwardingStep ( result .( DataFlow:: SourceNode ) .getALocalUse ( ) , source )
@@ -359,11 +404,11 @@ module Express {
359
404
* In this case, the previous from `foo` is `auth` although they do not act on the
360
405
* same requests.
361
406
*/
362
- Express:: RouteHandlerExpr getPreviousMiddleware ( ) {
407
+ Express:: RouteHandlerNode getPreviousMiddleware ( ) {
363
408
index = 0 and
364
409
result = setup .getRouter ( ) .getMiddlewareStackAt ( setup .asExpr ( ) .getAPredecessor ( ) )
365
410
or
366
- index > 0 and result = setup .getRouteHandlerNode ( index - 1 ) . asExpr ( )
411
+ index > 0 and result = setup .getRouteHandlerNode ( index - 1 )
367
412
or
368
413
// Outside the router's original container, use the flow-insensitive model of its middleware stack.
369
414
// Its state is not tracked to CFG nodes outside its original container.
@@ -377,7 +422,7 @@ module Express {
377
422
/**
378
423
* Gets a route handler that may follow immediately after this one in its route stack.
379
424
*/
380
- Express:: RouteHandlerExpr getNextMiddleware ( ) { result .getPreviousMiddleware ( ) = this }
425
+ Express:: RouteHandlerNode getNextMiddleware ( ) { result .getPreviousMiddleware ( ) = this }
381
426
382
427
/**
383
428
* Gets a route handler that precedes this one (not necessarily immediately), may handle
@@ -390,7 +435,7 @@ module Express {
390
435
* router installs a route handler `r1` on a path that matches the path of a route handler
391
436
* `r2` installed on a subrouter, `r1` will not be recognized as an ancestor of `r2`.
392
437
*/
393
- Express:: RouteHandlerExpr getAMatchingAncestor ( ) {
438
+ Express:: RouteHandlerNode getAMatchingAncestor ( ) {
394
439
result = this .getPreviousMiddleware + ( ) and
395
440
exists ( RouteSetup resSetup | resSetup = result .getSetup ( ) |
396
441
// check whether request methods are compatible
@@ -407,7 +452,7 @@ module Express {
407
452
or
408
453
// if this is a sub-router, any previously installed middleware for the same
409
454
// request method will necessarily match
410
- exists ( RouteHandlerExpr outer |
455
+ exists ( RouteHandlerNode outer |
411
456
setup .getRouter ( ) = outer .getAsSubRouter ( ) and
412
457
outer .getSetup ( ) .handlesSameRequestMethodAs ( setup ) and
413
458
result = outer .getAMatchingAncestor ( )
@@ -417,7 +462,7 @@ module Express {
417
462
/**
418
463
* Gets the router being registered as a sub-router here, if any.
419
464
*/
420
- RouterDefinition getAsSubRouter ( ) { isRouter ( this . flow ( ) , result ) }
465
+ RouterDefinition getAsSubRouter ( ) { isRouter ( this , result ) }
421
466
}
422
467
423
468
/**
@@ -934,22 +979,19 @@ module Express {
934
979
*
935
980
* If `node` is not in the same container where `router` was defined, the predicate has no result.
936
981
*/
937
- Express:: RouteHandlerExpr getMiddlewareStackAt ( ControlFlowNode node ) {
938
- // TODO: DataFlow::Node?
982
+ Express:: RouteHandlerNode getMiddlewareStackAt ( ControlFlowNode node ) {
939
983
if
940
984
exists ( Express:: RouteSetup setup | node = setup .asExpr ( ) and setup .getRouter ( ) = this |
941
985
setup .isUseCall ( )
942
986
)
943
- then
944
- result =
945
- node .( AST:: ValueNode ) .flow ( ) .( Express:: RouteSetup ) .getLastRouteHandlerNode ( ) .asExpr ( )
987
+ then result = node .( AST:: ValueNode ) .flow ( ) .( Express:: RouteSetup ) .getLastRouteHandlerNode ( )
946
988
else result = this .getMiddlewareStackAt ( node .getAPredecessor ( ) )
947
989
}
948
990
949
991
/**
950
992
* Gets the final middleware registered on this router.
951
993
*/
952
- Express:: RouteHandlerExpr getMiddlewareStack ( ) {
994
+ Express:: RouteHandlerNode getMiddlewareStack ( ) {
953
995
result = this .getMiddlewareStackAt ( this .getContainer ( ) .getExit ( ) )
954
996
}
955
997
}
0 commit comments