Skip to content

Commit 8cd3cb5

Browse files
authored
Merge pull request #1346 from xiemaisi/js/revert-1078
Approved by esben-semmle
2 parents fe920ec + 924664a commit 8cd3cb5

File tree

5 files changed

+0
-183
lines changed

5 files changed

+0
-183
lines changed

javascript/ql/src/semmle/javascript/Functions.qll

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -173,49 +173,6 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
173173
result = getAReturnStmt().getExpr()
174174
}
175175

176-
/**
177-
* Gets a return from a function which has undefined value (that is, implicit
178-
* returns and returns without expressions).
179-
*
180-
* Functions can have undefined returns in a few different ways:
181-
*
182-
* 1. An explicit return statement with no expression (the statement `return;`)
183-
*
184-
* 2. An implicit return resulting from an expression executing as the last thing
185-
* in the function. For example, the test in a final `if` statement:
186-
*
187-
* ```
188-
* function foo() {
189-
* ...
190-
* if (test) { return 1; }
191-
* }
192-
* ```
193-
*
194-
* Some things look like they might return undefined but actually don't because
195-
* the containing functioning doesn't return at all. For instance, `throw`
196-
* statements prevent the containing function from returning, so they don't count
197-
* as undefined returns. Similarly, `yield` doesn't actually cause a return,
198-
* since the containing function is a generator and can be re-entered, so we also
199-
* exclude yields entirely. Likewise, we exclude generator functions from
200-
* consideration, as well as asynchronous functions, since calls to both produce
201-
* something distinct from what's explicitly returned by the function.
202-
*
203-
* Despite the fact that yield expressions are invalid outside of generators, we
204-
* include them anyway just to ensure that we're not relying on a perfect analysis
205-
* of a function to be a generator, and instead are looking also explicitly at the
206-
* return sites.
207-
*/
208-
ConcreteControlFlowNode getAnUndefinedReturn() {
209-
not this.getBody() instanceof Expr and
210-
not this.isGenerator() and
211-
not this.isAsync() and
212-
not result instanceof ThrowStmt and
213-
not result instanceof YieldExpr and
214-
not (result instanceof ReturnStmt and exists(result.(ReturnStmt).getExpr())) and
215-
result.getContainer() = this and
216-
result.isAFinalNode()
217-
}
218-
219176
/**
220177
* Gets the function whose `this` binding a `this` expression in this function refers to,
221178
* which is the nearest enclosing non-arrow function.

javascript/ql/test/library-tests/Functions/getAnUndefinedReturn.qll

Lines changed: 0 additions & 6 deletions
This file was deleted.

javascript/ql/test/library-tests/Functions/tests.expected

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ test_getVariable
1212
| tst.js:11:1:11:35 | functio ... ts; } } |
1313
| tst.js:12:1:12:44 | functio ... s) {} } |
1414
| tst.js:14:1:14:37 | functio ... s[0]; } |
15-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } |
16-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } |
17-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } |
18-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
19-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } |
20-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } |
21-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } |
22-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } |
2315
test_getScope
2416
| arrowfns.js:1:24:1:36 | s => s.length |
2517
| arrowfns.js:2:13:2:23 | () => ++cnt |
@@ -41,17 +33,6 @@ test_getScope
4133
| tst.js:11:1:11:35 | functio ... ts; } } |
4234
| tst.js:12:1:12:44 | functio ... s) {} } |
4335
| tst.js:14:1:14:37 | functio ... s[0]; } |
44-
| undefinedreturns.js:11:20:11:32 | function () 1 |
45-
| undefinedreturns.js:12:29:12:35 | () => 1 |
46-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } |
47-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } |
48-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } |
49-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
50-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } |
51-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } |
52-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } |
53-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } |
54-
| undefinedreturns.js:30:29:30:37 | () => { } |
5536
test_getParameter
5637
| arrowfns.js:1:24:1:36 | s => s.length | 0 | arrowfns.js:1:24:1:24 | s |
5738
| defaultargs.js:1:1:1:24 | functio ... +19) {} | 0 | defaultargs.js:1:12:1:12 | x |
@@ -71,10 +52,6 @@ test_ReturnedExpression
7152
| arrowfns.js:2:13:2:23 | () => ++cnt | arrowfns.js:2:19:2:23 | ++cnt |
7253
| exprclosures.js:1:7:1:21 | function(x) x+1 | exprclosures.js:1:19:1:21 | x+1 |
7354
| tst.js:14:1:14:37 | functio ... s[0]; } | tst.js:14:23:14:34 | arguments[0] |
74-
| undefinedreturns.js:11:20:11:32 | function () 1 | undefinedreturns.js:11:32:11:32 | 1 |
75-
| undefinedreturns.js:12:29:12:35 | () => 1 | undefinedreturns.js:12:35:12:35 | 1 |
76-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | undefinedreturns.js:17:46:17:46 | 1 |
77-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:49:29:49 | 1 |
7855
test_getDefaultArguments
7956
| defaultargs.js:1:15:1:15 | y | defaultargs.js:1:17:1:20 | x+19 |
8057
test_Function
@@ -98,17 +75,6 @@ test_Function
9875
| tst.js:11:1:11:35 | functio ... ts; } } |
9976
| tst.js:12:1:12:44 | functio ... s) {} } |
10077
| tst.js:14:1:14:37 | functio ... s[0]; } |
101-
| undefinedreturns.js:11:20:11:32 | function () 1 |
102-
| undefinedreturns.js:12:29:12:35 | () => 1 |
103-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } |
104-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } |
105-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } |
106-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
107-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } |
108-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } |
109-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } |
110-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } |
111-
| undefinedreturns.js:30:29:30:37 | () => { } |
11278
test_getBody
11379
| arrowfns.js:1:24:1:36 | s => s.length | arrowfns.js:1:29:1:36 | s.length |
11480
| arrowfns.js:2:13:2:23 | () => ++cnt | arrowfns.js:2:19:2:23 | ++cnt |
@@ -130,17 +96,6 @@ test_getBody
13096
| tst.js:11:1:11:35 | functio ... ts; } } | tst.js:11:14:11:35 | { { var ... ts; } } |
13197
| tst.js:12:1:12:44 | functio ... s) {} } | tst.js:12:14:12:44 | { try { ... s) {} } |
13298
| tst.js:14:1:14:37 | functio ... s[0]; } | tst.js:14:14:14:37 | { retur ... s[0]; } |
133-
| undefinedreturns.js:11:20:11:32 | function () 1 | undefinedreturns.js:11:32:11:32 | 1 |
134-
| undefinedreturns.js:12:29:12:35 | () => 1 | undefinedreturns.js:12:35:12:35 | 1 |
135-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } | undefinedreturns.js:13:26:13:28 | { } |
136-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } | undefinedreturns.js:14:27:14:29 | { } |
137-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } | undefinedreturns.js:15:29:15:40 | { throw 1; } |
138-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } | undefinedreturns.js:16:30:16:41 | { yield 1; } |
139-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | undefinedreturns.js:17:37:17:49 | { return 1; } |
140-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } | undefinedreturns.js:27:28:27:30 | { } |
141-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | undefinedreturns.js:28:38:28:48 | { return; } |
142-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:28:29:54 | { if (t ... 1; } } |
143-
| undefinedreturns.js:30:29:30:37 | () => { } | undefinedreturns.js:30:35:30:37 | { } |
14499
test_getId
145100
| defaultargs.js:1:1:1:24 | functio ... +19) {} | defaultargs.js:1:10:1:10 | f | f |
146101
| generators.js:1:1:4:1 | functio ... i++;\\n} | generators.js:1:11:1:13 | foo | foo |
@@ -155,14 +110,6 @@ test_getId
155110
| tst.js:11:1:11:35 | functio ... ts; } } | tst.js:11:10:11:10 | m | m |
156111
| tst.js:12:1:12:44 | functio ... s) {} } | tst.js:12:10:12:10 | n | n |
157112
| tst.js:14:1:14:37 | functio ... s[0]; } | tst.js:14:10:14:10 | p | p |
158-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } | undefinedreturns.js:13:11:13:22 | generator_fn | generator_fn |
159-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } | undefinedreturns.js:14:16:14:23 | async_fn | async_fn |
160-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } | undefinedreturns.js:15:10:15:25 | fn_w_final_throw | fn_w_final_throw |
161-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } | undefinedreturns.js:16:11:16:26 | fn_w_final_yield | fn_w_final_yield |
162-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | undefinedreturns.js:17:10:17:33 | fn_w_fi ... _w_expr | fn_w_final_return_w_expr |
163-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } | undefinedreturns.js:27:10:27:24 | fn_w_empty_body | fn_w_empty_body |
164-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | undefinedreturns.js:28:10:28:34 | fn_w_fi ... wo_expr | fn_w_final_return_wo_expr |
165-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:10:29:24 | fn_w_final_expr | fn_w_final_expr |
166113
test_hasRestParameter
167114
| restparms.js:1:1:2:1 | functio ... ys) {\\n} |
168115
test_getArgumentsVariable
@@ -183,15 +130,6 @@ test_getArgumentsVariable
183130
| tst.js:11:1:11:35 | functio ... ts; } } |
184131
| tst.js:12:1:12:44 | functio ... s) {} } |
185132
| tst.js:14:1:14:37 | functio ... s[0]; } |
186-
| undefinedreturns.js:11:20:11:32 | function () 1 |
187-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } |
188-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } |
189-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } |
190-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
191-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } |
192-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } |
193-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } |
194-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } |
195133
test_getBodyStmt
196134
| arrowfns.js:3:12:3:41 | () => { ... "); ; } | 0 | arrowfns.js:3:20:3:37 | alert("Wake up!"); |
197135
| arrowfns.js:3:12:3:41 | () => { ... "); ; } | 1 | arrowfns.js:3:39:3:39 | ; |
@@ -200,16 +138,9 @@ test_getBodyStmt
200138
| tst.js:11:1:11:35 | functio ... ts; } } | 0 | tst.js:11:16:11:33 | { var arguments; } |
201139
| tst.js:12:1:12:44 | functio ... s) {} } | 0 | tst.js:12:16:12:42 | try { } ... nts) {} |
202140
| tst.js:14:1:14:37 | functio ... s[0]; } | 0 | tst.js:14:16:14:35 | return arguments[0]; |
203-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } | 0 | undefinedreturns.js:15:31:15:38 | throw 1; |
204-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } | 0 | undefinedreturns.js:16:32:16:39 | yield 1; |
205-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | 0 | undefinedreturns.js:17:39:17:47 | return 1; |
206-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | 0 | undefinedreturns.js:28:40:28:46 | return; |
207-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | 0 | undefinedreturns.js:29:30:29:52 | if (tes ... rn 1; } |
208141
test_isGenerator
209142
| generators.js:1:1:4:1 | functio ... i++;\\n} |
210143
| generators.js:6:2:6:19 | function* bar() {} |
211-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } |
212-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
213144
test_usesArgumentsObject
214145
| tst.js:14:1:14:37 | functio ... s[0]; } |
215146
test_getEnclosingStmt
@@ -233,41 +164,7 @@ test_getEnclosingStmt
233164
| tst.js:11:1:11:35 | functio ... ts; } } | tst.js:11:1:11:35 | functio ... ts; } } |
234165
| tst.js:12:1:12:44 | functio ... s) {} } | tst.js:12:1:12:44 | functio ... s) {} } |
235166
| tst.js:14:1:14:37 | functio ... s[0]; } | tst.js:14:1:14:37 | functio ... s[0]; } |
236-
| undefinedreturns.js:11:20:11:32 | function () 1 | undefinedreturns.js:11:1:11:33 | const f ... n () 1; |
237-
| undefinedreturns.js:12:29:12:35 | () => 1 | undefinedreturns.js:12:1:12:36 | const a ... ) => 1; |
238-
| undefinedreturns.js:13:1:13:28 | functio ... n() { } | undefinedreturns.js:13:1:13:28 | functio ... n() { } |
239-
| undefinedreturns.js:14:1:14:29 | async f ... n() { } | undefinedreturns.js:14:1:14:29 | async f ... n() { } |
240-
| undefinedreturns.js:15:1:15:40 | functio ... ow 1; } | undefinedreturns.js:15:1:15:40 | functio ... ow 1; } |
241-
| undefinedreturns.js:16:1:16:41 | functio ... ld 1; } | undefinedreturns.js:16:1:16:41 | functio ... ld 1; } |
242-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | undefinedreturns.js:17:1:17:49 | functio ... rn 1; } |
243-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } | undefinedreturns.js:27:1:27:30 | functio ... y() { } |
244-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | undefinedreturns.js:28:1:28:48 | functio ... turn; } |
245-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:1:29:54 | functio ... 1; } } |
246-
| undefinedreturns.js:30:29:30:37 | () => { } | undefinedreturns.js:30:1:30:38 | const a ... => { }; |
247167
test_isRestParameter
248168
| restparms.js:1:18:1:19 | ys |
249169
test_ReturnStmt
250170
| tst.js:14:1:14:37 | functio ... s[0]; } | tst.js:14:16:14:35 | return arguments[0]; |
251-
| undefinedreturns.js:17:1:17:49 | functio ... rn 1; } | undefinedreturns.js:17:39:17:47 | return 1; |
252-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | undefinedreturns.js:28:40:28:46 | return; |
253-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:42:29:50 | return 1; |
254-
test_getAnUndefinedReturn
255-
| arrowfns.js:3:12:3:41 | () => { ... "); ; } | arrowfns.js:3:39:3:39 | ; |
256-
| defaultargs.js:1:1:1:24 | functio ... +19) {} | defaultargs.js:1:23:1:24 | {} |
257-
| restparms.js:1:1:2:1 | functio ... ys) {\\n} | restparms.js:1:22:2:1 | {\\n} |
258-
| tst.js:1:1:1:15 | function A() {} | tst.js:1:14:1:15 | {} |
259-
| tst.js:2:1:2:16 | function B(x) {} | tst.js:2:15:2:16 | {} |
260-
| tst.js:3:1:3:19 | function C(x, y) {} | tst.js:3:18:3:19 | {} |
261-
| tst.js:4:9:4:21 | function() {} | tst.js:4:20:4:21 | {} |
262-
| tst.js:5:2:5:15 | function(x) {} | tst.js:5:14:5:15 | {} |
263-
| tst.js:6:2:6:18 | function(x, y) {} | tst.js:6:17:6:18 | {} |
264-
| tst.js:7:9:7:23 | function h() {} | tst.js:7:22:7:23 | {} |
265-
| tst.js:9:1:9:24 | functio ... nts) {} | tst.js:9:23:9:24 | {} |
266-
| tst.js:10:1:10:31 | functio ... ents; } | tst.js:10:20:10:28 | arguments |
267-
| tst.js:11:1:11:35 | functio ... ts; } } | tst.js:11:22:11:30 | arguments |
268-
| tst.js:12:1:12:44 | functio ... s) {} } | tst.js:12:20:12:22 | { } |
269-
| tst.js:12:1:12:44 | functio ... s) {} } | tst.js:12:41:12:42 | {} |
270-
| undefinedreturns.js:27:1:27:30 | functio ... y() { } | undefinedreturns.js:27:28:27:30 | { } |
271-
| undefinedreturns.js:28:1:28:48 | functio ... turn; } | undefinedreturns.js:28:40:28:46 | return; |
272-
| undefinedreturns.js:29:1:29:54 | functio ... 1; } } | undefinedreturns.js:29:34:29:37 | test |
273-
| undefinedreturns.js:30:29:30:37 | () => { } | undefinedreturns.js:30:35:30:37 | { } |

javascript/ql/test/library-tests/Functions/tests.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ import usesArgumentsObject
1414
import getEnclosingStmt
1515
import isRestParameter
1616
import ReturnStmt
17-
import getAnUndefinedReturn

javascript/ql/test/library-tests/Functions/undefinedreturns.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)