chakra-core / chakra-core/ChakraCore

Debugger doesn't catch error thrown inside for...of loop immediately

Open
#3,685 9 comments 0 reactions 1 assignee Claimed by @akroshg View on GitHub
Bug Severity: 3
Dominant language
JavaScript
Stars
9.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I have JsDiagBreakOnExceptionAttributeUncaught enabled. Normally, errors are caught as soon as they're thrown. I've noticed, however, that if an error is thrown inside a for...of loop, entire stack frames can be unwound before the error is intercepted, losing valuable debugging information in the process. Here's an example, illustrated by my SSj debugger:

```
D:\src\spectacles-i>ssj dist
SSj X.X.X Sphere JavaScript debugger (x64)
the powerful symbolic JS debugger for Sphere
(c) 2015-2017 Fat Cerberus

starting 'D:/src/spectacles-i/dist/'... OK.
connecting to 127.0.0.1:1208... OK.
establishing communication... OK.
querying target... OK.
game: Spectacles: Bruce's Story
author: Fat Cerberus

=> # 0: [anon] at src/main.js:6
6 RequireSystemScript('persist.js');

src/main.js:6 [anon]
(ssj) c
UNCAUGHT: Error: The pig ate everything at 8:12
at Anonymous function (src/main.js:45:12)
at game (src/main.js:45:4)
=> # 0: [anon] at src/main.js:49
49 Console.initialize({ hotKey: Key.Tilde });

src/main.js:49 [anon]
(ssj) l 20
39
40 persist.init();
41
42 var evens = from([ 1, 2, 3, 4, 5, 6 ])
43 .where(it => it % 2 == 0);
44 for (let even of evens) {
45 (() => { throw new Error("The pig ate everything at 8:12"); })();
46 SSj.log(even);
47 }
48
=> 49 Console.initialize({ hotKey: Key.Tilde });
50 Console.defineObject('yap', null, {
51 'on': function() {
52 Sphere.Game.disableTalking = false;
53 Console.log("oh, yappy times are here again...");
54 },
55 'off': function() {
56 Sphere.Game.disableTalking = true;
57 Console.log("the yappy times are OVER!");
58 },

src/main.js:49 [anon]
(ssj) bt
=> # 0: [anon] at src/main.js:49
```

Notice the stacktrace of the Error object includes the arrow function, but the `backtrace` output does not, and the breakpoint actually triggered later, completely outside the for...of loop.

If I move the throw outside the loop, then it works as expected:

```
src/main.js:6 [anon]
(ssj) c
UNCAUGHT: Error: The pig ate everything at 8:12
at Anonymous function (src/main.js:42:11)
at game (src/main.js:42:3)
=> # 0: [anon] at src/main.js:42
42 (() => { throw new Error("The pig ate everything at 8:12"); })();

src/main.js:42 [anon]
(ssj) bt
=> # 0: [anon] at src/main.js:42
# 1: [anon] at src/main.js:42
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.