When loading r.js Context.enter() is called 1 time more often than Context.exit()

58 views
Skip to first unread message

themi...@gmail.com

unread,
Feb 25, 2015, 10:02:45 AM2/25/15
to mozill...@googlegroups.com
Hi,
 
when I am loading r.js 2.1.16 with rhino, Context.enter() is called 1 time more often than Context.exit(), i.e. at the end after calling Context.exit() a last time I expect that Context.getCurrentContext() is null which is not the case.
 
This can be reproduced by loading the r.js. When you set breakpoint in Context.enter and Context.exit you see that enter is called one time more than Context.exit during the load of r.js.
 
You can reproduce it with following JUnit test which is failing. When removing the loading of r.js the test is successful.
 

public class RJSTest extends AbstractTest {

   
  @Test
  public void testScript() throws IOException {
     
    //this has to be changed e.g. with path on you local disk where r.js is located
    String javascriptRoot = getTestResourceURL("/javascripts").getPath() + "/";
     
    try {
      //initialize
      Context context = Context.enter();
      context.setOptimizationLevel(-1);
      context.setLanguageVersion(Context.VERSION_1_7);
      Global global = new Global();
      global.init(context);
      Scriptable scope = context.initStandardObjects(global);  
       
      //execute Hello World Java Script
      Object wrappedOut = Context.javaToJS(System.out, scope);
      ScriptableObject.putProperty(scope, "out", wrappedOut);
      context.evaluateString(scope, "out.println('Hello World')", null, 1, null);

      // load r.js, with the following code the test is failing, without the test is successful

      global.defineProperty("arguments", new String[]{}, ScriptableObject.DONTENUM);
      executeJS(context, scope, javascriptRoot + "/common/lib", "r.js");

    } finally {
      Context.exit();
    }  
     
    assertTrue("Context.getCurrentContext() is not null!", Context.getCurrentContext() == null);
  }
   
   
  public void executeJS(Context context, Scriptable scope, String jsPath, String jsFileName) {
     
    InputStream inputStream = null;
    try {
      File jsFile = new File(jsPath + "/" + jsFileName);
      inputStream = new FileInputStream(jsFile);
      context.evaluateReader(scope, new InputStreamReader(inputStream), jsFileName, 1, null);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          // ignore
        }
      }
    }
  }

}

I hope you can find a reason.
 
Thanks in advance.
 
Best regards,
Florian

 

 

Reply all
Reply to author
Forward
0 new messages