cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript JavaScriptInterpreter.java
Date Sun, 23 Mar 2003 19:41:03 GMT
coliver     2003/03/23 11:41:03

  Modified:    src/java/org/apache/cocoon/components/flow/javascript
                        JavaScriptInterpreter.java
  Log:
  got debugger working again
  
  Revision  Changes    Path
  1.9       +49 -42    cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
  
  Index: JavaScriptInterpreter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JavaScriptInterpreter.java	20 Mar 2003 04:18:51 -0000	1.8
  +++ JavaScriptInterpreter.java	23 Mar 2003 19:41:03 -0000	1.9
  @@ -171,7 +171,34 @@
   
       JSErrorReporter errorReporter;
       boolean enableDebugger = false;
  -    org.mozilla.javascript.tools.debugger.Main debugger;
  +    /**
  +     * JavaScript debugger: there's only one of these: it can debug multiple
  +     * threads executing JS code.
  +     */
  +    static org.mozilla.javascript.tools.debugger.Main debugger;
  +
  +    static synchronized org.mozilla.javascript.tools.debugger.Main getDebugger() {
  +	if (debugger == null) {
  +            final org.mozilla.javascript.tools.debugger.Main db
  +                = new org.mozilla.javascript.tools.debugger.Main("Cocoon Flow Debugger");
  +            db.pack();
  +	    java.awt.Dimension size = 
  +		java.awt.Toolkit.getDefaultToolkit().getScreenSize();
  +	    size.width *= 0.75;
  +	    size.height *= 0.75;
  +            db.setSize(size);
  +            db.setExitAction(new Runnable() { 
  +                    public void run() { 
  +                        db.setVisible(false); 
  +                    } 
  +                });
  +	    db.setOptimizationLevel(OPTIMIZATION_LEVEL);
  +            db.setVisible(true);
  +            debugger = db;
  +            Context.addContextListener(debugger);
  +	}
  +	return debugger;
  +    }
   
       public void configure(Configuration config)
           throws ConfigurationException
  @@ -195,26 +222,11 @@
           throws Exception
       {
           if (enableDebugger) {
  -
               if (getLogger().isDebugEnabled()) {
                   getLogger().debug("Flow debugger enabled, creating");
               }
  -
  -            final org.mozilla.javascript.tools.debugger.Main db
  -                = new org.mozilla.javascript.tools.debugger.Main("Cocoon Flow Debugger");
  -            db.pack();
  -            db.setSize(600,460);
  -            db.setExitAction(new Runnable() { 
  -                    public void run() { 
  -                        db.setVisible(false); 
  -                    } 
  -                });
  -            db.setVisible(true);
  -            debugger = db;
  -            Context.addContextListener(debugger);
  -            debugger.doBreak();
  +	    getDebugger().doBreak();
           }
  -
           Context context = Context.enter();
           context.setOptimizationLevel(OPTIMIZATION_LEVEL);
           context.setCompileFunctionsWithDynamicScope(true);
  @@ -280,17 +292,15 @@
           if (session == null) {
               return null;
           }
  -
           Scriptable scope;
           HashMap userScopes = (HashMap)session.getAttribute(USER_GLOBAL_SCOPE);
   
           if (userScopes == null) {
               return null;
           }
  -
  -        scope = (Scriptable)userScopes.get(environment.getURIPrefix());
  -
  -        return scope;
  +	String uriPrefix = environment.getURIPrefix();
  +	scope = (Scriptable)userScopes.get(uriPrefix);
  +	return scope;
       }
   
       /**
  @@ -312,8 +322,9 @@
               userScopes = new HashMap();
               session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
           }
  -
  -        userScopes.put(environment.getURIPrefix(), scope);
  +	String uriPrefix = environment.getURIPrefix();
  +	System.out.println("set uriPrefix="+uriPrefix);
  +        userScopes.put(uriPrefix, scope);
       }
   
       public void removeSessionScope(Environment environment)
  @@ -429,6 +440,8 @@
           }
           thrScope.put(LAST_EXEC_TIME, thrScope, 
                        new Long(System.currentTimeMillis()));
  +	// Compile all the scripts first. That way you can set breakpoints
  +	// in the debugger before they execute.
           for (int i = 0, size = execList.size(); i < size; i++) {
               String sourceURI = (String)execList.get(i);
               ScriptSourceEntry entry = 
  @@ -440,12 +453,18 @@
               }
               // Compile the script if necessary
               Script script = entry.getScript(context, this.scope, needsRefresh);
  +        }
  +	// Execute the scripts if necessary
  +        for (int i = 0, size = execList.size(); i < size; i++) {
  +            String sourceURI = (String)execList.get(i);
  +            ScriptSourceEntry entry = 
  +                (ScriptSourceEntry)compiledScripts.get(sourceURI);
               long lastMod = entry.getSource().getLastModified();
  -            // Execute the script if necessary
  +            Script script = entry.getScript(context, this.scope, false);
               if (lastExecTime == 0 || lastMod > lastExecTime) {
                   script.exec(context, thrScope);
               } 
  -        }
  +	}
           return thrScope;
       }
   
  @@ -523,13 +542,7 @@
               Context context = Context.getCurrentContext();
               JSCocoon cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
               if (enableDebugger) {
  -                final Scriptable s = thrScope;
  -                debugger.setScopeProvider(
  -                                          new ScopeProvider()
  -                                              { public Scriptable getScope() {return s;}
}
  -                                          );
  -                if (!debugger.isVisible())
  -                    debugger.setVisible(true);
  +		getDebugger().setVisible(true);
               }
               int size = (params != null ? params.size() : 0);
               Object[] funArgs = new Object[size];
  @@ -590,14 +603,8 @@
           JSCocoon cocoon = jswk.getJSCocoon();
           cocoon.setContext(manager, environment);
           final Scriptable kScope = cocoon.getParentScope();
  -
  -        if (enableDebugger) {
  -            debugger.setScopeProvider(
  -                                      new ScopeProvider()
  -                                          { public Scriptable getScope() {return kScope;}
}
  -                                      );
  -            if (!debugger.isVisible())
  -                debugger.setVisible(true);
  +	if (enableDebugger) {
  +	    getDebugger().setVisible(true);
           }
   
           // We can now resume the processing from the state saved by the
  
  
  

Mime
View raw message