From f9309cec0b015ea25f5e118904934a7af07f4e1e Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Tue, 12 Mar 2024 13:29:34 +0100 Subject: [PATCH 1/2] JS: Add tests before #15823 changes --- .../classes/VerifyAssertions.expected | 4 +++ .../ql/test/ApiGraphs/classes/classes.js | 21 +++++++++++++++ .../TypeTracking/TypeTracking.expected | 3 +++ .../TypeTracking/implicit-receiver.js | 27 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js diff --git a/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected b/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected index e69de29bb2d1..03f159832fb6 100644 --- a/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected +++ b/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected @@ -0,0 +1,4 @@ +| classes.js:31:28:31:122 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("MyThirdStream") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | +| classes.js:33:37:33:131 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("MyThirdStream") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | +| classes.js:40:28:40:112 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("bar") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | +| classes.js:45:26:45:110 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("bar") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | diff --git a/javascript/ql/test/ApiGraphs/classes/classes.js b/javascript/ql/test/ApiGraphs/classes/classes.js index f4eb7023262d..29e7d223247b 100644 --- a/javascript/ql/test/ApiGraphs/classes/classes.js +++ b/javascript/ql/test/ApiGraphs/classes/classes.js @@ -25,3 +25,24 @@ MyOtherStream.prototype.instanceProp = 1; /* def=moduleImport("classes").getMemb MyOtherStream.classProp = 1; /* def=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getMember("classProp") */ module.exports.MyOtherStream = MyOtherStream; + + +// function-style class without .prototype reference +function MyThirdStream() { /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */ +} +let instance = new MyThirdStream(); /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */ + +module.exports.MyThirdStream = MyThirdStream; + + +// function-style class without .prototype reference (through global variable) +(function(f) { + foo.bar = function() { /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */ + } +})(foo = foo || {}); + +(function(f) { + let x = new f.bar(); /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */ +})(foo = foo || {}); + +module.exports.bar = foo.bar; diff --git a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected index e69de29bb2d1..4ae2de157b3e 100644 --- a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected +++ b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected @@ -0,0 +1,3 @@ +| implicit-receiver.js:8:22:8:52 | // trac ... ver-obj | Failed to track implicit-receiver-obj here. | +| implicit-receiver.js:9:24:9:84 | // trac ... er-prop | Failed to track implicit-receiver-obj here. | +| implicit-receiver.js:9:24:9:84 | // trac ... er-prop | Failed to track implicit-receiver-prop here. | diff --git a/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js b/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js new file mode 100644 index 000000000000..447a3eb0e057 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js @@ -0,0 +1,27 @@ +import 'dummy'; + +let trackedProp = "implicit-receiver-prop"; // name: implicit-receiver-prop + +function factory() { + let obj = unknown(); // name: implicit-receiver-obj + obj.foo = function() { + track(this); // track: implicit-receiver-obj + track(this.x); // track: implicit-receiver-obj track: implicit-receiver-prop + } + return obj; +} +let obj = factory(); +obj.x = trackedProp; + + +function factory2() { + let obj2 = { // name: implicit-receiver-obj2 + foo: function() { + track(this); // track: implicit-receiver-obj2 + track(this.x); // track: implicit-receiver-obj2 track: implicit-receiver-prop + } + } + return obj2; +} +let obj2 = factory2() +obj2.x = trackedProp; From c82f5dad567e2bb5cb10e7ed784bb690fe3b96d6 Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Tue, 12 Mar 2024 13:36:44 +0100 Subject: [PATCH 2/2] JS: show test changes after #15823 --- .../ql/test/ApiGraphs/classes/VerifyAssertions.expected | 4 ---- .../ql/test/library-tests/TypeTracking/TypeTracking.expected | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected b/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected index 03f159832fb6..e69de29bb2d1 100644 --- a/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected +++ b/javascript/ql/test/ApiGraphs/classes/VerifyAssertions.expected @@ -1,4 +0,0 @@ -| classes.js:31:28:31:122 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("MyThirdStream") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | -| classes.js:33:37:33:131 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("MyThirdStream") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | -| classes.js:40:28:40:112 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("bar") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | -| classes.js:45:26:45:110 | /* use= ... ce() */ | def moduleImport("classes").getMember("exports").getMember("bar") has no outgoing edge labelled getInstance(); it does have outgoing edges labelled getReceiver(). | diff --git a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected index 4ae2de157b3e..8b137891791f 100644 --- a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected +++ b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected @@ -1,3 +1 @@ -| implicit-receiver.js:8:22:8:52 | // trac ... ver-obj | Failed to track implicit-receiver-obj here. | -| implicit-receiver.js:9:24:9:84 | // trac ... er-prop | Failed to track implicit-receiver-obj here. | -| implicit-receiver.js:9:24:9:84 | // trac ... er-prop | Failed to track implicit-receiver-prop here. | +