I'm having an issue with some code I'm trying to debug in Chrome/Edge. I think it's probably a bug, as it isn't happening with Firefox. I've managed to create a small test file that is causing others to experience the same issue. The code will run fine without debugging, it only crashes when you step through it. Weirdly, it only happens when I use a "for of" loop. A standard for loop, or the array's forEach function work fine.
My version of Chrome is: 134.0.6998.178 (Official Build) (64-bit)
This is the code causing the crash:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chrome Crash Test</title>
</head>
<body>
<script>
class Test {
constructor() {
// When this code is ran without debugging, it will work fine and print out two objects and a message.
// When it is ran with the debugger attached, it will crash the browser with error code "STATUS_BREAKPOINT" once you press Step Over
debugger;
// when debugger is over this line, press F10 and it will crash the browser if the "for of" loop is left in
const items = [{
canDrop: function () {
console.log(this);
}
}];
// if the for of loop is used, it will crash
for (const item of items) {
const myFunc = () => item.canDrop.call(this);
myFunc();
}
// if the for loop is used instead, it will not crash
for (let i = 0; i < items.length; i++) {
const item = items[i];
const myFunc = () => item.canDrop.call(this);
myFunc();
}
console.log('The code has ran');
}
}
var test = new Test();
</script>
</body>
</html>