Igor Bukanov wrote:
Igor Bukanov wrote:

Ugo Cei wrote:

Igor Bukanov wrote:

http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working patch against Rhino CVS from mozilla.org to enable Continuation support there.




What am I supposed to do if I want to play with it?


...

2) Do a cvs checkout and build since your patch is already applied?


Use this option.


The attached patch against cocoon-2.1.5.1 simplifies "playing": it changes Rhino bindings to use "org.mozilla.javascript.Function" instead of "org.mozilla.javascript.continuations.Continuation" to refer to script Continuation objects.


In Rhino from mozilla.org Continuation class is package-private and implemented in a very different way compared with Rhino from cocondev.org. On the other hand the class in both versions implements Function interface and since the bindings in Cocoon use only functionality available through this interface the patch minimize the amount of code that has to be modified to use Rhino from mozilla.org.


And here is a patch to alter cocoon-2.1.5.1 to use Rhino from mozilla.org.

The patch assumes that rhino1.5r4-continuations-20040228.jar is replaced by rhino1_6R1pre.jar which should be produced by checking out the very latest CVS sources from mozilla.org, building js.jar and moving that to lib/core as rhino1_6R1pre.jar.

Regards, Igor
Sat Sep 25 00:35:28 CEST 2004  [EMAIL PROTECTED]
  * Using Rhino from mozilla.org

Fri Sep 24 19:08:03 CEST 2004  [EMAIL PROTECTED]
  * init

diff -rN -ud cocoon-2.1.5.1-old/src/blocks/petstore/java/org/apache/cocoon/components/flow/javascript/ScriptableResult.java cocoon-2.1.5.1-new/src/blocks/petstore/java/org/apache/cocoon/components/flow/javascript/ScriptableResult.java
--- cocoon-2.1.5.1-old/src/blocks/petstore/java/org/apache/cocoon/components/flow/javascript/ScriptableResult.java	2004-09-25 01:18:08.000000000 +0200
+++ cocoon-2.1.5.1-new/src/blocks/petstore/java/org/apache/cocoon/components/flow/javascript/ScriptableResult.java	2004-09-24 23:27:45.000000000 +0200
@@ -21,7 +21,6 @@
 
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.JavaScriptException;
-import org.mozilla.javascript.NotAFunctionException;
 import org.mozilla.javascript.PropertyException;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
@@ -60,7 +59,7 @@
 
     ScriptableResult(Scriptable scope, 
                      ResultSet rs, int startRow, int maxRows) 
-        throws SQLException, PropertyException, NotAFunctionException, JavaScriptException {
+        throws SQLException, PropertyException, JavaScriptException {
         Context cx = Context.getCurrentContext();
         Scriptable rowMap = cx.newObject(scope, "Array");
         put("rows", this, rowMap);
diff -rN -ud cocoon-2.1.5.1-old/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java cocoon-2.1.5.1-new/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
--- cocoon-2.1.5.1-old/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java	2004-09-25 01:18:08.000000000 +0200
+++ cocoon-2.1.5.1-new/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java	2004-09-24 23:15:58.000000000 +0200
@@ -52,6 +52,7 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ContextFactory;
 import org.mozilla.javascript.EcmaError;
 import org.mozilla.javascript.EvaluatorException;
 import org.mozilla.javascript.Function;
@@ -107,9 +108,12 @@
      */
     public static final String USER_GLOBAL_SCOPE = "FOM JavaScript GLOBAL SCOPE";
 
-    // This is the only optimization level that supports continuations
-    // in the Christoper Oliver's Rhino JavaScript implementation
-    static int OPTIMIZATION_LEVEL = -2;
+    private static final MyContextFactory 
+        contextFactory = new MyContextFactory();
+    
+    static {
+        ContextFactory.initGlobal(contextFactory);
+    }
 
     // the postfix of the resulting file streamed into the same directory as
     // the basescript
@@ -142,6 +146,30 @@
      */
     List topLevelScripts = new ArrayList();
 
+    private static class MyContextFactory extends ContextFactory
+    {
+        protected boolean hasFeature(Context cx, int featureIndex)
+        {
+            switch (featureIndex) {
+              case Context.FEATURE_INTERPRETER_CONTINUATIONS:
+                return true;
+            }
+            return super.hasFeature(cx, featureIndex);
+        }
+        
+        protected void onContextCreated(Context cx)
+        {
+            super.onContextCreated(cx);
+
+            // Force interpretation mode
+            cx.setOptimizationLevel(-1);
+            
+            cx.setGeneratingDebug(true);
+            
+            cx.setCompileFunctionsWithDynamicScope(true);
+        }
+    }
+
     class ScriptSourceEntry {
         final private Source source;
         private Script script;
@@ -204,18 +232,15 @@
             db.pack();
             java.awt.Dimension size =
                 java.awt.Toolkit.getDefaultToolkit().getScreenSize();
-            size.width *= 0.75;
-            size.height *= 0.75;
-            db.setSize(size);
+            db.setSize(size.width * 3 / 4, size.height * 3 / 4);
             db.setExitAction(new Runnable() {
                     public void run() {
                         db.setVisible(false);
                     }
                 });
-            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
             db.setVisible(true);
             debugger = db;
-            Context.addContextListener(debugger);
+            db.attachTo(contextFactory);
         }
         return debugger;
     }
@@ -267,9 +292,6 @@
             getDebugger().doBreak();
         }
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setCompileFunctionsWithDynamicScope(true);
-        context.setGeneratingDebug(true);
         // add support for Rhino objects to JXPath
         JXPathIntrospector.registerDynamicClass(org.mozilla.javascript.Scriptable.class,
                                                 ScriptablePropertyHandler.class);
