最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ChromeEdge crashing with error code: STATUS_BREAKPOINT. Only happens when debugging a specific "for of&

programmeradmin5浏览0评论

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>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论