You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Vidar S. Ramdal (JIRA)" <ji...@apache.org> on 2009/09/16 10:53:58 UTC

[jira] Created: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

RhinoJavaScriptEngine does not preserve scope between eval()s
-------------------------------------------------------------

                 Key: SLING-1111
                 URL: https://issues.apache.org/jira/browse/SLING-1111
             Project: Sling
          Issue Type: Bug
          Components: Scripting
    Affects Versions:  Scripting JavaScript 2.0.4
            Reporter: Vidar S. Ramdal
             Fix For: Scripting JavaScript 2.0.6


The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().

So that:
RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
engine.eval("var f = 1");
engine.eval("f += 1");
... fails with a "ReferenceError: "f" is not defined"

The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 

I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
So please review this.

More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carsten Ziegeler updated SLING-1111:
------------------------------------

    Fix Version/s:     (was: Scripting JavaScript 2.0.6)
                   Scripting JavaScript 2.0.8

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>             Fix For: Scripting JavaScript 2.0.8
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carsten Ziegeler resolved SLING-1111.
-------------------------------------

    Resolution: Fixed

Thanks for the patch - it looks good to me and I've applied it in revision 931522 (I really wanted to apply a bug with this number :) )

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>            Assignee: Carsten Ziegeler
>             Fix For: Scripting JavaScript 2.0.8
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Vidar S. Ramdal (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Vidar S. Ramdal updated SLING-1111:
-----------------------------------

    Attachment: SLING-1111.patch

Patch and testcase

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>             Fix For: Scripting JavaScript 2.0.6
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Bertrand Delacretaz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12755960#action_12755960 ] 

Bertrand Delacretaz edited comment on SLING-1111 at 9/16/09 2:42 AM:
---------------------------------------------------------------------

Just a minor comment about your patch, we usually don't do @author tags...mainly to avoid people contacting you privately when they read the code later ;-)

Apart from that the patch looks ok to me - I'm no expert in Rhino scopes, but it makes sense to couple the scope to a given engine. 

That's assuming each Sling request gets a new engine...do we have tests that demonstrate that?

      was (Author: bdelacretaz):
    Just a minor comment about your patch, we usually don't do @author tags...mainly to avoid people contacting you privately when the read the code later ;-)

Apart from that the patch looks ok to me - I'm no expert in Rhino scopes, but it makes sense to couple the scope to a given engine. 

That's assuming each Sling request gets a new engine...do we have tests that demonstrate that?
  
> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>             Fix For: Scripting JavaScript 2.0.6
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Bertrand Delacretaz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12755960#action_12755960 ] 

Bertrand Delacretaz commented on SLING-1111:
--------------------------------------------

Just a minor comment about your patch, we usually don't do @author tags...mainly to avoid people contacting you privately when the read the code later ;-)

Apart from that the patch looks ok to me - I'm no expert in Rhino scopes, but it makes sense to couple the scope to a given engine. 

That's assuming each Sling request gets a new engine...do we have tests that demonstrate that?

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>             Fix For: Scripting JavaScript 2.0.6
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Vidar S. Ramdal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12755966#action_12755966 ] 

Vidar S. Ramdal commented on SLING-1111:
----------------------------------------

Good catch about the @author - I haven't even added the Apache license header, so the javadoc comment must be replaced.

It seems that fmeschbe and cziegeler have commited most of the code in RhinoJavaScriptEngine, so maybe they could cast some light on the issue?

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>             Fix For: Scripting JavaScript 2.0.6
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (SLING-1111) RhinoJavaScriptEngine does not preserve scope between eval()s

Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-1111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carsten Ziegeler reassigned SLING-1111:
---------------------------------------

    Assignee: Carsten Ziegeler

> RhinoJavaScriptEngine does not preserve scope between eval()s
> -------------------------------------------------------------
>
>                 Key: SLING-1111
>                 URL: https://issues.apache.org/jira/browse/SLING-1111
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions:  Scripting JavaScript 2.0.4
>            Reporter: Vidar S. Ramdal
>            Assignee: Carsten Ziegeler
>             Fix For: Scripting JavaScript 2.0.8
>
>         Attachments: SLING-1111.patch
>
>
> The RhinoJavaScriptEngine does not preserve it scope, so that the scope is reset between each call to eval().
> So that:
> RhinoJavaScriptEngineFactory factory = new RhinoJavaScriptEngineFactory();
> ScriptEngine engine = factory.getScriptEngine();
> engine.eval("var f = 1");
> engine.eval("f += 1");
> ... fails with a "ReferenceError: "f" is not defined"
> The problem seems to be that "scope" is a local variable in RhinoJavaScriptEngine.eval(), while it should have been a class field. 
> I have prepared a patch and a test (coming up), but I'm not familiar with the script engine code, so the fix might very likely break other stuff.
> So please review this.
> More background: http://www.coderanch.com/t/460570/Other-JSE-JEE-APIs/java/javax-script-Save-state-scope

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.