- js_NewFunction wasn't initializing (clearing) JSFunction members before it
linked the JSFunction to a JSObject that the GC could reach from a root.
- Make sure frame.scopeChain is cleared before linking frame via cx->fp, even
though we set frame.scopeChain to some object later (another signal that we
should rework js_Invoke to inline it and otherwise optimize it).
the errors are being wrapped by runtime exceptions and still need to be
explicitly caught (this is happening in the interpreter, but not in
generated code).
Problem was that one transformation of a node to GETVAR wasn't protected by a check of inWithStatement().
======================================
Subject:
multiple scopes
Date:
Fri, 01 Oct 1999 12:39:14 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com
CC:
Howard Lin <howard@softcom.com>
When I create two scopes, and one scope evaulates a string in the other
scope, it works. However, if I do this while handling an exception thrown
within a JavaAdapter method, it fails with an exception.
Run the attached Java program with the two script files. scope1.js
evaluates a string "printMessage" in the scope of scope2.js. This returns
a function object which is then invoked. This works in 3 cases, but fails
in the 4th (in the catch in the JavaAdapter). Even in the 4th case where
it fails, printing the function object looks normal.
Am I doing something wrong, or is there a bug here?
java CrossScope scope1.js scope2.js
Outside of JavaAdapter
works before exception
works after exception
Inside of JavaAdapter
works before exception
Caught exception
pma=
function printMessage(msg) {
java.lang.System.out.println(msg);
}
Exception in thread "main" org.mozilla.javascript.JavaScriptException:
org.mozilla.javascript.EvaluatorException: The undefined value has no
properties.
at
org.mozilla.javascript.JavaScriptException.wrapException(JavaScriptException
.java:61)
at
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java,
Compiled Code)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1256)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java,
Compiled Code)
at
org.mozilla.javascript.InterpretedScript.call(InterpretedScript.java:49)
at
org.mozilla.javascript.InterpretedScript.exec(InterpretedScript.java:37)
at org.mozilla.javascript.Context.evaluateReader(Context.java:697)
at CrossScope.<init>(CrossScope.java:30)
at CrossScope.main(CrossScope.java:10)
Thanks,
Andrew
import java.io.*;
import org.mozilla.javascript.*;
public class CrossScope {
private Context m_jsContext;
private Scriptable m_scope1;
private Scriptable m_scope2;
public static void main(String args[]) throws Exception {
new CrossScope(args[0], args[1]);
}
private CrossScope(String strFile1, String strFile2) throws Exception {
// Associate Context with main thread
m_jsContext = Context.enter();
m_jsContext.setOptimizationLevel(-1);
// Init scope1, expose Scope object
m_scope1 = m_jsContext.initStandardObjects(new ImporterTopLevel());
m_scope1.put("Scope", m_scope1, this);
// Init scope2
m_scope2 = m_jsContext.initStandardObjects(new ImporterTopLevel());
// Run script in scope2
Reader r2 = new FileReader(strFile2);
m_jsContext.evaluateReader(m_scope2, r2, strFile2, 1, null);
// Eval input JS in scope1 - it can in turn eval JS over in scope2
Reader r1 = new FileReader(strFile1);
Object obj = m_jsContext.evaluateReader(m_scope1, r1, strFile1, 1, null);
if (obj instanceof Throwable)
((Throwable)obj).printStackTrace();
m_jsContext.exit();
}
public Object scope1Eval(String str) throws JavaScriptException {
Context cx = Context.enter(m_jsContext);
Object objResult = cx.evaluateString(m_scope1, str, "scope1EvalString", 1, null);
cx.exit();
return objResult;
}
public Object scope2Eval(String str) throws JavaScriptException {
Context cx = Context.enter(m_jsContext);
Object objResult = cx.evaluateString(m_scope2, str, "scope2EvalString", 1, null);
cx.exit();
return objResult;
}
}
// Scope1
importPackage(java.lang);
System.out.println("Outside of JavaAdapter");
try {
var pm = Scope.scope2Eval("printMessage");
pm("works before exception");
System.arraycopy(null, 5, null, 5, 100);
} catch (e) {
var pma = Scope.scope2Eval("printMessage");
pma("works after exception");
}
var obj = new Runnable() {
run: function() {
System.out.println("Inside of JavaAdapter");
try {
var pm = Scope.scope2Eval("printMessage");
pm("works before exception");
System.arraycopy(null, 5, null, 5, 100);
} catch (e) {
System.out.println("Caught exception");
var pma = Scope.scope2Eval("printMessage");
System.out.println("pma=" + pma);
pma("works after exception");
}
}
};
obj.run();
// Scope2
function printMessage(msg) {
java.lang.System.out.println(msg);
}
14443 "Same origin" security policy may be circumvented using docu
14820 Fixing up the relationship between nsCodeBasePrincipal and n
14919 Crash in JS MM code
Reviewed by mstoltz, approved by scc.
Subject:
optimizer Makefiles
Date:
Fri, 01 Oct 1999 14:50:05 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com
CC:
Howard Lin <howard@softcom.com>
Norris,
Here are patches to the Rhino Makefiles to build the optimizer package and
the jsc compiler. They also fix a problem with "gmake clean".
Andrew
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
Subject:
Re: [Fwd: [Bug 13658] Changed - Rhino: null pointer exception on class with duplicate field/method]
Date:
Mon, 13 Sep 1999 20:57:32 -0400
From:
"Kurt Westerfeld" <kurt@westerfeld.com>
To:
"Norris Boyd" <norris@netscape.com>
I do have a patch for this, but it is intermixed with some other changes
that I have implemented for the get/set on Java instances (per my LC3
proposal). The bug requires changes that are a little involved actually;
basically it seems that when getting the default value for a "field and
methods" (which combines the same-named entities), the prototype of the
parent scope is deref-ed, and the parent scope is null. Hence, the scope
must be passed into the the cloned field and method values.
Also, the NativeJavaClass implementation passed "false" for isStatic on the
constructor of the FieldAndMethods Hashtable, which results in classes
having instance methods. Bad. I haven't filed a bug on that yet.
Additionally, I fixed a couple other NullPointerException nigglies thrown in
when exceptions are propagated in the same area. Finally, when getting the
default value for the field, it is helpful to convert a Scriptable to string
when that is requested (as when typing in the console).
I am attaching the changed files. The LC3++ code can be removed if you
want, which I can do for you but it will take a little longer. What is your
preference?
-----Original Message-----
From: Norris Boyd <norris@netscape.com>
To: Kurt Westerfeld <kurt@westerfeld.com>
Date: Monday, September 13, 1999 4:54 PM
Subject: [Fwd: [Bug 13658] Changed - Rhino: null pointer exception on class
with duplicate field/method]
>Kurt,
>
>Is this the bug that your patch fixes?
>
>Thanks,
>Norris
>