From 1e3f7aaaedeadfd0bb8e38cd995b262245368b2e Mon Sep 17 00:00:00 2001
From: "igor%mir2.org" Nothing significant yet!
+
+Automatic wrapping of JavaScript functions ans Java instances
+It is possible now to pass JavaScript function as argument to Java method expecting an interface with single method. Rhino automatically provides glue code to call the passed function when the interface method is called. It allows to simplify code that previously had to create explicit JavaAdapter objects.
+See Bugzilla 223435.
+
+For example, one can write now: +
+ var button = new javax.swing.JButton("My Button"); + button.addActionListener(function() { + java.lang.System.out.println("Button click"); + }); ++instead of +
+ var button = new javax.swing.JButton("My Button"); + button.addActionListener(new java.awt.event.ActionListener({ + actionPerformed : function() { + java.lang.System.out.println("Button click"); + } + }); ++which was necessary in the previous version of Rhino. + +
+For example, here is an extract from a Rhino shell session: +
+js> var x = { a: 1, b: 2, c: [1,2,3,4,5], f: function test() { return 1; }, o: { property1: "Test", proeprty2: new Date()}} +js> uneval(x) +({c:[1, 2, 3, 4, 5], o:{property1:"Test", proeprty2:(new Date(1076585338601))}, f:(function test() {return 1;}), a:1, b:2}) +js> x.toSource() +({c:[1, 2, 3, 4, 5], o:{property1:"Test", proeprty2:(new Date(1076585338601))}, f:(function test() {return 1;}), a:1, b:2}) +js> uneval(x.propertyThatDoesNotExist) +undefined ++ + + +
In Rhino 1.5R5 all script-related exceptions include source name of the script and number of the line that triggered exception. The exception class org.mozilla.javascript.JavaScriptException now is used only to represent exceptions explicitly thrown by scripts by JavaScript "throw" statement, it never wraps exceptions thrown by Java methods that called by scripts. Such exceptions are always wrapped now as org.mozilla.javascript.WrappedException. See Bugzilla 217584. +
+ ++In addition the new interface org.mozilla.javascript.Callable allows to execute scripts with JavaScript this keyword pointing to arbitrary object instead of defaulting to the scope object as exec method from org.mozilla.javascript.Script does. +
+ +The new class org.mozilla.javascript.optimizer.ClassCompiler provides simple API to compile JavaScript source into set of Java class files with the given set of compilation options. JavaScript Compiler was upgraded to use new API and the old API were deprecated. +
+ ++In Rhino 1.5R5 the default optimization mode generates only one class per script and all its functions where previously the optimizer generated additional class for each function definition in the script. It improves loading time for scripts and decreases memory usage especially for scripts with many function definitions. See Bugzilla 198086. +
+ ++The interpreted mode contains significantly less restrictions on size and complexity of the scripts and if the remaining restrictions are not satisfied, Rhino will report an exception instead of producing corrupted internal byte code. +See Bugzilla 225831. +
+ +