Open
Description
Problem
Currently, there is no way to execute probe-related code during the initialization or teardown phases of the SourceFile class lifecycle.
Proposal
My idea is to introduce two new optional callbacks for probes, to be implemented within the ProbeRunner:
-
initialize(SourceFile)
(done with PR: feat(probes): add initialize #362) -
finalize(SourceFile)
Both methods would receive the current SourceFile instance as a parameter. Since ProbeRunner already stores this reference internally, this integration would be straightforward.
Note
SourceFile has no finalize/teardown lifecycle, we need to implement one and use in AstAnalyser (probably)
Example
Here’s a snippet of code that would be moved into the initialize callback of the isWeakCrypto
probe:
this.tracer = new VariableTracer()
.enableDefaultTracing()
// ↓↓↓ this part
.trace("crypto.createHash", {
followConsecutiveAssignment: true, moduleName: "crypto"
});
We don't need to trace crypto.createHash
if the isWeakCrypto probe is not used.