Skip to content

Commit 2319c28

Browse files
authored
Merge pull request #4092 from erik-krogh/strictExtractor
Approved by esbena
2 parents bc77916 + 246d9b8 commit 2319c28

File tree

8 files changed

+81
-17
lines changed

8 files changed

+81
-17
lines changed

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,9 @@ public Label visit(MemberExpression nd, Context c) {
669669
public Label visit(Program nd, Context c) {
670670
contextManager.enterContainer(toplevelLabel);
671671

672-
isStrict = hasUseStrict(nd.getBody());
672+
boolean prevIsStrict = isStrict;
673+
674+
isStrict = isStrict || hasUseStrict(nd.getBody());
673675

674676
// Add platform-specific globals.
675677
scopeManager.addVariables(platform.getPredefinedGlobals());
@@ -715,6 +717,8 @@ public Label visit(Program nd, Context c) {
715717

716718
emitNodeSymbol(nd, toplevelLabel);
717719

720+
isStrict = prevIsStrict;
721+
718722
return toplevelLabel;
719723
}
720724

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Main {
4343
* A version identifier that should be updated every time the extractor changes in such a way that
4444
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4545
*/
46-
public static final String EXTRACTOR_VERSION = "2020-04-01";
46+
public static final String EXTRACTOR_VERSION = "2020-08-18";
4747

4848
public static final Pattern NEWLINE = Pattern.compile("\n");
4949

javascript/extractor/tests/ts/output/trap/decorators.ts.trap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ scopenodes(#20001,#20112)
311311
scopenesting(#20112,#20000)
312312
isModule(#20001)
313313
isES2015Module(#20001)
314-
#20113=@"var;{fun};{#20112}"
315-
variables(#20113,"fun",#20112)
316-
#20114=@"var;{Class};{#20112}"
317-
variables(#20114,"Class",#20112)
314+
#20113=@"var;{Class};{#20112}"
315+
variables(#20113,"Class",#20112)
316+
#20114=@"var;{fun};{#20112}"
317+
variables(#20114,"fun",#20112)
318318
#20115=@"var;{Class2};{#20112}"
319319
variables(#20115,"Class2",#20112)
320320
#20116=@"local_type_name;{Class};{#20112}"
@@ -347,7 +347,7 @@ hasLocation(#20123,#20037)
347347
enclosingStmt(#20123,#20118)
348348
exprContainers(#20123,#20001)
349349
literals("Class","Class",#20123)
350-
decl(#20123,#20114)
350+
decl(#20123,#20113)
351351
typedecl(#20123,#20116)
352352
#20124=*
353353
scopes(#20124,10)
@@ -499,7 +499,7 @@ exprs(#20161,78,#20159,-1,"fun")
499499
hasLocation(#20161,#20086)
500500
exprContainers(#20161,#20159)
501501
literals("fun","fun",#20161)
502-
decl(#20161,#20113)
502+
decl(#20161,#20114)
503503
#20162=*
504504
scopes(#20162,1)
505505
scopenodes(#20159,#20162)

javascript/extractor/tests/ts/output/trap/export.ts.trap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ scopenodes(#20001,#20055)
155155
scopenesting(#20055,#20000)
156156
isModule(#20001)
157157
isES2015Module(#20001)
158-
#20056=@"var;{f};{#20055}"
159-
variables(#20056,"f",#20055)
160-
#20057=@"var;{foo};{#20055}"
161-
variables(#20057,"foo",#20055)
162-
#20058=@"var;{C};{#20055}"
163-
variables(#20058,"C",#20055)
158+
#20056=@"var;{foo};{#20055}"
159+
variables(#20056,"foo",#20055)
160+
#20057=@"var;{C};{#20055}"
161+
variables(#20057,"C",#20055)
162+
#20058=@"var;{f};{#20055}"
163+
variables(#20058,"f",#20055)
164164
#20059=@"local_type_name;{C};{#20055}"
165165
local_type_names(#20059,"C",#20055)
166166
#20060=*
@@ -186,7 +186,7 @@ hasLocation(#20065,#20017)
186186
enclosingStmt(#20065,#20061)
187187
exprContainers(#20065,#20001)
188188
literals("foo","foo",#20065)
189-
decl(#20065,#20057)
189+
decl(#20065,#20056)
190190
#20066=*
191191
exprs(#20066,3,#20063,1,"42")
192192
hasLocation(#20066,#20021)
@@ -209,7 +209,7 @@ hasLocation(#20070,#20029)
209209
enclosingStmt(#20070,#20068)
210210
exprContainers(#20070,#20001)
211211
literals("C","C",#20070)
212-
decl(#20070,#20058)
212+
decl(#20070,#20057)
213213
typedecl(#20070,#20059)
214214
#20071=*
215215
scopes(#20071,10)
@@ -260,7 +260,7 @@ exprs(#20083,78,#20081,-1,"f")
260260
hasLocation(#20083,#20041)
261261
exprContainers(#20083,#20081)
262262
literals("f","f",#20083)
263-
decl(#20083,#20056)
263+
decl(#20083,#20058)
264264
#20084=*
265265
scopes(#20084,1)
266266
scopenodes(#20081,#20084)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(function () {
2+
if (true) {
3+
function foo() {
4+
return 3;
5+
}
6+
}
7+
return foo(); // this resolves to `foo` above, because we have function-scope in non-strict mode.
8+
})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function () {
2+
if (true) {
3+
function foo() {
4+
return 3;
5+
}
6+
}
7+
return foo(); // `foo` is not defined, because we are in strict-mode.
8+
})();
9+
10+
export default 3; // strict-mode implied because ES2015 module.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
(function () {
3+
"use strict";
4+
if (true) {
5+
function foo() {
6+
return 3;
7+
}
8+
}
9+
return foo(); // `foo` is not defined, because we are in strict-mode.
10+
})();
11+
12+
export default 3; // strict-mode implied because ES2015 module.

javascript/ql/test/library-tests/CallGraphs/FullTest/tests.expected

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ test_getAFunctionValue
9090
| m.js:3:1:3:16 | module.exports.f | m.js:1:13:1:25 | function() {} |
9191
| n.js:2:1:2:3 | m.f | m.js:1:13:1:25 | function() {} |
9292
| n.js:5:1:5:4 | m2.f | m2.js:2:6:2:18 | function() {} |
93+
| non-strict.js:1:1:8:2 | (functi ... ode.\\n}) | non-strict.js:1:2:8:1 | functio ... mode.\\n} |
94+
| non-strict.js:1:2:8:1 | functio ... mode.\\n} | non-strict.js:1:2:8:1 | functio ... mode.\\n} |
95+
| non-strict.js:3:5:5:5 | functio ... ;\\n } | non-strict.js:3:5:5:5 | functio ... ;\\n } |
96+
| non-strict.js:3:14:3:16 | foo | non-strict.js:3:5:5:5 | functio ... ;\\n } |
97+
| non-strict.js:7:10:7:12 | foo | non-strict.js:3:5:5:5 | functio ... ;\\n } |
9398
| protoclass.js:3:1:5:1 | functio ... it();\\n} | protoclass.js:3:1:5:1 | functio ... it();\\n} |
9499
| protoclass.js:3:10:3:10 | F | protoclass.js:3:1:5:1 | functio ... it();\\n} |
95100
| protoclass.js:4:3:4:11 | this.init | protoclass.js:7:20:11:1 | functio ... m();\\n} |
@@ -110,6 +115,12 @@ test_getAFunctionValue
110115
| reflection.js:7:1:7:3 | add | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
111116
| reflection.js:8:1:8:3 | add | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
112117
| reflection.js:8:1:8:9 | add.apply | reflection.js:5:15:5:39 | functio ... n 56; } |
118+
| strict2.js:2:1:10:2 | (functi ... ode.\\n}) | strict2.js:2:2:10:1 | functio ... mode.\\n} |
119+
| strict2.js:2:2:10:1 | functio ... mode.\\n} | strict2.js:2:2:10:1 | functio ... mode.\\n} |
120+
| strict2.js:5:5:7:5 | functio ... ;\\n } | strict2.js:5:5:7:5 | functio ... ;\\n } |
121+
| strict.js:1:1:8:2 | (functi ... ode.\\n}) | strict.js:1:2:8:1 | functio ... mode.\\n} |
122+
| strict.js:1:2:8:1 | functio ... mode.\\n} | strict.js:1:2:8:1 | functio ... mode.\\n} |
123+
| strict.js:3:5:5:5 | functio ... ;\\n } | strict.js:3:5:5:5 | functio ... ;\\n } |
113124
| tst3.js:1:1:1:22 | functio ... fn() {} | tst3.js:1:1:1:22 | functio ... fn() {} |
114125
| tst3.js:2:1:2:23 | functio ... n2() {} | tst3.js:2:1:2:23 | functio ... n2() {} |
115126
| tst.js:1:1:1:15 | function f() {} | tst.js:1:1:1:15 | function f() {} |
@@ -225,6 +236,8 @@ test_getNumArgument
225236
| n.js:2:1:2:5 | m.f() | 0 |
226237
| n.js:4:10:4:24 | require('./m2') | 1 |
227238
| n.js:5:1:5:6 | m2.f() | 0 |
239+
| non-strict.js:1:1:8:4 | (functi ... e.\\n})() | 0 |
240+
| non-strict.js:7:10:7:14 | foo() | 0 |
228241
| protoclass.js:4:3:4:13 | this.init() | 0 |
229242
| protoclass.js:8:3:8:15 | this.method() | 0 |
230243
| protoclass.js:9:11:9:32 | this.me ... d(this) | 1 |
@@ -233,6 +246,10 @@ test_getNumArgument
233246
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | 3 |
234247
| reflection.js:7:1:7:22 | reflective call | 2 |
235248
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | 2 |
249+
| strict2.js:2:1:10:4 | (functi ... e.\\n})() | 0 |
250+
| strict2.js:9:10:9:14 | foo() | 0 |
251+
| strict.js:1:1:8:4 | (functi ... e.\\n})() | 0 |
252+
| strict.js:7:10:7:14 | foo() | 0 |
236253
| tst.js:6:1:6:3 | f() | 0 |
237254
| tst.js:7:1:7:3 | g() | 0 |
238255
| tst.js:8:1:8:3 | h() | 0 |
@@ -321,6 +338,8 @@ test_getCalleeNode
321338
| n.js:2:1:2:5 | m.f() | n.js:2:1:2:3 | m.f |
322339
| n.js:4:10:4:24 | require('./m2') | n.js:4:10:4:16 | require |
323340
| n.js:5:1:5:6 | m2.f() | n.js:5:1:5:4 | m2.f |
341+
| non-strict.js:1:1:8:4 | (functi ... e.\\n})() | non-strict.js:1:1:8:2 | (functi ... ode.\\n}) |
342+
| non-strict.js:7:10:7:14 | foo() | non-strict.js:7:10:7:12 | foo |
324343
| protoclass.js:4:3:4:13 | this.init() | protoclass.js:4:3:4:11 | this.init |
325344
| protoclass.js:8:3:8:15 | this.method() | protoclass.js:8:3:8:13 | this.method |
326345
| protoclass.js:9:11:9:32 | this.me ... d(this) | protoclass.js:9:11:9:26 | this.method.bind |
@@ -330,6 +349,10 @@ test_getCalleeNode
330349
| reflection.js:7:1:7:22 | reflective call | reflection.js:7:1:7:3 | add |
331350
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | reflection.js:8:1:8:9 | add.apply |
332351
| reflection.js:8:1:8:25 | reflective call | reflection.js:8:1:8:3 | add |
352+
| strict2.js:2:1:10:4 | (functi ... e.\\n})() | strict2.js:2:1:10:2 | (functi ... ode.\\n}) |
353+
| strict2.js:9:10:9:14 | foo() | strict2.js:9:10:9:12 | foo |
354+
| strict.js:1:1:8:4 | (functi ... e.\\n})() | strict.js:1:1:8:2 | (functi ... ode.\\n}) |
355+
| strict.js:7:10:7:14 | foo() | strict.js:7:10:7:12 | foo |
333356
| tst.js:6:1:6:3 | f() | tst.js:6:1:6:1 | f |
334357
| tst.js:7:1:7:3 | g() | tst.js:7:1:7:1 | g |
335358
| tst.js:8:1:8:3 | h() | tst.js:8:1:8:1 | h |
@@ -408,11 +431,15 @@ test_getACallee
408431
| m.js:3:1:3:18 | module.exports.f() | m.js:1:13:1:25 | function() {} |
409432
| n.js:2:1:2:5 | m.f() | m.js:1:13:1:25 | function() {} |
410433
| n.js:5:1:5:6 | m2.f() | m2.js:2:6:2:18 | function() {} |
434+
| non-strict.js:1:1:8:4 | (functi ... e.\\n})() | non-strict.js:1:2:8:1 | functio ... mode.\\n} |
435+
| non-strict.js:7:10:7:14 | foo() | non-strict.js:3:5:5:5 | functio ... ;\\n } |
411436
| protoclass.js:4:3:4:13 | this.init() | protoclass.js:7:20:11:1 | functio ... m();\\n} |
412437
| protoclass.js:8:3:8:15 | this.method() | protoclass.js:13:22:13:34 | function() {} |
413438
| reflection.js:7:1:7:22 | reflective call | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
414439
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | reflection.js:5:15:5:39 | functio ... n 56; } |
415440
| reflection.js:8:1:8:25 | reflective call | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
441+
| strict2.js:2:1:10:4 | (functi ... e.\\n})() | strict2.js:2:2:10:1 | functio ... mode.\\n} |
442+
| strict.js:1:1:8:4 | (functi ... e.\\n})() | strict.js:1:2:8:1 | functio ... mode.\\n} |
416443
| tst.js:6:1:6:3 | f() | tst.js:1:1:1:15 | function f() {} |
417444
| tst.js:7:1:7:3 | g() | tst.js:2:9:2:21 | function() {} |
418445
| tst.js:8:1:8:3 | h() | tst.js:3:5:3:17 | function() {} |
@@ -463,13 +490,16 @@ test_getCalleeName
463490
| n.js:2:1:2:5 | m.f() | f |
464491
| n.js:4:10:4:24 | require('./m2') | require |
465492
| n.js:5:1:5:6 | m2.f() | f |
493+
| non-strict.js:7:10:7:14 | foo() | foo |
466494
| protoclass.js:4:3:4:13 | this.init() | init |
467495
| protoclass.js:8:3:8:15 | this.method() | method |
468496
| protoclass.js:9:11:9:32 | this.me ... d(this) | bind |
469497
| protoclass.js:10:3:10:5 | m() | m |
470498
| reflection.js:4:5:4:12 | sneaky() | sneaky |
471499
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | call |
472500
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | apply |
501+
| strict2.js:9:10:9:14 | foo() | foo |
502+
| strict.js:7:10:7:14 | foo() | foo |
473503
| tst.js:6:1:6:3 | f() | f |
474504
| tst.js:7:1:7:3 | g() | g |
475505
| tst.js:8:1:8:3 | h() | h |

0 commit comments

Comments
 (0)