@@ -587,9 +609,6 @@
         throws Exception
     {
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setGeneratingDebug(true);
-        context.setCompileFunctionsWithDynamicScope(true);
         context.setErrorReporter(errorReporter);
         AO_FOM_Cocoon cocoon = null;
         Scriptable thrScope = getSessionScope();
@@ -667,9 +686,6 @@
         }
 
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setGeneratingDebug(true);
-        context.setCompileFunctionsWithDynamicScope(true);
 
         // Obtain the continuation object from it, and setup the
         // FOM_Cocoon object associated in the dynamic scope of the saved
diff -rN -ud cocoon-2.1.5.1-old/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java cocoon-2.1.5.1-new/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
--- cocoon-2.1.5.1-old/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java	2004-09-25 01:18:09.000000000 +0200
+++ cocoon-2.1.5.1-new/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java	2004-09-24 23:04:54.000000000 +0200
@@ -58,6 +58,7 @@
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.SourceValidity;
 import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ContextFactory;
 import org.mozilla.javascript.EcmaError;
 import org.mozilla.javascript.EvaluatorException;
 import org.mozilla.javascript.Function;
@@ -99,9 +100,12 @@
      */
     public static final String USER_GLOBAL_SCOPE = "FOM JavaScript GLOBAL SCOPE";
 
-    // This is the only optimization level that supports continuations
-    // in the Christoper Oliver's Rhino JavaScript implementation
-    static int OPTIMIZATION_LEVEL = -2;
+    private static final MyContextFactory 
+        contextFactory = new MyContextFactory();
+    
+    static {
+        ContextFactory.initGlobal(contextFactory);
+    }
 
     /**
      * When was the last time we checked for script modifications. Used
@@ -136,6 +140,30 @@
     protected ServiceManager getServiceManager() {
         return manager;
     }
+    
+    private static class MyContextFactory extends ContextFactory
+    {
+        protected boolean hasFeature(Context cx, int featureIndex)
+        {
+            switch (featureIndex) {
+              case Context.FEATURE_INTERPRETER_CONTINUATIONS:
+                return true;
+            }
+            return super.hasFeature(cx, featureIndex);
+        }
+        
+        protected void onContextCreated(Context cx)
+        {
+            super.onContextCreated(cx);
+
+            // Force interpretation mode
+            cx.setOptimizationLevel(-1);
+            
+            cx.setGeneratingDebug(true);
+            
+            cx.setCompileFunctionsWithDynamicScope(true);
+        }
+    }
 
     class MyClassRepository implements CompilingClassLoader.ClassRepository {
 
@@ -224,10 +252,9 @@
                         db.setVisible(false);
                     }
                 });
-            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
             db.setVisible(true);
             debugger = db;
-            Context.addContextListener(debugger);
+            db.attachTo(contextFactory);
         }
         return debugger;
     }
@@ -273,9 +300,6 @@
             getDebugger().doBreak();
         }
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setCompileFunctionsWithDynamicScope(true);
-        context.setGeneratingDebug(true);
         // add support for Rhino objects to JXPath
         JXPathIntrospector.registerDynamicClass(Scriptable.class,
                                                 ScriptablePropertyHandler.class);
@@ -657,9 +681,6 @@
     public void callFunction(String funName, List params,
                              Redirector redirector) throws Exception {
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setGeneratingDebug(true);
-        context.setCompileFunctionsWithDynamicScope(true);
         context.setErrorReporter(errorReporter);
         ThreadScope thrScope = getSessionScope();
         synchronized (thrScope) {
@@ -743,9 +764,6 @@
         }
 
         Context context = Context.enter();
-        context.setOptimizationLevel(OPTIMIZATION_LEVEL);
-        context.setGeneratingDebug(true);
-        context.setCompileFunctionsWithDynamicScope(true);
 
         // Obtain the continuation object from it, and setup the
         // FOM_Cocoon object associated in the dynamic scope of the saved

Reply via email to