You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we recently upgraded from version 1.7.12 to 1.7.14 and now one of our test fails.
The test uses importClass with a class in our JUnit tests and run the same script multiple times. We get this exception in 1.7.14:
org.mozilla.javascript.EvaluatorException: Cannot import "JSLongTest" since a property by that name is already defined. (TestJSScriptCode2#2)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:79)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:907)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:963)
at org.mozilla.javascript.Context.reportRuntimeErrorById(Context.java:914)
at org.mozilla.javascript.ImporterTopLevel.importClass(ImporterTopLevel.java:216)
at org.mozilla.javascript.ImporterTopLevel.js_importClass(ImporterTopLevel.java:176)
at org.mozilla.javascript.ImporterTopLevel.execIdCall(ImporterTopLevel.java:257)
at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:100)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:59)
at org.mozilla.javascript.gen.TestJSScriptCode2_1._c_script_0(TestJSScriptCode2:2)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.call(TestJSScriptCode2)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:380)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3868)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.call(TestJSScriptCode2)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.exec(TestJSScriptCode2)
I tried to debug org.mozilla.javascript.ImporterTopLevel.importClass and compared the sources. There is now a scope object that is used instead of this, and there are 2 differences that I see:
In 1.7.12, the NativeJavaClass cl is always the same Java object. And we always have a new ImporterTopLevel object in each run, so cl is not found:
private void importClass(NativeJavaClass cl)
{
String s = cl.getClassObject().getName();
String n = s.substring(s.lastIndexOf('.')+1);
Object val = get(n, this);
if (**val != NOT_FOUND** && val != cl) {
throw Context.reportRuntimeError1("msg.prop.defined", n);
}
//defineProperty(n, cl, DONTENUM);
put(n, this, cl);
}
In 1.7.14, the NativeJavaClass cl is a different Java object (but equal) in each run. And the ImporterTopLevel object is the same on the second run, so the object is found, but not the same object, so the error occurs:
Hi,
we recently upgraded from version 1.7.12 to 1.7.14 and now one of our test fails.
The test uses importClass with a class in our JUnit tests and run the same script multiple times. We get this exception in 1.7.14:
org.mozilla.javascript.EvaluatorException: Cannot import "JSLongTest" since a property by that name is already defined. (TestJSScriptCode2#2)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:79)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:907)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:963)
at org.mozilla.javascript.Context.reportRuntimeErrorById(Context.java:914)
at org.mozilla.javascript.ImporterTopLevel.importClass(ImporterTopLevel.java:216)
at org.mozilla.javascript.ImporterTopLevel.js_importClass(ImporterTopLevel.java:176)
at org.mozilla.javascript.ImporterTopLevel.execIdCall(ImporterTopLevel.java:257)
at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:100)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:59)
at org.mozilla.javascript.gen.TestJSScriptCode2_1._c_script_0(TestJSScriptCode2:2)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.call(TestJSScriptCode2)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:380)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3868)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.call(TestJSScriptCode2)
at org.mozilla.javascript.gen.TestJSScriptCode2_1.exec(TestJSScriptCode2)
I tried to debug org.mozilla.javascript.ImporterTopLevel.importClass and compared the sources. There is now a scope object that is used instead of this, and there are 2 differences that I see:
In 1.7.12, the NativeJavaClass cl is always the same Java object. And we always have a new ImporterTopLevel object in each run, so cl is not found:
In 1.7.14, the NativeJavaClass cl is a different Java object (but equal) in each run. And the ImporterTopLevel object is the same on the second run, so the object is found, but not the same object, so the error occurs:
The code would probably work as expected, if the cl object would be the same Java object as it is in 1.7.12.
Any idea why this happens in 1.7.14?
Regards,
Andreas Mueller
The text was updated successfully, but these errors were encountered: