Skip to content

Commit 7af4baf

Browse files
author
Max Schaefer
authored
Merge pull request #1220 from esben-semmle/js/another-getAPropertyAttribut-performance-fix
JS: inline CallToObjectDefineProperty::getAPropertyAttribute
2 parents 4c9edaf + b86f43b commit 7af4baf

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

javascript/ql/src/Declarations/DeadStoreOfProperty.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ where
161161
// exclude results from non-value definitions from `Object.defineProperty`
162162
(
163163
assign1 instanceof CallToObjectDefineProperty implies
164-
assign1.(CallToObjectDefineProperty).getAPropertyAttribute().getPropertyName() = "value"
164+
assign1.(CallToObjectDefineProperty).hasPropertyAttributeWrite("value", _)
165165
)
166166
select assign1.getWriteNode(),
167167
"This write to property '" + name + "' is useless, since $@ always overrides it.",

javascript/ql/src/Expressions/ExprHasNoEffect.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ predicate isGetterProperty(string name) {
3939
exists(CallToObjectDefineProperty defProp |
4040
name = defProp.getPropertyName() |
4141
// ... where `descriptor` defines a getter
42-
defProp.getAPropertyAttribute().getPropertyName() = "get" or
42+
defProp.hasPropertyAttributeWrite("get", _) or
4343
// ... where `descriptor` may define a getter
4444
exists (DataFlow::SourceNode descriptor |
4545
descriptor.flowsTo(defProp.getPropertyDescriptor()) |

javascript/ql/src/semmle/javascript/StandardLibrary.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ class CallToObjectDefineProperty extends DataFlow::MethodCallNode {
2222
/** Gets the data flow node denoting the descriptor of the property being defined. */
2323
DataFlow::Node getPropertyDescriptor() { result = getArgument(2) }
2424

25-
/** Gets a data flow node defining a descriptor attribute of the property being defined. */
26-
DataFlow::PropWrite getAPropertyAttribute() {
27-
exists (DataFlow::SourceNode descriptor |
25+
/**
26+
* Holds if there is an assignment to property `name` to the
27+
* attributes object on this node, and the right hand side of the
28+
* assignment is `rhs`.
29+
*/
30+
predicate hasPropertyAttributeWrite(string name, DataFlow::Node rhs) {
31+
exists(DataFlow::SourceNode descriptor |
2832
descriptor.flowsTo(getPropertyDescriptor()) and
29-
result = descriptor.getAPropertyWrite()
33+
descriptor.hasPropertyWrite(name, rhs)
3034
)
3135
}
32-
3336
}
3437

3538
/**

0 commit comments

Comments
 (0)