Skip to content

Commit db9a247

Browse files
committed
JS: add test for DOM access where expression appears to have no side effects
1 parent a519eab commit db9a247

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| dom.js:5:3:5:18 | box.offsetHeight | This expression has no effect. |
2+
| dom.js:11:5:11:40 | documen ... ntWidth | This expression has no effect. |
13
| try.js:22:9:22:26 | x.ordinaryProperty | This expression has no effect. |
24
| tst2.js:2:4:2:4 | 0 | This expression has no effect. |
35
| tst.js:3:1:3:2 | 23 | This expression has no effect. |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function f() {
2+
const box = document.getElementById('box');
3+
box.classList.remove('animate');
4+
// Force a reflow by reading layout property (side effect!)
5+
box.offsetHeight; // $SPURIOUS:Alert
6+
7+
try {
8+
console.log("Hello, world!");
9+
} catch (e) {
10+
// Reading this property also forces layout
11+
document.documentElement.clientWidth; // $SPURIOUS:Alert
12+
}
13+
}

0 commit comments

Comments
 (0)