refactor promisify models into a module

This commit is contained in:
Erik Krogh Kristensen
2021-06-20 22:12:18 +02:00
parent 05389bb9d4
commit f2ca2134d1
3 changed files with 34 additions and 13 deletions

View File

@@ -686,9 +686,7 @@ module API {
promisified = false and
boundArgs = 0
or
exists(DataFlow::CallNode promisify |
promisify = DataFlow::moduleImport(["util", "bluebird"]).getAMemberCall("promisify")
|
exists(Promisify::PromisifyCall promisify |
trackUseNode(nd, false, boundArgs, t.continue()).flowsTo(promisify.getArgument(0)) and
promisified = true and
result = promisify

View File

@@ -659,3 +659,33 @@ private module DynamicImportSteps {
}
}
}
/**
* Provides classes modeling libraries implementing `promisify` functions.
* That is, functions that convert callback style functions to functions that return a promise.
*/
module Promisify {
/**
* Gets a call to a `promisifyAll` function.
* E.g. `require("bluebird").promisifyAll(...)`.
*/
class PromisifyAllCall extends DataFlow::CallNode {
PromisifyAllCall() {
this =
[
DataFlow::moduleMember("bluebird", "promisifyAll"),
DataFlow::moduleImport("util-promisifyall")
].getACall()
}
}
/**
* Gets a call to a `promisify` function.
* E.g. `require("util").promisify(...)`.
*/
class PromisifyCall extends DataFlow::CallNode {
PromisifyCall() {
this = DataFlow::moduleImport(["util", "bluebird"]).getAMemberCall("promisify")
}
}
}

View File

@@ -472,14 +472,9 @@ module NodeJSLib {
result = pred.track(t2, t)
or
t.continue() = t2 and
exists(DataFlow::CallNode promisifyAllCall |
exists(Promisify::PromisifyAllCall promisifyAllCall |
result = promisifyAllCall and
pred.flowsTo(promisifyAllCall.getArgument(0)) and
promisifyAllCall =
[
DataFlow::moduleMember("bluebird", "promisifyAll"),
DataFlow::moduleImport("util-promisifyall")
].getACall()
pred.flowsTo(promisifyAllCall.getArgument(0))
)
or
// const fs = require('fs');
@@ -648,9 +643,7 @@ module NodeJSLib {
private DataFlow::SourceNode maybePromisified(DataFlow::SourceNode callback) {
result = callback
or
exists(DataFlow::CallNode promisify |
promisify = DataFlow::moduleMember(["util", "bluebird"], "promisify").getACall()
|
exists(Promisify::PromisifyCall promisify |
result = promisify and promisify.getArgument(0).getALocalSource() = callback
)
}