@@ -91,39 +91,43 @@ private class JsValueSummaries extends SummaryModelCsv {
91
91
}
92
92
}
93
93
94
- /** The class `JSContext` . */
95
- private class JsContextDecl extends ClassDecl {
96
- JsContextDecl ( ) { this .getName ( ) = "JSContext " }
94
+ /** The `JSExport` protocol . */
95
+ private class JsExport extends ProtocolDecl {
96
+ JsExport ( ) { this .getName ( ) = "JSExport " }
97
97
}
98
98
99
- /** The type of an object exposed to JavaScript through `JSContext.setObject`. */
100
- private class TypeExposedThroughJsContext extends Type {
101
- TypeExposedThroughJsContext ( ) {
102
- exists ( ApplyExpr c , FuncDecl f |
103
- c .getStaticTarget ( ) = f and
104
- f .getEnclosingDecl ( ) instanceof JsContextDecl and
105
- f .getName ( ) = "setObject(_:forKeyedSubscript)"
106
- |
107
- c .getArgument ( 0 ) .getExpr ( ) .getType ( ) = this
108
- )
109
- }
99
+ /** A protocol inheriting `JSExport`. */
100
+ private class JsExportedProto extends ProtocolDecl {
101
+ JsExportedProto ( ) { this .getABaseTypeDecl + ( ) instanceof JsExport }
102
+ }
103
+
104
+ /** A type that adopts a `JSExport`-inherited protocol. */
105
+ private class JsExportedType extends ClassOrStructDecl {
106
+ JsExportedType ( ) { this .getABaseTypeDecl * ( ) instanceof JsExportedProto }
110
107
}
111
108
112
109
/**
113
- * The members (fields and parameters of functions) of a class or struct
114
- * an instance of which is exposed to JavaScript through `JSContext.setObject`.
110
+ * A flow source that models properties and methods defined in a `JSExport`-inherited protocol
111
+ * and implemented in a type adopting that protcol. These members are accessible from JavaScript
112
+ * when the object is assigned to a `JSContext`.
115
113
*/
116
- private class ExposedThroughJsContextSource extends RemoteFlowSource {
117
- ExposedThroughJsContextSource ( ) {
118
- exists ( ParamDecl p | this .( DataFlow:: ParameterNode ) .getParameter ( ) = p |
119
- p .getDeclaringFunction ( ) .getEnclosingDecl ( ) .( ClassOrStructDecl ) .getType ( ) instanceof
120
- TypeExposedThroughJsContext
114
+ private class JsExportedSource extends RemoteFlowSource {
115
+ JsExportedSource ( ) {
116
+ exists ( MethodDecl adopter , MethodDecl base |
117
+ base .getEnclosingDecl ( ) instanceof JsExportedProto and
118
+ adopter .getEnclosingDecl ( ) instanceof JsExportedType
119
+ |
120
+ this .( DataFlow:: ParameterNode ) .getParameter ( ) .getDeclaringFunction ( ) = adopter and
121
+ adopter .getName ( ) = base .getName ( )
121
122
)
122
123
or
123
- exists ( FieldDecl f | this .asDefinition ( ) .getSourceVariable ( ) = f |
124
- f .getEnclosingDecl ( ) .( ClassOrStructDecl ) .getType ( ) instanceof TypeExposedThroughJsContext
124
+ exists ( FieldDecl adopter , FieldDecl base |
125
+ base .getEnclosingDecl ( ) instanceof JsExportedProto and
126
+ adopter .getEnclosingDecl ( ) instanceof JsExportedType
127
+ |
128
+ this .asDefinition ( ) .getSourceVariable ( ) = adopter and adopter .getName ( ) = base .getName ( )
125
129
)
126
130
}
127
131
128
- override string getSourceType ( ) { result = "Member of a type exposed through JSContext " }
132
+ override string getSourceType ( ) { result = "Member of a type exposed through JSExport " }
129
133
}
0 commit comments