JS-Interpreter icon indicating copy to clipboard operation
JS-Interpreter copied to clipboard

Feature/try catch

Open hath995 opened this issue 8 years ago • 6 comments

Tried to implement try, catch, finally. It captures the correct control flow. I added some helper methods for testing as well as some tweaks so I could run the tests using nodejs and mocha.

~~I haven't quite got the behavior right on the attaching and populating the scope needed for the catch block.~~ Edit: grabbed the right scope code for catch blocks from master and added it to this implementation, and it fixed the last test.

hath995 avatar May 01 '16 00:05 hath995

I don't understand how this differs from our existing try/catch/finally implementation. For instance, you add a stepCatchClause function at line 2644, overwriting the one already at line 2163. Does the existing implementation have bugs?

NeilFraser avatar May 01 '16 06:05 NeilFraser

I started this a couple months back when it wasn't implemented, then put it down for a while. I pulled from master and saw a stepTry and stepCatch had been implemented and I thought I would post my implementation in case it was useful. It seems like it was too late.

hath995 avatar May 01 '16 06:05 hath995

A related question I have is, do you have a test harness that you're using with the interpreter or are you manually testing bit of code?

hath995 avatar May 01 '16 07:05 hath995

Actually, I branched off master and added in my test harness and many tests break. It looks like the cases of returning or continuing from within in a try/catch block are not handled correctly. There was also an infinite loop in a test of rethrowing.

hath995 avatar May 01 '16 07:05 hath995

The tests I use are the unit tests for other projects. If one can load the other project and run their own unit tests, then that exercises the interpreter pretty well. My regular tests are from my other projects, Diff Match Patch, and the Blockly generators. But any projects are good, as long as they don't rely on DOM methods.

NeilFraser avatar May 06 '16 10:05 NeilFraser

I asked just because without the tests available internally, I think it's difficult to confidently contribute. Implementing try/catch/finally, was pretty tricky so I grabbed a lot of these tests from https://github.com/tc39/test262/tree/es5-tests and they covered plenty of weird situations which I would not have thought to cover initially.

hath995 avatar May 06 '16 14:05 hath995