Bug 1843499 - Part 2: Rethrow with exception stack in for-of loop. r=iain
commit715c5967c73463f5df5627633f9d504a5dbb2c94
authorAndré Bargull <andre.bargull@gmail.com>
Mon, 22 Jan 2024 14:29:41 +0000 (22 14:29 +0000)
committerAndré Bargull <andre.bargull@gmail.com>
Mon, 22 Jan 2024 14:29:41 +0000 (22 14:29 +0000)
treeae0592d9093ef9fcc9e4f08ed95947f43f03a444
parent2b26436fa9cee5a36dad8e9ad1b33fcdbdf906fa
Bug 1843499 - Part 2: Rethrow with exception stack in for-of loop. r=iain

The exception stack trace is discarded when using the opcodes `JSOp::Exception`
and `JSOp::Throw`. This is visible when throwing values which aren't instances
of `ErrorObject`.

This happens for example in test262, because `Test262Error` isn't an `Error`
subclass.

Example using test262 assertions:
```
for (let value of [0]) {
  assert.throws(TypeError, () => {});  // This is line 2.

  assert.sameValue(value, 0);  // This is line 4.
}
```

Before this patch:
```
/tmp/a.js:4:10 uncaught exception: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
Stack:
  @/tmp/a.js:4:10
```

With this patch:
```
/tmp/test262-assert.js:104:9 uncaught exception: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
Stack:
  assert.throws@/tmp/test262-assert.js:104:9
  @/tmp/a.js:2:10
```

Differential Revision: https://phabricator.services.mozilla.com/D183563
js/src/frontend/ForOfLoopControl.cpp
js/src/frontend/TryEmitter.cpp
js/src/frontend/TryEmitter.h
js/src/jit-test/tests/basic/throw-exception-stack-location.js [new file with mode: 0644]