Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8089392

JavaScript2Java Bridge: the situations when a proper assignment cannot be performed should be reported

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: fx2.1
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Subcomponent:
      web

      Description

      JavaScript2Java Bridge permits to expose Java objects to JavaScript. As JavaScript is weakly typed, it doesn't care about types of assigned value and vairable which the value is assigned to during the assignment. Java, however, cannot allow this.
      Currently, when a value is assigned to a variable of incompatible type, a variable ends up with its original value changed to something meaningless (MIN_VALUE in case of integer), and no error is reported.
      Consider the following example with integer:
      WebEngine e; // Initialized somehow
      MyObject o = new MyObject(); // Has an integer field
      o.integerField = 3;
      e.addJavaScriptBinding("test", o);
      e.executeScript("test.integerField='tralala'"); // We assign string to integer field here, and JS sees no problem
      System.out.println(o.integerField); // o.integerField is now Integer.MIN_VALUE
      In my opinion, this situation should be reported (by throwing an exception, for example), and original value of a variable should not be damaged.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ilatyshe Irina Grineva (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported: