Migration to Rhino broke Nashorn scripts

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Migration to Rhino broke Nashorn scripts

Postby buddy.robbins@linquest.com » Wed Jan 25, 2023 2:12 pm

I'm using MagicDraw/Cameo's Scripting engine to create Role-based UI's for non-SysML users. They were developed (successfully) using Nashorn, but the newest Cameo is using Rhino. The migration breaks all of my scripts.
The script file contains functions and global variables (holding state info), and also creates the JDialog box with components (JButton). The button has a listener, but I am unable to reference the global variables and functions.

Code: Select all
/* Short Example, assume the JavaImporter has the write java classes*/
var _myVariable = 12;
function _myFunction(){ return true;}
function doFunction(){
   var panel = new JPanel();
   var dialog = new Dialog();
   dialog.setConentPane(panel);
   var btnSubmit = new JButton("submit");
   panel.add(btnSubmit);
   btnSubmit.addActionListener( new ActionListener(){
      actionPerformed: function(e){
         if( _myFunction() ){ /* <-- breaks here */
            _myVariable += 1; /* <-- breaks here */
         }
      }
   });
}

doFunction();


This would run under Javascript Nashorn, but in Rhino it errors out because _myFunction and _myVariable are undefined.
I tried to extend the ActionListener so I could pass in the global object, but examining the global object, it looks like I won't get any state info, only the script code.
Any Ideas how to access the globals?
buddy.robbins@linquest.com
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Fri Jul 23, 2021 11:14 am

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests