chakra-core / chakra-core/ChakraCore
Wrong stack trace in errors shown in combination of for..of loops and JsSetException
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
When throwing an error using JsSetException inside a for..of loop error.stack does point to the last line of the for loop instead of the line which has caused the real exception.
for..in however does work properly
throwing inside JavaScript works properly even inside for..of loop
try..catch and rethrow works properly
Example "for..of":
```javascript
1 function crash() {
2 Sys.CauseException();
3 }
4
5 for (let x of [1,2,3]) {
6 crash();
7 }
```
error.stack:
```
Error: Error invoking CLR method CauseException()
at Global code (test.js:6:2)
```
Example "for..in":
```javascript
1 function crash() {
2 Sys.CauseException();
3 }
4
5 for (let x in [1,2,3]) {
6 crash();
7 }
```
error.stack:
```
Error: Error invoking CLR method CauseException()
at crash (test.js:2:2)
at Global code (test.js:6:2)
```
Example "rethrow":
```javascript
1 function crash() {
2 try {
3 Sys.CauseException();
4 } catch(error) } { throw error; }
5 }
6
7 for (let x in [1,2,3]) {
8 crash();
9 }
```
error.stack:
```
Error: Error invoking CLR method CauseException()
at crash (test.js:4:19)
at Global code (test.js:8:2)`
```
throwing the error in C#:
```csharp
var error = JavaScriptValue.CreateError(JavaScriptValue.FromString("Error invoking CLR method CauseException()"));
JavaScriptContext.SetException(error);
return JavaScriptValue.Invalid;
```
Contributor guide
Assessment
This issue has not been assessed yet.