JS: Add exception test case

This commit is contained in:
Asger F
2024-11-04 16:22:09 +01:00
parent 33b7ba41ca
commit 5ed362f7d6

View File

@@ -0,0 +1,65 @@
import 'dummy';
function e1() {
let array = [source('e1.1')];
try {
array.forEach(x => {
throw x;
});
array.forEach(x => {
throw source('e1.2');
});
} catch (err) {
sink(err); // $ hasValueFlow=e1.2 hasValueFlow=e1.1
}
}
function e2() {
let array = [source('e2.1')];
try {
array.unknown(x => {
throw x;
});
array.unknown(x => {
throw source('e2.2');
});
} catch (err) {
sink(err); // $ MISSING: hasValueFlow=e2.2
}
}
function e3() {
const events = getSomething();
try {
events.addEventListener('click', () =>{
throw source('e3.1');
});
events.addListener('click', () =>{
throw source('e3.2');
});
events.on('click', () =>{
throw source('e3.3');
});
events.unknownMethod('click', () =>{
throw source('e3.4');
});
} catch (err) {
sink(err); // $ MISSING: hasValueFlow=e3.4
}
}
function e4() {
function thrower(array) {
array.forEach(x => { throw x });
}
try {
thrower([source("e4.1")]);
} catch (e) {
sink(e); // $ hasValueFlow=e4.1
}
try {
thrower(["safe"]);
} catch (e) {
sink(e); // $ SPURIOUS: hasValueFlow=e4.1
}
}