Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make exceptions work across Java/JavaScript boundary
The essence of the change is, instead of throwing subclasses of Java Throwable class in generated throw statements, we now throw the backing JavaScript error object so the generated code looks like this: try { throw new SomeJavaException.backingJsObject; // Exceptions.unwrap } catch(e) { e = Exceptions.wrap(e); if (instanceof(e, SomeJavaException_ID)) { // catch block for SomeJavaException } // other catch blocks... else { throw e.backingJsObject; // Exceptions.unwrap } As the propagated thrown object is a real JavaScript error, it plays better with the browser dev tools and JavaScript callers (which become more essential due to JsInterop). There are two potentially breaking semantic changes with the patch: - If the original thrown object encapsulated by JavaScriptException is not a JavaScript Error (e.g. a string as you can do that in JavaScript), we no longer try to auto-fill the stacktrace by other means. The developers needs to call fillInStackTrace in that case. I think this we was already the behavior pre GWT 2.6 or 2.7 (see the original javadoc that was missed) and preserving the newer behavior in the new design causes extra complications. - If you catch the exception in JSNI and pass it back to Java, it is not a Java object anymore. This is unlikely to be a real issue in practice. The patch is also breaks GIN as it uses its own hacky class loader to load super-sourced versions of the files and ends up trying to load java.lang.JsException which is forbidden by java due to package name. I fixed GIN but this could be also worked around in released versions by setting a compiler flag: -setProperty gin.classloading.exceptedPackages=com.google.gwt.core.client, com.google.gwt.core.client.impl Change-Id: Id21c182078075ca19bb0953136a8b9136adcba63 Review-Link: https://gwt-review.googlesource.com/#/c/14030/
- Loading branch information
Showing
22 changed files
with
297 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
user/src/com/google/gwt/core/client/impl/JavaScriptExceptionBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
/* | |||
* Copyright 2015 Google Inc. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.google.gwt.core.client.impl; | |||
|
|||
/** | |||
* A helper so that we can change the parent of JavaScriptException via super-source. Otherwise we | |||
* would need to copy whole content of the class and also dev mode would choke. | |||
*/ | |||
public class JavaScriptExceptionBase extends RuntimeException { | |||
public JavaScriptExceptionBase(Object e) { | |||
super(); | |||
} | |||
} |
Oops, something went wrong.