From 1e3f7aaaedeadfd0bb8e38cd995b262245368b2e Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Thu, 12 Feb 2004 18:13:00 +0000 Subject: [PATCH] Preparations for 1.5R5 --- js/rhino/docs/changes.html | 74 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/js/rhino/docs/changes.html b/js/rhino/docs/changes.html index 52392015c505..0f6bdf830191 100644 --- a/js/rhino/docs/changes.html +++ b/js/rhino/docs/changes.html @@ -1,7 +1,7 @@ - + Change Log @@ -13,7 +13,77 @@ Change Log for Significant Rhino Changes This is a log of significant changes since Rhino 1.5 Release 4. -

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. + +

Support for uneval()/toSource()

+Rhino now fully supports uneval() function and toSource() method which are extensions to ECMAScript available in SpiderMonkey. They return a string that can be passed to eval to reconstruct the original value when possible. It is guaranteed that uneval(eval(uneval(x))) == uneval(x) and in many cases more useful notion eval(uneval(x)) == deep copy of x holds. See Bugzilla 225465. +

+

+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
+
+

+ + +

Exception changes

+

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. +

+ +

Compiled scripts are scope independent

+Previously Rhino required a scope object in the compileReader method of org.mozilla.javascript.Context to compile script into org.mozilla.javascript.Script instances. Under some circumstances it was possible that this object would be stored in the resulting compiled script preventing reuse of the compiled form to execute the script against different scopes. Now all such cases are removed and compileReader and newly introduced compileString no longer take the scope argument. For compatibility the old form of compileReader is kept as a deprecated method. See Bugzilla 218440. +

+

+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. +

+ +

No static caching

+Rhino no longer caches generated classes and information about reflected Java classes in static objects. Instead such caches by default are initialized once per call to initStandardObjects of org.mozilla.javascript.Context but this can be overridden with explicit call to the associate method of org.mozilla.javascript.ClassCache if cache sharing is desired. The change allows to instantiate multiple Rhino runtime instances which would not interfere with each other and prevents memory leaks throw ever growing caches. + +

New API for compiling scripts into class files

+

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. +

+ +

Optimizer generates only one class per script

+

+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. +

+ +

Improved support for huge scripts

+

+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. +

+ +

back to top