On Sat, 22 Feb 2020 15:39:35 GMT, Rony G. Flatscher 
<github.com+60214806+rony...@openjdk.org> wrote:

> …9: FXMLLoader does not populate ENGINE_SCOPE Bindings with FILENAME and ARGV

OK, forgot to submit an explanatory text related to this fix. Posted [1] which 
explains the problem and the suggested solution for discussion. 

- This pull request relates to: 
<https://bugs.openjdk.java.net/browse/JDK-8234959>

- Brief background: the controller code for a FXML file can be written in
  any of the Java script languages that implement the javax.script framework
  introduced with Java 6

There are three possible types of script code definitions possible in fxml 
files:

1. in an empty script element where the source attribute denotes an external 
file
   that contains the code, e.g.:

     <fx:script source="somescript.rex" />

   This pull request uses the source attribute value as the filename.

   There are no arguments to be supplied.

2. text of a script element, e.g.:

      <fx:script>say 'code executed at:' .dateTime~new </fx:script>

   or:

      <fx:script><![CDATA[say 'code executed at:' .dateTime~new ]]></fx:script>

   This pull request uses the fxml-filename appended with the string
   "-script_starting_at_line_" and the starting line number of the code.

   There are no arguments to be supplied.

   Reasonings:

        - in the case that multiple fxml files employ script code it is 
important
          to learn the name of the fxml file that hosts the code that gets 
executed

        - the dash after the fxml filename is meant to ease parsing

        - in the case that there are multiple fx:script elements in a fxml file
          with inline code it is important to learn in which line the code 
starts
          that gets executed

        - the decorated filename thereby becomes self documentary and 
unambiguous to
          the script code developer when debugging


3. PCDATA text in an event attribute which by convention starts with "on", e.g. 
"onAction":

   <fx:button text="Hi!" onAction="say 'click at:' .dateTime~new', 
event='arg(1)~toString" />

   This pull request uses the fxml-filename appended with a dash "-", appended 
with the
   name of the event attribute, the string 
"_attribute_in_element_ending_at_line_" and
   the ending line number of the element.

   In the ScriptEventHandler constructor the decorated filename gets stored in 
addition
   to the script and the scriptEngine.

   Each time the event fires the event object argument will be stored in a copy 
of the
   engineBindings with the index EVENT_KEY as well as with a single capacity 
Object array
   stored with the index ScriptEngine.ARGV and the filename with the index
   ScriptEngine.FILENAME. The script's evaluation will get this engineBindings 
as
   its ENGINE_SCOPE Bindings supplied.

   Reasonings:

        - in the case that multiple fxml files employ script code it is 
important
          to learn the name of the fxml file that hosts the event code that gets
          executed

        - the dash after the fxml filename is meant to ease parsing

        - in the case that there are multiple event attributes in elements
          in a fxml file it is important to learn which event attribute in which
          element hosts the event script code that gets executed

        - the decorated filename thereby becomes self documentary and 
unambiguous to
          the script code developer when debugging

        - the structural change to the constructor (adding the decorated 
filename as
          a third argument) of the private static ScriptEventHandler class is 
confined
          to the FXMLLoader class and has no side effects

[1] "Ad suggested test unit for 'JDK-8234959 FXMLLoader does not populate 
ENGINE_SCOPE Bindings with FILENAME and ARGV'": 
<https://mail.openjdk.java.net/pipermail/openjfx-dev/2020-February/025104.html>

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

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

Reply via email to