Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9dccd9f

Browse files
authored
Merge pull request #1050 from asger-semmle/prototype-instance-methods
Approved by xiemaisi
2 parents b85f446 + 56977b8 commit 9dccd9f

4 files changed

Lines changed: 136 additions & 2 deletions

File tree

javascript/ql/src/semmle/javascript/dataflow/internal/AbstractPropertiesImpl.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ AbstractValue getAnInitialPropertyValue(DefiniteAbstractValue baseVal, string pr
4747
result = p.getInit().analyze().getALocalValue()
4848
)
4949
or
50-
// `f.prototype` for functions `f` that are instantiated
50+
// `f.prototype` for functions `f`
5151
propertyName = "prototype" and
52-
baseVal = any(NewExpr ne).getCallee().analyze().getALocalValue() and
5352
result = TAbstractInstance(baseVal)
5453
}
5554

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as dummy from 'dummy';
2+
3+
function F() {
4+
this.init();
5+
}
6+
7+
F.prototype.init = function() {
8+
this.method();
9+
let m = this.method.bind(this);
10+
m();
11+
};
12+
13+
F.prototype.method = function() {};
14+
15+
export default F;

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ test_isUncertain
1212
| n.js:2:1:2:5 | m.f() |
1313
| n.js:4:10:4:24 | require('./m2') |
1414
| n.js:5:1:5:6 | m2.f() |
15+
| protoclass.js:4:3:4:13 | this.init() |
16+
| protoclass.js:8:3:8:15 | this.method() |
17+
| protoclass.js:9:11:9:32 | this.me ... d(this) |
18+
| protoclass.js:10:3:10:5 | m() |
1519
| reflection.js:7:1:7:22 | add.cal ... 23, 19) |
1620
| reflection.js:8:1:8:25 | add.app ... 3, 19]) |
1721
| tst.js:6:1:6:3 | f() |
@@ -86,6 +90,18 @@ test_getAFunctionValue
8690
| m.js:3:1:3:16 | module.exports.f | m.js:1:13:1:25 | function() {} |
8791
| n.js:2:1:2:3 | m.f | m.js:1:13:1:25 | function() {} |
8892
| n.js:5:1:5:4 | m2.f | m2.js:2:6:2:18 | function() {} |
93+
| protoclass.js:3:1:5:1 | functio ... it();\\n} | protoclass.js:3:1:5:1 | functio ... it();\\n} |
94+
| protoclass.js:3:10:3:10 | F | protoclass.js:3:1:5:1 | functio ... it();\\n} |
95+
| protoclass.js:4:3:4:11 | this.init | protoclass.js:7:20:11:1 | functio ... m();\\n} |
96+
| protoclass.js:7:1:7:1 | F | protoclass.js:3:1:5:1 | functio ... it();\\n} |
97+
| protoclass.js:7:1:11:1 | F.proto ... m();\\n} | protoclass.js:7:20:11:1 | functio ... m();\\n} |
98+
| protoclass.js:7:20:11:1 | functio ... m();\\n} | protoclass.js:7:20:11:1 | functio ... m();\\n} |
99+
| protoclass.js:8:3:8:13 | this.method | protoclass.js:13:22:13:34 | function() {} |
100+
| protoclass.js:9:11:9:21 | this.method | protoclass.js:13:22:13:34 | function() {} |
101+
| protoclass.js:13:1:13:1 | F | protoclass.js:3:1:5:1 | functio ... it();\\n} |
102+
| protoclass.js:13:1:13:34 | F.proto ... on() {} | protoclass.js:13:22:13:34 | function() {} |
103+
| protoclass.js:13:22:13:34 | function() {} | protoclass.js:13:22:13:34 | function() {} |
104+
| protoclass.js:15:16:15:16 | F | protoclass.js:3:1:5:1 | functio ... it();\\n} |
89105
| reflection.js:1:1:3:1 | functio ... x+y;\\n} | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
90106
| reflection.js:5:3:5:5 | add | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
91107
| reflection.js:5:3:5:39 | add.app ... n 56; } | reflection.js:5:15:5:39 | functio ... n 56; } |
@@ -176,6 +192,7 @@ test_getArgument
176192
| es2015.js:36:1:36:17 | sum(1, ...[2], 3) | 0 | es2015.js:36:5:36:5 | 1 |
177193
| n.js:1:9:1:22 | require('./m') | 0 | n.js:1:17:1:21 | './m' |
178194
| n.js:4:10:4:24 | require('./m2') | 0 | n.js:4:18:4:23 | './m2' |
195+
| protoclass.js:9:11:9:32 | this.me ... d(this) | 0 | protoclass.js:9:28:9:31 | this |
179196
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | 0 | reflection.js:7:10:7:13 | null |
180197
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | 1 | reflection.js:7:16:7:17 | 23 |
181198
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | 2 | reflection.js:7:20:7:21 | 19 |
@@ -207,6 +224,10 @@ test_getNumArgument
207224
| n.js:2:1:2:5 | m.f() | 0 |
208225
| n.js:4:10:4:24 | require('./m2') | 1 |
209226
| n.js:5:1:5:6 | m2.f() | 0 |
227+
| protoclass.js:4:3:4:13 | this.init() | 0 |
228+
| protoclass.js:8:3:8:15 | this.method() | 0 |
229+
| protoclass.js:9:11:9:32 | this.me ... d(this) | 1 |
230+
| protoclass.js:10:3:10:5 | m() | 0 |
210231
| reflection.js:4:5:4:12 | sneaky() | 0 |
211232
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | 3 |
212233
| reflection.js:7:1:7:22 | reflective call | 2 |
@@ -252,6 +273,10 @@ test_isIncomplete
252273
| n.js:2:1:2:5 | m.f() |
253274
| n.js:4:10:4:24 | require('./m2') |
254275
| n.js:5:1:5:6 | m2.f() |
276+
| protoclass.js:4:3:4:13 | this.init() |
277+
| protoclass.js:8:3:8:15 | this.method() |
278+
| protoclass.js:9:11:9:32 | this.me ... d(this) |
279+
| protoclass.js:10:3:10:5 | m() |
255280
| reflection.js:7:1:7:22 | add.cal ... 23, 19) |
256281
| reflection.js:8:1:8:25 | add.app ... 3, 19]) |
257282
| tst.js:6:1:6:3 | f() |
@@ -295,6 +320,10 @@ test_getCalleeNode
295320
| n.js:2:1:2:5 | m.f() | n.js:2:1:2:3 | m.f |
296321
| n.js:4:10:4:24 | require('./m2') | n.js:4:10:4:16 | require |
297322
| n.js:5:1:5:6 | m2.f() | n.js:5:1:5:4 | m2.f |
323+
| protoclass.js:4:3:4:13 | this.init() | protoclass.js:4:3:4:11 | this.init |
324+
| protoclass.js:8:3:8:15 | this.method() | protoclass.js:8:3:8:13 | this.method |
325+
| protoclass.js:9:11:9:32 | this.me ... d(this) | protoclass.js:9:11:9:26 | this.method.bind |
326+
| protoclass.js:10:3:10:5 | m() | protoclass.js:10:3:10:3 | m |
298327
| reflection.js:4:5:4:12 | sneaky() | reflection.js:4:5:4:10 | sneaky |
299328
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | reflection.js:7:1:7:8 | add.call |
300329
| reflection.js:7:1:7:22 | reflective call | reflection.js:7:1:7:3 | add |
@@ -334,6 +363,7 @@ test_getLastArgument
334363
| es2015.js:27:5:27:23 | console.log(this.x) | es2015.js:27:17:27:22 | this.x |
335364
| n.js:1:9:1:22 | require('./m') | n.js:1:17:1:21 | './m' |
336365
| n.js:4:10:4:24 | require('./m2') | n.js:4:18:4:23 | './m2' |
366+
| protoclass.js:9:11:9:32 | this.me ... d(this) | protoclass.js:9:28:9:31 | this |
337367
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | reflection.js:7:20:7:21 | 19 |
338368
| reflection.js:7:1:7:22 | reflective call | reflection.js:7:20:7:21 | 19 |
339369
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | reflection.js:8:17:8:24 | [23, 19] |
@@ -349,6 +379,7 @@ test_getAnArgument
349379
| es2015.js:36:1:36:17 | sum(1, ...[2], 3) | es2015.js:36:16:36:16 | 3 |
350380
| n.js:1:9:1:22 | require('./m') | n.js:1:17:1:21 | './m' |
351381
| n.js:4:10:4:24 | require('./m2') | n.js:4:18:4:23 | './m2' |
382+
| protoclass.js:9:11:9:32 | this.me ... d(this) | protoclass.js:9:28:9:31 | this |
352383
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | reflection.js:7:10:7:13 | null |
353384
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | reflection.js:7:16:7:17 | 23 |
354385
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | reflection.js:7:20:7:21 | 19 |
@@ -377,6 +408,8 @@ test_getACallee
377408
| m.js:3:1:3:18 | module.exports.f() | m.js:1:13:1:25 | function() {} |
378409
| n.js:2:1:2:5 | m.f() | m.js:1:13:1:25 | function() {} |
379410
| n.js:5:1:5:6 | m2.f() | m2.js:2:6:2:18 | function() {} |
411+
| protoclass.js:4:3:4:13 | this.init() | protoclass.js:7:20:11:1 | functio ... m();\\n} |
412+
| protoclass.js:8:3:8:15 | this.method() | protoclass.js:13:22:13:34 | function() {} |
380413
| reflection.js:7:1:7:22 | reflective call | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
381414
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | reflection.js:5:15:5:39 | functio ... n 56; } |
382415
| reflection.js:8:1:8:25 | reflective call | reflection.js:1:1:3:1 | functio ... x+y;\\n} |
@@ -430,6 +463,10 @@ test_getCalleeName
430463
| n.js:2:1:2:5 | m.f() | f |
431464
| n.js:4:10:4:24 | require('./m2') | require |
432465
| n.js:5:1:5:6 | m2.f() | f |
466+
| protoclass.js:4:3:4:13 | this.init() | init |
467+
| protoclass.js:8:3:8:15 | this.method() | method |
468+
| protoclass.js:9:11:9:32 | this.me ... d(this) | bind |
469+
| protoclass.js:10:3:10:5 | m() | m |
433470
| reflection.js:4:5:4:12 | sneaky() | sneaky |
434471
| reflection.js:7:1:7:22 | add.cal ... 23, 19) | call |
435472
| reflection.js:8:1:8:25 | add.app ... 3, 19]) | apply |
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,89 @@
1+
| ChatListScreen.js:3:1:5:1 | instance of function foo | ChatListScreen.js:3:1:5:1 | instance of function foo |
2+
| a.js:3:8:5:1 | instance of function setX | a.js:3:8:5:1 | instance of function setX |
3+
| a.js:15:1:17:1 | instance of function bump | a.js:15:1:17:1 | instance of function bump |
4+
| amd2.js:1:8:3:1 | instance of anonymous function | amd2.js:1:8:3:1 | instance of anonymous function |
5+
| amd3.js:1:24:4:1 | instance of anonymous function | amd3.js:1:24:4:1 | instance of anonymous function |
6+
| amd.js:1:31:6:1 | instance of anonymous function | amd.js:1:31:6:1 | instance of anonymous function |
7+
| arguments.js:1:2:3:1 | instance of anonymous function | arguments.js:1:2:3:1 | instance of anonymous function |
8+
| arguments.js:5:2:8:1 | instance of anonymous function | arguments.js:5:2:8:1 | instance of anonymous function |
9+
| arguments.js:10:2:14:1 | instance of anonymous function | arguments.js:10:2:14:1 | instance of anonymous function |
10+
| arguments.js:16:2:19:1 | instance of anonymous function | arguments.js:16:2:19:1 | instance of anonymous function |
11+
| arguments.js:22:2:28:1 | instance of anonymous function | arguments.js:22:2:28:1 | instance of anonymous function |
12+
| arguments.js:30:2:33:1 | instance of anonymous function | arguments.js:30:2:33:1 | instance of anonymous function |
13+
| c.js:3:1:5:1 | instance of function f | c.js:3:1:5:1 | instance of function f |
14+
| destructuring.js:1:1:4:1 | instance of function f | destructuring.js:1:1:4:1 | instance of function f |
115
| es2015.js:8:1:16:1 | instance of class Sub | es2015.js:1:11:6:1 | instance of class Sup |
16+
| es2015.js:18:1:20:1 | instance of function f | es2015.js:18:1:20:1 | instance of function f |
17+
| es2015.js:22:2:24:1 | instance of anonymous function | es2015.js:22:2:24:1 | instance of anonymous function |
18+
| es2015.js:31:2:35:1 | instance of anonymous function | es2015.js:31:2:35:1 | instance of anonymous function |
19+
| es2015.js:38:2:42:1 | instance of anonymous function | es2015.js:38:2:42:1 | instance of anonymous function |
20+
| es2015.js:44:2:47:1 | instance of anonymous function | es2015.js:44:2:47:1 | instance of anonymous function |
21+
| esLib.js:3:8:3:24 | instance of function foo | esLib.js:3:8:3:24 | instance of function foo |
22+
| f.js:1:13:1:25 | instance of anonymous function | f.js:1:13:1:25 | instance of anonymous function |
23+
| fundecls.js:1:2:10:1 | instance of anonymous function | fundecls.js:1:2:10:1 | instance of anonymous function |
24+
| fundecls.js:4:3:4:17 | instance of function f | fundecls.js:4:3:4:17 | instance of function f |
25+
| fundecls.js:8:5:8:19 | instance of function g | fundecls.js:8:5:8:19 | instance of function g |
26+
| globals.html:7:8:10:7 | instance of anonymous function | globals.html:7:8:10:7 | instance of anonymous function |
27+
| globals.html:16:8:19:7 | instance of anonymous function | globals.html:16:8:19:7 | instance of anonymous function |
28+
| globals.html:22:7:22:21 | instance of function x | globals.html:22:7:22:21 | instance of function x |
29+
| globals.html:26:23:26:69 | instance of anonymous function | globals.html:26:23:26:69 | instance of anonymous function |
30+
| h.js:1:8:1:22 | instance of function f | h.js:1:8:1:22 | instance of function f |
231
| instances.js:1:1:4:1 | instance of function A | instances.js:1:1:4:1 | instance of function A |
32+
| instances.js:3:14:3:26 | instance of anonymous function | instances.js:3:14:3:26 | instance of anonymous function |
33+
| instances.js:6:19:6:31 | instance of anonymous function | instances.js:6:19:6:31 | instance of anonymous function |
334
| instances.js:13:1:13:18 | instance of function SubA | instances.js:1:1:4:1 | instance of function A |
435
| instances.js:13:1:13:18 | instance of function SubA | instances.js:13:1:13:18 | instance of function SubA |
36+
| n.js:1:1:1:15 | instance of function f | n.js:1:1:1:15 | instance of function f |
37+
| n.js:2:1:2:15 | instance of function g | n.js:2:1:2:15 | instance of function g |
38+
| nestedImport.js:9:1:12:1 | instance of function tst | nestedImport.js:9:1:12:1 | instance of function tst |
39+
| nodeJsLib.js:1:18:1:43 | instance of function nodeJsModule | nodeJsLib.js:1:18:1:43 | instance of function nodeJsModule |
40+
| nodeJsLib.js:3:15:3:37 | instance of function nodeJsFoo | nodeJsLib.js:3:15:3:37 | instance of function nodeJsFoo |
41+
| objlit.js:2:9:2:21 | instance of anonymous function | objlit.js:2:9:2:21 | instance of anonymous function |
42+
| objlit.js:4:8:4:20 | instance of method baz | objlit.js:4:8:4:20 | instance of method baz |
43+
| objlit.js:10:2:12:1 | instance of anonymous function | objlit.js:10:2:12:1 | instance of anonymous function |
44+
| objlit.js:11:11:11:23 | instance of anonymous function | objlit.js:11:11:11:23 | instance of anonymous function |
45+
| objlit.js:23:2:48:1 | instance of anonymous function | objlit.js:23:2:48:1 | instance of anonymous function |
46+
| objlit.js:41:10:41:22 | instance of anonymous function | objlit.js:41:10:41:22 | instance of anonymous function |
547
| objlit.js:43:12:45:3 | object literal | file://:0:0:0:0 | null |
648
| objlit.js:43:12:45:3 | object literal | objlit.js:33:12:40:3 | object literal |
49+
| refinements.js:1:1:8:1 | instance of function f1 | refinements.js:1:1:8:1 | instance of function f1 |
50+
| refinements.js:10:1:24:1 | instance of function f2 | refinements.js:10:1:24:1 | instance of function f2 |
51+
| refinements.js:26:1:32:1 | instance of function f3 | refinements.js:26:1:32:1 | instance of function f3 |
52+
| refinements.js:34:1:40:1 | instance of function f4 | refinements.js:34:1:40:1 | instance of function f4 |
53+
| refinements.js:35:20:35:31 | instance of anonymous function | refinements.js:35:20:35:31 | instance of anonymous function |
54+
| refinements.js:42:1:56:1 | instance of function f5 | refinements.js:42:1:56:1 | instance of function f5 |
55+
| refinements.js:44:3:48:3 | instance of function inner | refinements.js:44:3:48:3 | instance of function inner |
56+
| refinements.js:58:1:62:1 | instance of function f6 | refinements.js:58:1:62:1 | instance of function f6 |
57+
| ts2.ts:1:10:1:22 | instance of anonymous function | ts2.ts:1:10:1:22 | instance of anonymous function |
58+
| tst2.js:3:2:5:1 | instance of anonymous function | tst2.js:3:2:5:1 | instance of anonymous function |
59+
| tst.js:1:1:39:1 | instance of function tst | tst.js:1:1:39:1 | instance of function tst |
60+
| tst.js:15:12:15:23 | instance of function xd | tst.js:15:12:15:23 | instance of function xd |
61+
| tst.js:42:1:44:1 | instance of function nonstrict | tst.js:42:1:44:1 | instance of function nonstrict |
62+
| tst.js:46:1:49:1 | instance of function strict | tst.js:46:1:49:1 | instance of function strict |
63+
| tst.js:51:1:57:1 | instance of function capturedFn | tst.js:51:1:57:1 | instance of function capturedFn |
64+
| tst.js:52:3:52:24 | instance of function captured | tst.js:52:3:52:24 | instance of function captured |
65+
| tst.js:53:3:55:3 | instance of function capturing | tst.js:53:3:55:3 | instance of function capturing |
66+
| tst.js:59:2:62:1 | instance of anonymous function | tst.js:59:2:62:1 | instance of anonymous function |
67+
| tst.js:64:2:66:1 | instance of anonymous function | tst.js:64:2:66:1 | instance of anonymous function |
68+
| tst.js:68:2:70:1 | instance of anonymous function | tst.js:68:2:70:1 | instance of anonymous function |
69+
| tst.js:72:2:76:1 | instance of function s | tst.js:72:2:76:1 | instance of function s |
70+
| tst.js:78:2:82:1 | instance of anonymous function | tst.js:78:2:82:1 | instance of anonymous function |
71+
| tst.js:84:2:87:1 | instance of anonymous function | tst.js:84:2:87:1 | instance of anonymous function |
72+
| tst.js:89:2:92:1 | instance of anonymous function | tst.js:89:2:92:1 | instance of anonymous function |
73+
| tst.js:94:2:104:1 | instance of anonymous function | tst.js:94:2:104:1 | instance of anonymous function |
74+
| tst.js:95:3:97:3 | instance of function inner | tst.js:95:3:97:3 | instance of function inner |
75+
| tst.js:106:2:109:1 | instance of anonymous function | tst.js:106:2:109:1 | instance of anonymous function |
76+
| tst.js:111:1:113:1 | instance of function tst | tst.js:111:1:113:1 | instance of function tst |
77+
| tst.js:115:2:132:1 | instance of anonymous function | tst.js:115:2:132:1 | instance of anonymous function |
78+
| tst.js:116:12:118:3 | instance of anonymous function | tst.js:116:12:118:3 | instance of anonymous function |
79+
| tst.js:119:12:121:3 | instance of anonymous function | tst.js:119:12:121:3 | instance of anonymous function |
80+
| tst.js:122:12:124:3 | instance of anonymous function | tst.js:122:12:124:3 | instance of anonymous function |
81+
| tst.js:125:12:125:24 | instance of anonymous function | tst.js:125:12:125:24 | instance of anonymous function |
82+
| tst.js:126:12:130:3 | instance of anonymous function | tst.js:126:12:130:3 | instance of anonymous function |
83+
| tst.js:131:12:131:37 | instance of anonymous function | tst.js:131:12:131:37 | instance of anonymous function |
84+
| tst.js:134:1:142:1 | instance of function tst2 | tst.js:134:1:142:1 | instance of function tst2 |
85+
| tst.js:144:1:149:1 | instance of function tst3 | tst.js:144:1:149:1 | instance of function tst3 |
86+
| tst.js:151:1:162:1 | instance of function tst4 | tst.js:151:1:162:1 | instance of function tst4 |
87+
| tst.js:164:1:172:1 | instance of function tst5 | tst.js:164:1:172:1 | instance of function tst5 |
88+
| tst.ts:8:1:10:1 | instance of function setX | tst.ts:8:1:10:1 | instance of function setX |
89+
| with.js:1:1:17:1 | instance of function f | with.js:1:1:17:1 | instance of function f |

0 commit comments

Comments
 (0)