RFR: 8238080: FXMLLoader: if script engines implement javax.script.Compilable compile scripts

Kevin Rushforth kcr at openjdk.java.net
Tue May 12 16:55:17 UTC 2020


On Wed, 22 Apr 2020 16:33:47 GMT, Rony G. Flatscher <github.com+60214806+ronyfla at openjdk.org> wrote:

>> This WIP adds the ability for a fallback in case compilation of scripts fails, in which case a warning gets issued
>> about this fact and evaluation of the script will be done without compilation. Because of the fallback scripts get
>> compiled with this version by default. It extends PR 187 <https://github.com/openjdk/jfx/pull/187>.  To further ease
>> spotting scripts that cause a ScriptException a message in the form of "filename: caused ScriptException" gets added to
>> the exception handling in either of the three locations: an error message, a stack trace or a wrap-up into a
>> RuntimeException (having three different kinds of reporting ScriptExceptions may be questioned, however none of these
>> tear down the FXML GUI).
>
> ============================ test units for: compile PI+fallback
> 
> tests/system/src/testscriptapp2/java/mymod/myapp2/FXMLScriptDeployment2Compile_Off.java
> ... use compile PI to set off compilation of scripts; each script code starts with "demo_02_"
> 
> tests/system/src/testscriptapp2/resources/mymod/myapp2/demo_02_off.fxml
> ... set compilation for scripts off ("<?compile false?>"), therefore no script gets compiled
> 
> ---
> 
> tests/system/src/testscriptapp2/java/mymod/myapp2/FXMLScriptDeployment2Compile_Off_On.java
> ... alternatively uses compile PI to turn compilation off and on; the script code starts alternatively with "demo_02_"
> and "RgfPseudoCompiledScript.eval(", depending on the state set with the PI
> tests/system/src/testscriptapp2/resources/mymod/myapp2/demo_02_off_on.fxml
> ... starts out explicitly with "<?compile false?>" switching the state after each element containing a script
> 
> ---
> 
>  tests/system/src/testscriptapp2/java/mymod/myapp2/FXMLScriptDeployment2Compile_On.java
>  ... no compile PI given, hence compilation of scripts is on; each script code starts with
>  "RgfPseudoCompiledScript.eval("
>  tests/system/src/testscriptapp2/resources/mymod/myapp2/demo_02_on.fxml
> ... no compile PI given, starts out to compile scripts by default
> 
> ---
> 
> tests/system/src/testscriptapp2/java/mymod/myapp2/FXMLScriptDeployment2Compile_On_Off.java
> ... alternatively uses compile PI to turn compilation on and off; the script code starts alternatively with
> "RgfPseudoCompiledScript.eval(", and "demo_02_" depending on the state set with the PI
> tests/system/src/testscriptapp2/resources/mymod/myapp2/demo_02_on_off.fxml
> ... starts out explicitly with "<?compile true?>" switching the state after each element containing a script (sometimes
> using PI "<?compile?>" to test setting it to true)
> ---
> 
> tests/system/src/testscriptapp2/java/mymod/myapp2/FXMLScriptDeployment2Compile_Fail_Compilation.java
> ... although compile scripts is on, none of the scripts get compiled as they all contain the string "FAIL COMPILATION"
> which causes RgfPseudoScriptEngineCompilable.compile(...) to throw a ScriptException causing the fallback to be used;
> all scripts therefore start with "demo_03_"
>  tests/system/src/testscriptapp2/resources/mymod/myapp2/demo_03_fail_compile.fxml
>  ... explicitly turns on compilation (which is on by default anyway), adds "FAIL COMPILATION" to all inline scripts and
>  to all external scripts with the filename that starts with "demo_03_"

I think the approach proposed in this PR is the best solution for this enhancement. Go ahead and remove the `WIP` from
the title, and we can proceed with the review.

The interface and behavior change will need to be specified in the API docs. This can be done by modifying the
[Introduction to
FXML](https://github.com/openjdk/jfx/blob/master/modules/javafx.fxml/src/main/docs/javafx/fxml/doc-files/introduction_to_fxml.html)
document. I recommend documenting the new behavior and `<?compile>` attribute somewhere in the
[Scripting](https://github.com/openjdk/jfx/blob/master/modules/javafx.fxml/src/main/docs/javafx/fxml/doc-files/introduction_to_fxml.html#L769)
section.

As discussed on the mailing list, this will need a CSR, which should include the changes to the docs.

-------------

PR: https://git.openjdk.java.net/jfx/pull/192


More information about the openjfx-dev mailing list