forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jssrc2cpg] Fix race condition for registering types (joernio#3900)
This is for: joernio#3869 (Also applied the same for swiftsrc2cpg with this PR as it uses mostly the same mechanics)
- Loading branch information
1 parent
0b7376e
commit 7682b74
Showing
29 changed files
with
156 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...n-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/datastructures/JsGlobal.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.joern.jssrc2cpg.datastructures | ||
|
||
import io.joern.jssrc2cpg.passes.Defines | ||
import io.joern.x2cpg.datastructures.Global | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
object JsGlobal extends Global { | ||
|
||
def typesSeen(): List[String] = { | ||
val types = usedTypes.keys().asScala.filterNot(_ == Defines.Any).toList | ||
usedTypes.clear() | ||
types | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...n-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/passes/BuiltinTypesPass.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/passes/JavaScriptTypeNodePass.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.joern.jssrc2cpg.passes | ||
|
||
import io.joern.x2cpg.passes.frontend.TypeNodePass | ||
import io.shiftleft.codepropertygraph.Cpg | ||
import io.shiftleft.semanticcpg.language._ | ||
import io.shiftleft.passes.KeyPool | ||
|
||
import scala.collection.mutable | ||
|
||
object JavaScriptTypeNodePass { | ||
|
||
def withRegisteredTypes(registeredTypes: List[String], cpg: Cpg, keyPool: Option[KeyPool] = None): TypeNodePass = { | ||
new TypeNodePass(registeredTypes, cpg, keyPool, getTypesFromCpg = false) { | ||
|
||
override protected def typeDeclTypes: mutable.Set[String] = { | ||
// The only difference to the default implementation in TypeNodePass.typeDeclTypes is the following: | ||
// We do not want to add types for types being inherited as this is already handled by the JavaScriptInheritanceNamePass. | ||
val typeDeclTypes = mutable.Set[String]() | ||
cpg.typeDecl.foreach { typeDecl => | ||
typeDeclTypes += typeDecl.fullName | ||
} | ||
typeDeclTypes | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
18 changes: 0 additions & 18 deletions
18
joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/passes/TypeNodePass.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
...i/frontends/jssrc2cpg/src/test/scala/io/joern/jssrc2cpg/passes/BuiltinTypesPassTest.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.