-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ScriptRuntime:throwCustomError to make it easier to re-throw Java exceptions #176
Comments
PS: I dremel'd something by reverting the suspicous commits: https://github.com/raimi/rhino/commit/219c06a6f30ea2afbdc7173cf90e945164ceca3c This fixes my problem but is wrong with regard to that one exception being thrown. https://github.com/raimi/rhino/commit/219c06a6f30ea2afbdc7173cf90e945164ceca3c#diff-5461f4051c38ef65beb8b329a22ad442R536 Heeeelp :) |
@raimi To check that you don't create EcmaError in your java code, can you please apply this commit and run your tests again? There I replaced the names of EcmaError in strings with values from NativeErrors enum. |
a-ha, that's it. With your commit applied my java code doesn't compile anymore :) I have an instance of "throw ScriptRuntime.constructError(className, msg);" in my code. That's the culprit. I wasn't aware of that situation: The Java code tries to throw an Exception object that is defined in the JavaScript world - and all of that has to be mangled through the Java API... Bottom line:
Thanks, Internet! |
Dear Internet, @sainaen , @gbrail ! I think that I figured out what the problem is: For ages I've been throwing custom-defined JS-Objects (called "Exception" and some sub-types) from the Java side. Those objects behaved like native "Error" objects (duck typing), at least with regards to what I wanted from them. @anba's commit disallowed the throwing of arbitrary objects for good reason, @sainaen's commit makes sure this is enforced in the java-world. I hereby try to contribute a little patch: https://github.com/raimi/rhino/commit/b3234c4fe3280a204da031a0b7c70a5b11dcb600 - in this branch together with the other stuff: https://github.com/raimi/rhino/commits/issue_176 This introduces a java-way of throwing js-objects, given their constructor name (same as the very old implementation used to allow). It uses the same arguments, so that an implementation has access to the source position etc. My test suite is still running, i'll see if this breaks anything else in existing code :) Am I missing something or may this be the right thing to do? |
Yes, I think that opening up a pull request is a good way to handle this. The change looks reasonable to me. |
@raimi |
Thanks for tracking this down and sticking with it! |
I maintain a largish application with lots of java/rhino-interwoven code. Luckily we have a test suite wich showed us that something broke with 1.7.6 wich still worked with 1.7R5.
I can reproduce serveral occasions of this trace:
where XXX is a custom js-class that I use like "throw new XXX()". I suspect these commits:
9320d8c
15be937
ff0ef45
Unfortunately, I cannot reproduce the problem in a simple Rhino shell. This all may be my fault, as I use dynamic scopes and re-loading of js source files. I just post here to warn others for a possible change of semantics.
The above Exception occurs with this code:
...when foo() throws one of my XXX. Somehow it is an EcmaError here: https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ScriptRuntime.java#L3436 ...but that does not work out.
Does this ring a bell for somebody?
The text was updated successfully, but these errors were encountered: