chakra-core / chakra-core/ChakraCore

Debugger: Support detecting pending promise reactions for "break on uhandled exceptions"

Open
#5,371 0 comments 0 reactions 0 assignees View on GitHub
Task
Dominant language
JavaScript
Stars
9.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

For reference, see
- Throw in async function after await is not caught by debugger #4630
- Debugger: Add support for breaking in debugger on unhandled promise rejection #5370
- fixing issue where "uncaught" exceptions in promises wouldn't notify debugger #5328

Currently, when we resolve a promise with a thenable, we defer the call the to the thenable's then() method by putting a task in the queue. This is by-design wrt the spec. However, this results in some undesired behavior wrt breaking on uhandled promise rejections.

Specifically, this code:
```javascript
function f1() {
let promiseA = new Promise((resolveA, rejectA) => {
let promiseB = Promise.resolve(true).then(() => {
throw new Error('error for handledPromiseRejection9_bugbug');
});
resolveA(promiseB);
});
return promiseA;
}

f1().catch((e) => {
});
```
will trigger a 2nd-chance exception break on the throw because we don't yet know about the pending hookup of handlers in the `.catch` block, as that's pending in the queue.

The fix here is to add some logic to keep track of the pending hookup on the thenable, and then inspect that the reactions of that thenable when the throw happens.

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.