Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-1111

RhinoJavaScriptEngine does not preserve scope between eval()s

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Scripting JavaScript 2.0.4
    • Scripting
    • None

    Description

      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

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            cziegeler Carsten Ziegeler
            vramdal Vidar Skauge Ramdal
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment