|
1 | 1 | import javascript |
2 | 2 | private import semmle.javascript.dataflow.TypeTracking |
| 3 | +private import semmle.javascript.internal.CachedStages |
3 | 4 | private import FlowSteps |
4 | 5 |
|
5 | | -class PropertyName extends string { |
6 | | - PropertyName() { |
7 | | - this = any(DataFlow::PropRef pr).getPropertyName() |
8 | | - or |
9 | | - AccessPath::isAssignedInUniqueFile(this) |
10 | | - or |
11 | | - exists(AccessPath::getAnAssignmentTo(_, this)) |
12 | | - or |
13 | | - SharedTypeTrackingStep::loadStep(_, _, this) |
14 | | - or |
15 | | - SharedTypeTrackingStep::storeStep(_, _, this) |
16 | | - or |
17 | | - SharedTypeTrackingStep::loadStoreStep(_, _, this, _) |
18 | | - or |
19 | | - SharedTypeTrackingStep::loadStoreStep(_, _, _, this) |
| 6 | +cached |
| 7 | +private module Cached { |
| 8 | + cached |
| 9 | + module Public { |
| 10 | + cached |
| 11 | + predicate forceStage() { Stages::TypeTracking::ref() } |
| 12 | + |
| 13 | + cached |
| 14 | + class PropertyName extends string { |
| 15 | + cached |
| 16 | + PropertyName() { |
| 17 | + this = any(DataFlow::PropRef pr).getPropertyName() |
| 18 | + or |
| 19 | + AccessPath::isAssignedInUniqueFile(this) |
| 20 | + or |
| 21 | + exists(AccessPath::getAnAssignmentTo(_, this)) |
| 22 | + or |
| 23 | + SharedTypeTrackingStep::loadStep(_, _, this) |
| 24 | + or |
| 25 | + SharedTypeTrackingStep::storeStep(_, _, this) |
| 26 | + or |
| 27 | + SharedTypeTrackingStep::loadStoreStep(_, _, this, _) |
| 28 | + or |
| 29 | + SharedTypeTrackingStep::loadStoreStep(_, _, _, this) |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * A description of a step on an inter-procedural data flow path. |
| 35 | + */ |
| 36 | + cached |
| 37 | + newtype TStepSummary = |
| 38 | + LevelStep() or |
| 39 | + CallStep() or |
| 40 | + ReturnStep() or |
| 41 | + StoreStep(PropertyName prop) or |
| 42 | + LoadStep(PropertyName prop) or |
| 43 | + CopyStep(PropertyName prop) or |
| 44 | + LoadStoreStep(PropertyName fromProp, PropertyName toProp) { |
| 45 | + SharedTypeTrackingStep::loadStoreStep(_, _, fromProp, toProp) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * INTERNAL: Use `SourceNode.track()` or `SourceNode.backtrack()` instead. |
| 51 | + */ |
| 52 | + cached |
| 53 | + predicate step(DataFlow::SourceNode pred, DataFlow::SourceNode succ, StepSummary summary) { |
| 54 | + exists(DataFlow::Node mid | pred.flowsTo(mid) | StepSummary::smallstep(mid, succ, summary)) |
20 | 55 | } |
21 | 56 | } |
22 | 57 |
|
| 58 | +import Cached::Public |
| 59 | + |
23 | 60 | class OptionalPropertyName extends string { |
24 | 61 | OptionalPropertyName() { this instanceof PropertyName or this = "" } |
25 | 62 | } |
26 | 63 |
|
27 | | -/** |
28 | | - * A description of a step on an inter-procedural data flow path. |
29 | | - */ |
30 | | -newtype TStepSummary = |
31 | | - LevelStep() or |
32 | | - CallStep() or |
33 | | - ReturnStep() or |
34 | | - StoreStep(PropertyName prop) or |
35 | | - LoadStep(PropertyName prop) or |
36 | | - CopyStep(PropertyName prop) or |
37 | | - LoadStoreStep(PropertyName fromProp, PropertyName toProp) { |
38 | | - SharedTypeTrackingStep::loadStoreStep(_, _, fromProp, toProp) |
39 | | - } |
40 | | - |
41 | 64 | /** |
42 | 65 | * INTERNAL: Use `TypeTracker` or `TypeBackTracker` instead. |
43 | 66 | * |
@@ -68,10 +91,7 @@ module StepSummary { |
68 | 91 | /** |
69 | 92 | * INTERNAL: Use `SourceNode.track()` or `SourceNode.backtrack()` instead. |
70 | 93 | */ |
71 | | - cached |
72 | | - predicate step(DataFlow::SourceNode pred, DataFlow::SourceNode succ, StepSummary summary) { |
73 | | - exists(DataFlow::Node mid | pred.flowsTo(mid) | smallstep(mid, succ, summary)) |
74 | | - } |
| 94 | + predicate step = Cached::step/3; |
75 | 95 |
|
76 | 96 | /** |
77 | 97 | * INTERNAL: Use `TypeBackTracker.smallstep()` instead. |
|
0 commit comments