A Rhino user has complained about concurrency problems in the interpreter,
and I think the attached diff fixes some problems that could be caused if
the same interpreted function or script was called simultaneously from
two different threads.
Re: Rhino1.5.R1: problems with multithreaded embedded application.
Date:
Mon, 03 Jul 2000 14:38:56 -0400
From:
Norris Boyd <nboyd@atg.com>
Organization:
Art Technology Group
To:
Fergus Gallagher <Fergus.Gallagher@orbisuk.com>
Newsgroups:
netscape.public.mozilla.jseng
References:
1
You found a bug in Rhino; I wonder if others have been running into the same thing.
The problem is with a class called LazilyLoadedCtor. I wrote this class to reduce the
time
required by initStandardObjects by only creating standard objects when the associated
constructors are first accessed. The problem is that this class was not threadsafe.
I've
made changes to that class, and to ScriptableObject as well. The design of dynamic
properties calling getters and setters (which LazilyLoadedCtor uses) didn't really
allow
any way for the getter/setter to replace itself without a thread hazard. I've now
extended
setters so that they can return a value which replaces the getter/setter to avoid this
problem.
Thanks for finding this problem. There have been a couple of other reports of problems
in
this area, so I hope this will fix them.
The patch follows.
--N
Index: LazilyLoadedCtor.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/org/mozilla/javascript/LazilyLoadedCtor.java,v
retrieving revision 1.1
diff -u -r1.1 LazilyLoadedCtor.java
--- LazilyLoadedCtor.java 2000/02/29 21:34:37 1.1
+++ LazilyLoadedCtor.java 2000/07/03 18:31:03
@@ -58,9 +58,12 @@
}
public Object getProperty(ScriptableObject obj) {
- obj.delete(ctorName);
try {
- ScriptableObject.defineClass(obj, Class.forName(className));
+ synchronized (obj) {
+ if (!isReplaced)
+ ScriptableObject.defineClass(obj, Class.forName(className));
+ isReplaced = true;
+ }
}
catch (ClassNotFoundException e) {
throw WrappedException.wrapException(e);
@@ -83,11 +86,14 @@
return obj.get(ctorName, obj);
}
- public void setProperty(ScriptableObject obj, Object val) {
- obj.delete(ctorName);
- obj.put(ctorName, obj, val);
+ public Object setProperty(ScriptableObject obj, Object val) {
+ synchronized (obj) {
+ isReplaced = true;
+ return val;
+ }
}
private String ctorName;
private String className;
+ private boolean isReplaced;
}
Index: ScriptableObject.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/org/mozilla/javascript/ScriptableObject.java,v
retrieving revision 1.17
diff -u -r1.17 ScriptableObject.java
--- ScriptableObject.java 2000/03/13 17:12:36 1.17
+++ ScriptableObject.java 2000/07/03 18:31:04
@@ -246,11 +246,21 @@
break;
}
}
- getterSlot.setter.invoke(start, arg);
+ Object v = getterSlot.setter.invoke(start, arg);
+ if (getterSlot.setterReturnsValue) {
+ slots[slotIndex].value = v;
+ if (!(v instanceof Method))
+ slots[slotIndex].flags = 0;
+ }
return;
}
Object[] args = { this, actualArg };
- getterSlot.setter.invoke(getterSlot.delegateTo, args);
+ Object v = getterSlot.setter.invoke(getterSlot.delegateTo, args);
+ if (getterSlot.setterReturnsValue) {
+ slots[slotIndex].value = v;
+ if (!(v instanceof Method))
+ slots[slotIndex].flags = 0;
+ }
return;
}
catch (InvocationTargetException e) {
@@ -1183,6 +1193,7 @@
slot.delegateTo = delegateTo;
slot.getter = getter;
slot.setter = setter;
+ slot.setterReturnsValue = setter != null && setter.getReturnType() !=
Void.TYPE;
slot.value = null;
slot.attributes = (short) attributes;
slot.flags = flags;
@@ -1551,6 +1562,7 @@
Object delegateTo; // OPT: merge with "value"
Method getter;
Method setter;
+ boolean setterReturnsValue;
}
Fergus Gallagher wrote:
> I am having problems getting my head around contexts and scopes and my
> multi-threaded application fall over.
>
> If I set "global=false" the following code used a per-thread
> initStandardObject() and this seems to work. But when I set
> "global=true", the global "parentScope" is used and I get some wierd
> errors.
>
> If I change "__CODE__.slice(0,5)" to
> 1. "__CODE__" - works
> 2. "__CODE__.substring(0,5)" - fails
> 3. "__CODE__.toString()" - works
>
> Any help appreciated.
>
> Fergus
>
> ===== Test.java =========================================
> import java.io.*;
> import org.mozilla.javascript.*;
>
> public class Test implements Runnable {
> private Script script;
> private Scriptable parentScope;
> private String __CODE__="ABCDEFGHIJK";
> private boolean global = true;
> private static Context globalContext = null;
> public Test() throws Exception {
> String js= "java.lang.System.out.println(__CODE__.slice(0,5));";
> globalContext.setCompileFunctionsWithDynamicScope(false);
> parentScope = globalContext.initStandardObjects(null);
> StringReader sr = new StringReader(js);
> script = globalContext.compileReader(parentScope, sr, "(compiled)",
> 1,null);
> }
>
> public void run() {
> try {
> Context context = Context.enter();
> Scriptable threadScope;
> if (global) {
> threadScope = context.newObject(parentScope);
> threadScope.setPrototype(parentScope);
> threadScope.setParentScope(null);
> } else {
> threadScope = context.initStandardObjects(null);
> }
> threadScope.put("__CODE__",threadScope,__CODE__);
> script.exec(context,threadScope);
> }
> catch (Exception e) {
> System.err.println(e.getClass().getName()+":
"+e.getMessage());
> }
> finally {
> Context.exit();
> }
> }
>
> public static void main(String args[]) throws Exception {
> globalContext = Context.enter();
> Test me = new Test();
> int count=10;
> Thread[] threads = new Thread[count];
> for (int i=0; i<count; i++) {
> Thread t = new Thread(me);
> threads[i] = t;
> t.start();
> }
> for (int i=0; i<count; i++) {
> threads[i].join();
> }
> Context.exit();
> }
> }
>
> ==== OUTPUT ===============================================
> ABCDE
> ABCDE
> org.mozilla.javascript.EcmaError: undefined is not a function.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> org.mozilla.javascript.EvaluatorException: Constructor for "String" not
> found.
> ===========================================================
>
> The number and type of exceptions is highly variable from run to run -
> anywhere from 1-9 out of 10.
> The EcmaError in particular only happens occasionally.
>
> --
> Fergus Gallagher Tel: +44 (20) 8 987 0717
> Orbis Fax: +44 (20) 8 742 2649
> The Swan Centre email: Fergus.Gallagher@orbisuk.com
> Fishers Lane Web: http://www.orbisuk.com
> London W4 1RX / UK
Commit the following contributions:
* Andi Vajda's changes to allow embedders to capture the generated bytecode (and thus control
generated class names).
* Marshall Cline's changes to allow embedders to override the default Java object wrapping
behavior
* Kurt Westerfeld's change to handle calling static methods better
Subject:
Odd behaviour on placement of .jar files?!
Date:
Mon, 05 Jun 2000 10:46:08 -0700
From:
John Raykowski <xski@xski.org>
To:
nboyd@atg.com
Hello,
I didn't want to post this directly as a rhino bug 'coz I think it may
be more of a JDK thing, but I thought I'd toss it to you as well.
The goal is to create a JavaScript object that implements a Java
interface. Straightforward enough and the example on the page using
ActionListener works without a hitch. However, when I try to do the
same with my own interface, I get an error message: error instantiating
({0}): class {1} is interface or abstract (coming from
NativeJavaClass.construct).
Here's where it gets a bit strange. Normally, I run with the jar files
in jre/lib/ext. When I remove the rhino files from jre/lib/ext and
reference them explicitly on the commandline with the -cp option, it
works as expected and my script can implement the interface just fine.
Go figure.
Anyhoo, there ya go. Like I said, I think its a JDK issue, but I
thought you'd be interested. The attached zipfile contains a set of
sample code to demonstrate this problem.
Thanks heaps,
-jmr
resulting in a NullPointerException on the following code when run on the MS VM with -opt 9:
var testcases = getTestCases();
function getTestCases() {
return new Boolean(new MyObject(true));
}
function MyObject( value ) {
this.value = value;
this.valueOf = new Function( "return this.value" );
return this;
}
Subject:
JavaAdapter return type conversion
Date:
Wed, 19 Apr 2000 12:12:47 +0100
From:
Matthias Radestock <rade@logee.com>
Organization:
Logee
To:
norris@netscape.com
CC:
mccabe@netscape.com, beard@netscape.com, rogerl@netscape.com
Dear Rhino team,
When returning an array from a scripted Java object (i.e. a JS object
that implements a Java interface), no type conversion is performed, ie.
a NativeArray is returned instead of a Java array. Example:
Java:
interface Foo {
public String[] boo();
}
JS:
FooI = {
boo: function() { return ["Boo"];}
}
myFoo = new Packages.Foo(FooI);
myFoo.boo(); //==> breaks with a ClassCastException
Looking at the JavaAdapter code, there is no code for array conversion.
This is particularly bad because precisely such a conversion *does*
happen when calling a Java method from JS. So we end up with a
discrepancy.
See attachment for a patch to fix this and little test program. The
patch works by calling the coerceType function on NativeJavaObject,
which is the function responsible for doing the conversion when calling
from JS to Java. I've simplified the code so that this function gets
called for all non-primitive return type, not just arrays. There are
probably more efficient solutions but I'm not a Java bytecode hacker.
Matthias
PS: I didn't open a bug for this because I wasn't sure whether you guys
would agree that this is indeed a problem ;)
public interface JSReturnTest {
public boolean returnBoolean();
public char returnChar();
public int returnInt();
public String returnString();
public org.mozilla.javascript.Scriptable returnScriptable();
public Object returnObject();
public boolean[] returnBooleanA();
public char[] returnCharA();
public int[] returnIntA();
public String[] returnStringA();
public org.mozilla.javascript.Scriptable[] returnScriptableA();
public Object[] returnObjectA();
public Object[][] returnObjectAA();
}
Index: JavaAdapter.java
===================================================================
RCS file: /cvsroot/mozilla/js/rhino/org/mozilla/javascript/JavaAdapter.java,v
retrieving revision 1.21
diff -r1.21 JavaAdapter.java
54c54,59
<
---
>
> public static Object convertResult(Object result, String classname)
> throws ClassNotFoundException {
> return NativeJavaObject.coerceType(Class.forName(classname),
> result);
> }
467,474c472,474
< } else if (retType.equals(String.class)) {
< cfw.add(ByteCode.INVOKESTATIC,
< "org/mozilla/javascript/Context",
< "toString", "(Ljava/lang/Object;)",
< "Ljava/lang/String;");
< cfw.add(ByteCode.ARETURN);
< } else if (retType.equals(Scriptable.class)) {
< cfw.add(ByteCode.ALOAD_0); // load 'this' to find scope from
---
> } else {
> String retTypeStr = retType.getName();
> cfw.addLoadConstant(retTypeStr);
476,477c476,477
< "org/mozilla/javascript/Context",
< "toObject",
---
> "org/mozilla/javascript/JavaAdapter",
> "convertResult",
479,500c479,480
< "Lorg/mozilla/javascript/Scriptable;)",
< "Lorg/mozilla/javascript/Scriptable;");
< cfw.add(ByteCode.ARETURN);
< } else {
< // If it is a wrapped type, cast to Wrapper and call unwrap()
< cfw.add(ByteCode.DUP);
< cfw.add(ByteCode.INSTANCEOF, "org/mozilla/javascript/Wrapper");
< // skip 3 for IFEQ, 3 for CHECKCAST, and 5 for INVOKEINTERFACE
< cfw.add(ByteCode.IFEQ, 11);
< cfw.add(ByteCode.CHECKCAST, "org/mozilla/javascript/Wrapper");
< cfw.add(ByteCode.INVOKEINTERFACE,
< "org/mozilla/javascript/Wrapper",
< "unwrap", "()", "Ljava/lang/Object;");
<
< // If Undefined, return null
< cfw.add(ByteCode.DUP);
< cfw.add(ByteCode.INSTANCEOF, "org/mozilla/javascript/Undefined");
< // skip 3 for IFEQ, 1 for ACONST_NULL, 1 for ARETURN
< cfw.add(ByteCode.IFEQ, 5);
< cfw.add(ByteCode.ACONST_NULL);
< cfw.add(ByteCode.ARETURN);
<
---
> "Ljava/lang/String;)",
> "Ljava/lang/Object;");
502,503c482
< String retTypeStr = retType.getName().replace('.', '/');
< cfw.add(ByteCode.CHECKCAST, retTypeStr);
---
> cfw.add(ByteCode.CHECKCAST, retTypeStr.replace('.', '/'));
testpatch.js
Name:
testpatch.js
Type:
JavaScript Program (application/x-javascript)
Encoding:
7bit
contextClassloader problem in ScriptRuntime.java
Date:
Tue, 11 Apr 2000 09:45:36 -0400
From:
"Howard Lin" <howard@softcom.com>
To:
"Norris Boyd" <norris@netscape.com>
CC:
"Andrew Wason" <aw@softcom.com>
Hi, Norris, we are trying to create a Java class in JavaScript. When security manager is on, everything works fine. But when security
manager is off, we got an error saying the "... is not defined". The problem is that in ScriptRuntime.java, when security is on,
getContextClassLoader is null due to SecurityException and Class.forName is used to find the class, which works fine. When security
is off, ContextClassLoaderMethod is invoked to find the class. Since we use a separate thread to load third party jar files,
ContextClassLoaderMethod will throw a ClassNotFound exception.
To illustrate this problem, I wrote a simple applet, evaluating a simple js file in its paint method, which is running on a separate thread.
When security is off, I got the following:
ReferenceError: "Global" is not defined.
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:
494)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java, Compile
d Code)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java, Compil
ed Code)
at org.mozilla.javascript.InterpretedScript.call(InterpretedScript.java:
67)
at org.mozilla.javascript.InterpretedScript.exec(InterpretedScript.java:
54)
at org.mozilla.javascript.Context.evaluateReader(Context.java:739)
at test.evaluate(test.java:26)
at test.paint(test.java:16)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:117)
at java.awt.Component.dispatchEventImpl(Component.java:2447)
at java.awt.Container.dispatchEventImpl(Container.java:1035)
at java.awt.Component.dispatchEvent(Component.java:2307)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:10
1)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
When security is on, it runs fine. Or if the code moved to init method, it works fine regardless of security. We are using JDK 1.2.2.
Howard
step += (InLeapYear(t) ? 29 : 28);
with the form
if (InLeapYear(t))
step += 29;
else
step += 28;
to work around an apparent JRE bug in which the code always returns 28.
2. Change from using Class.getDeclaredMethods to Class.getMethods since the former may cause
security problems. Implement a cache to ameleorate the possible performance degredation.
3. Add a new class to lazily load constructors to improve performance
This was caused by a previous bug fix in which I moved the try stack
decrement to the end of the catch clause because it was getting skipped
by the final statement in the try block (which is always a goto around the
catch block). Better is to make sure the endTry is the statment just before
that goto, and do the try stack decrement in the catch the way god intended.
Subject:
Rhino request URGENT
Date:
Thu, 02 Dec 1999 15:58:40 -0500
From:
slobo@espialgroup.com
To:
Norris Boyd <norris@netscape.com>
References:
1 , 2
Hello Norris
In Rhino, the following script gives the error : "function does not always return a value" during the parsing phase. The script
runs perfectly fine in Netscape 4.61. It is an urgent requirement. Many thanks in advance.
Steven
///////////////////////////////////////////////////////SCRIPT BEGIN ///////////////////////////////////////////////
function test (a) {
this.arg = a;
if (a>20)
return;
return this;
}
//print = alert;
function joe() {
a = new test (20);
print (a.arg);
a = new test (25);
print (a.arg);
}
joe();
///////////////////////////////////////////////////////SCRIPT END ///////////////////////////////////////////////
Subject:
Re: another getClassLoader exception
Date:
Mon, 18 Oct 1999 22:01:24 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com (Norris Boyd)
CC:
Howard Lin <howard@softcom.com>
References:
1 , 2
At 05:03 PM 10/18/99 -0700, Norris Boyd wrote:
>Are you still seeing this problem?
Yes. I just did a CVS update to get the latest stuff and we still have
this problem.
I wrote a standalone sample program that duplicates the problem. Run
JSSupport and you should get this exception:
defineClass org.mozilla.javascript.gen.c2
Exception in thread "main" java.lang.NoClassDefFoundError:
org/mozilla/javascript/gen/c1
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:545)
at
JSSupport$MySecuritySupport$DataClassLoader.loadClass(JSSupport.java:89)
at JSSupport$MySecuritySupport.defineClass(JSSupport.java:47)
at org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java,
Compiled Code)
at org.mozilla.javascript.Context.compile(Context.java:1761)
at org.mozilla.javascript.Context.compile(Context.java:1691)
at org.mozilla.javascript.Context.compileReader(Context.java:810)
at org.mozilla.javascript.Context.evaluateReader(Context.java:725)
at org.mozilla.javascript.Context.evaluateString(Context.java:692)
at JSSupport.<init>(JSSupport.java:20)
at JSSupport.main(JSSupport.java:9)
Andrew
>--N
>
>Andrew Wason wrote:
>
> > At 04:54 PM 10/12/99 -0700, Norris Boyd wrote:
> > >I just checked in changes so that the class calling ScriptRuntime (c5
> in your
> > >case) will load the class itself using the normal Java classloading
> mechanism
> > >rather than an explicit call to the class loader. I pushed the bits up
> to the
> > >ftp site, but it takes a bit to propagate.
> >
> > I get this exception now (debugging statements are from my code):
> >
> > SecuritySupport.defineClass org.mozilla.javascript.gen.c5
> > DataClassLoader.loadClass org.mozilla.javascript.gen.c5
> > DataClassLoader.loadClass org.mozilla.javascript.gen.c4
> > using default loader com.softcom.realjava.PluginClassLoader@da9486a0
> > java.lang.NoClassDefFoundError: org/mozilla/javascript/gen/c4
> > at java.lang.ClassLoader.resolveClass0(Native Method)
> > at java.lang.ClassLoader.resolveClass(ClassLoader.java:545)
> > at
> >
> com.softcom.realjava.plugins.RealJavaScript$RealJavaScriptSecuritySupport$Da
> > taClassLoader.loadClass(RealJavaScript.java:410)
> > at
> >
> com.softcom.realjava.plugins.RealJavaScript$RealJavaScriptSecuritySupport.de
> > fineClass(RealJavaScript.java:352)
> > at org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java,
> > Compiled Code)
> > at org.mozilla.javascript.Context.compile(Context.java:1761)
> > at org.mozilla.javascript.Context.compile(Context.java:1691)
> > at org.mozilla.javascript.Context.compileReader(Context.java:810)
> >
> > So when c5 is being loaded by my SecuritySupport, it also needs to load c4.
> > I decompiled org.mozilla.javascript.gen.c5 and it's constant pool
> > references CLASS org.mozilla.javascript.gen.c4, so c5 is dependent on c4
> > being loadable. Is the problem that c5 is being loaded before the
> > optimizer has defined c4?
> >
> > I get the above exception for some classes and not others. It seems
> > consistent that I always get it for classes with dependencies on other
> > optimizer classes that haven't been generated yet.
> >
> > Andrew
> >
> > --
> > Andrew Wason
> > SoftCom, Inc.
> > aw@softcom.com
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
JSSupport.java
Name:
JSSupport.java
Type:
Java Source File (text/java)
Encoding:
base64
Subject:
another getClassLoader exception
Date:
Tue, 12 Oct 1999 10:39:26 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com (Norris Boyd)
CC:
Howard Lin <howard@softcom.com>
Norris,
It looks like the classes the optimizer generates call
ScriptRuntime.defineFunction which calls getClassLoader. This throws a
SecurityException.
java.security.AccessControlException: access denied
(java.lang.RuntimePermission getClassLoader )
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java
, Compiled Code)
at java.security.AccessController.checkPermission(AccessController.java,
Compiled Code)
at java.lang.SecurityManager.checkPermission(SecurityManager.java, Compiled
Code)
at java.lang.Class.getClassLoader(Class.java, Compiled Code)
at
org.mozilla.javascript.ScriptRuntime.defineFunction(ScriptRuntime.java:2045)
at org.mozilla.javascript.gen.c5.initScript(order.js)
at org.mozilla.javascript.gen.c5.exec(order.js)
at org.mozilla.javascript.Context.evaluateReader(Context.java:728)
[...]
Andrew
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
Subject:
optimizer SecurityException
Date:
Mon, 11 Oct 1999 17:37:51 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com (Norris Boyd)
CC:
Howard Lin <howard@softcom.com>
We use our own SecuritySupport implementation in Rhino. This is properly
getting called by the optimizer to generate new classes (e.g.
org.mozilla.javascript.gen.c5 etc.)
However, after defining the class, Codegen.compile calls getClassLoader()
on the new class. The default SecurityManager doesn't allow
getClassLoader() to be called and so an exception is thrown:
java.lang.RuntimeException: Malformed optimizer package
java.security.AccessControlException: access denied
(java.lang.RuntimePermission getClassLoader )
at org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java:138)
at org.mozilla.javascript.Context.compile(Context.java:1761)
at org.mozilla.javascript.Context.compile(Context.java:1691)
at org.mozilla.javascript.Context.compileReader(Context.java:810)
at org.mozilla.javascript.Context.evaluateReader(Context.java:725)
[...]
This is kind of a pain to duplicate outside of our application, but if you
require a test case I can create one.
Codegen is attempting to call loadClass() after it uses
SecuritySupport.defineClass(). Our SecuritySupport calls loadClass()
internally in its defineClass() implementation. This is what JavaAdapter
expects.
This is from Codegen.compile():
if (securitySupport == null) {
if (Context.isSecurityDomainRequired())
throw new SecurityException("Required " +
"security context missing");
if (classLoader == null)
classLoader = new JavaScriptClassLoader();
clazz = classLoader.defineClass(name, classFile);
} else {
clazz = securitySupport.defineClass(name,
classFile,
securityDom
securityDomain);
}
ClassLoader loader = clazz.getClassLoader();
clazz = loader.loadClass(name);
This is from JavaAdapter.createAdapterClass():
SecuritySupport ss = cx.getSecuritySupport();
if (ss != null) {
Object securityDomain = cx.getSecurityDomainForStackDepth(-1);
return ss.defineClass(adapterName, bytes, securityDomain);
} else {
if (classLoader == null)
classLoader = new MyClassLoader();
classLoader.defineClass(adapterName, bytes);
return classLoader.loadClass(adapterName, true);
}
So JavaAdapter is assuming SecuritySupport.defineClass() will call
ClassLoader.loadClass() on the new class, while Codegen is assuming it
needs to call ClassLoader.loadClass() on the class defined by
SecuritySupport.defineClass().
These should be made consistent, and in both cases it should be assumed
that SecuritySupport will both define and load the class.
Andrew
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
Re: NPL vs. MPL
Date:
Wed, 06 Oct 1999 18:30:34 -0400
From:
"Ian D. Stewart" <idstewart@softhome.net>
To:
Norris Boyd <norris@netscape.com>
References:
1 , 2 , 3
Norris Boyd wrote:
Great. So I'd like to change this copyright text
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset:
4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "MozPL"); you may not use this file except in
* compliance with the MozPL. You may obtain a copy of the MozPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the MozPL is distributed on an "AS IS"
basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
MozPL
* for the specific language governing rights and limitations under the
* MozPL.
*
* The Initial Developer of this code under the MozPL is Ian D. Stewart.
* Portions created by Ian D. Stewart are Copyright (C) 1998, 1999
* Ian D. Stewart.
* All Rights Reserved.
*/
to this:
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset:
4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is ListenerCollection, released
* May 15, 1998.
*
* The Initial Developer of the Original Code is Ian D. Stewart.
* Portions created by Ian D. Stewart are Copyright (C) 1998, 1999
* Ian D. Stewart.
* Rights Reserved.
*
* Contributor(s):
* Ian D. Stewart
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
Can you give me your approval for this change?
Make it so.
Ian
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);
}
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
>
Turned off 'super' keyword - was letting through some cut'n'pasted java
code quietly and blowing big chunks out of the codegen/interpreter later.
Anybody know why 'super' had an interesting value here? - there was no
support for it on any path that I could see.
Subject:
Embedding the shell
Date:
Wed, 8 Sep 1999 16:01:44 -0400
From:
"Kurt Westerfeld" <kurt@westerfeld.com>
To:
"Norris Boyd" <norris@netscape.com>
Norris, please find the attached zip file containing the (minor)
modifications to the Rhino shell module that enables the shell to be
embedded in a host application.
There are two areas of change to be concerned about:
1. Any and all references to System.in/out/err have been modified to use
Main.in/out/err, which default to System.in/out/err. Methods to do a setIn,
setOut, and setErr were added. Note that in/out/err on Main were made
static public, so that the jikes compiler wouldn't complain (I had them as
static protected, but when accessed outside of the package, a warning was
issued).
2. The global and sharedGlobal static variables were made protected so
that my app can make use of them (to add extensions after an initial pass
through main()).
That's it.
I have successfully used the facility to drop a remote telnet server into
the shell interpreter, effectively giving our server a remote shell
interpreter. It's quite nice, as we have a lot of extensions to Rhino
written that blend into our server already.
PS, I am still working on the array issues, but made a lot of progress
today. I just wanted to get this stuff off my desk.
Thanks!
________________________________________________________________________
Kurt Westerfeld
Managed Object Solutions
2722 Merrilee Drive
Suite 350
Fairfax, VA 22031
Phone: 703.208.3330 x225
Fax: 703.208.3331
http://www.mosol.com
mailto:kurt@mosol.com
shell.zip
Name:
shell.zip
Type:
Zip Compressed Data (application/x-zip-compressed)
Encoding:
base64
==============================================================================
Subject:
Rhino Array Source (Fixed)
Date:
Thu, 9 Sep 1999 14:12:03 -0400
From:
"Kurt Westerfeld" <kurt@mosol.com>
To:
"Norris Boyd" <norris@netscape.com>
Attached is NativeJavaObject.java, which seems to now pass the tests supplied to me by you and Scott. Not a lot of change, but a lot of
testing and thinking was involved. <g>
PS. I also fixed a bug in reportConversionError() which was throwing an IllegalArgumentException inside of the MessageFormat class at times.
It also looks a little nicer (uses formatting from NativeJavaMethod) and closer to the C implementation.
NativeJavaObject.java
Name:
NativeJavaObject.java
Type:
Java Source File (text/java)
Encoding:
quoted-printable