Skip to content

Commit a828359

Browse files
committed
JS: Make PropWrite not depend on SourceNode
1 parent e3440c1 commit a828359

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,25 +647,24 @@ module DataFlow {
647647
* writes to the corresponding property.
648648
*/
649649
private class ObjectDefinePropertyAsPropWrite extends PropWrite, ValueNode {
650-
CallToObjectDefineProperty odp;
650+
override MethodCallExpr astNode;
651651

652-
ObjectDefinePropertyAsPropWrite() { odp = this }
652+
ObjectDefinePropertyAsPropWrite() {
653+
astNode.getReceiver().(GlobalVarAccess).getName() = "Object" and
654+
astNode.getMethodName() = "defineProperty"
655+
}
653656

654-
override Node getBase() { result = odp.getBaseObject() }
657+
override Node getBase() { result = astNode.getArgument(0).flow() }
655658

656-
override Expr getPropertyNameExpr() { result = odp.getArgument(1).asExpr() }
659+
override Expr getPropertyNameExpr() { result = astNode.getArgument(1) }
657660

658-
override string getPropertyName() { result = odp.getPropertyName() }
661+
override string getPropertyName() { result = astNode.getArgument(1).getStringValue() }
659662

660663
override Node getRhs() {
661-
// not using `CallToObjectDefineProperty::getAPropertyAttribute` for performance reasons
662-
exists(ObjectLiteralNode propdesc |
663-
propdesc.flowsTo(odp.getPropertyDescriptor()) and
664-
propdesc.hasPropertyWrite("value", result)
665-
)
664+
result = astNode.getArgument(2).(ObjectExpr).getPropertyByName("value").getInit().flow()
666665
}
667666

668-
override ControlFlowNode getWriteNode() { result = odp.getAstNode() }
667+
override ControlFlowNode getWriteNode() { result = astNode }
669668
}
670669

671670
/**

0 commit comments

Comments
 (0)