I looked into this somewhat and I noticed the following:
1) There is a bug in Interpreter.java, line 1695. It sets the variable "i" to
the line number of the special call, but overwrites it on line 1699. It then
passes this value to ScriptRuntime.callSpecial
2) In "generateScriptICode" in Interpreter.java the variable
itsData.itsSourceFile fails to be set to itsSourceFile. This causes a null
source file name to be passed to handleCompilationDone when "Widget.js" is
compiled. That is why you
initially see "<stdin>, line 6" when the debugger comes up (the debugger
interprets a null source name as "stdin"). I simply modified it as follows
(this might not be the right thing to do?):
private InterpretedScript generateScriptICode(Context cx,
Scriptable scope,
Node tree,
Object securityDomain)
{
itsSourceFile = (String) tree.getProp(Node.SOURCENAME_PROP);
itsData.itsSourceFile = itsSourceFile;
...
and that corrected the problem.
However there seems to be no way for the debugger to detect that the script
passed to handleCompilationDone() is the argument of an "eval()". So I modifed
NativeGlobal.evalSpecial() to munge the filename to indicate this (by appending
"(eval)" to it). That way a separate window is created in the debugger to hold
the compiled eval code. This is probably not be the best way to solve the
problem.
I have attached the files I modified.
Cheers,
Chris
Simon Massey wrote:
> Christopher,
>
> Attached is the code that trips the debugger up. The debugger comes up. You
minimize the console to reveal Widget.js file window. You click 'Go'. The
Widget.js window looses all the code in it and is just replaced by the evaluated
code:
>
> this.invokedByEval()
>
> The rhino tip I have is rhino15R2pre.zip
>
> I am running it with the command:
>
> start javaw org.mozilla.javascript.tools.debugger.JSDebugger -f Widget.js -f
Main.js
>
> using the JVM:
>
> java version "1.3.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
> Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
>
> on Win2k.
>
> Just in case you are wondering why on earth my code wants to do this, it is
because I want to do some introspection. The real Widget invokes all its methods
that have a particular substring in their names:
>
> for( key in this ){
> if( key.indexOf('reflect') == 0 ){
> var evalStr = "this."+key+"()";
> eval(evalStr);
> }
> }
>
> Thanks for the great code. I have the real Widget stabilized and am happily
using the debugger on my other files.
>
> Thanks again!
>
> Simon Massey
>
jsdoc.js - added simple support for methods
Date:
Thu, 14 Jun 2001 09:12:26 +0100 (GMT Daylight Time)
From:
Simon Massey <simon_massey@hotmail.com>
To:
<nboyd@atg.com>
First off let me say thanks a lot for rhino. It is a really excellent piece
of software.
I am writing a large piece of js for making Excel2000 htm interactive on IE
and other browser such as Netscape6. Use a alot of code OO using methods
along the lines of:
/**
* Constructor
*/
function Type(x){
this.x = x;
}
/**
* Method
*/
Type.prototype.getX = function(){
return x;
}
var type = new Type('a');
var a = type.getX();
I have added to jsdoc.js so that finds and documents the method
declarations.
Attached is my modified jsdoc.js and a sample of the html that it generates
for the some of our proprietry :-( "Axel" code.
As an aside have you seen the job that www.blox.com have done on making a
dhtml spreadsheet? Bet they wished they could use exceptions in Netscape4!
Looking forward to the production JSDebugger. The tip version is great. It
does however seem to trash the view that it has of a file when an eval call
is made in that file. Is there a work around or will I have to wait till
the production version?
Thanks Again!
Simon Massey
-----
The patch adds to NativeArray.put a check for (this == start) so the
length field or a dense array element would not be updated if this !=
start. The following script exposes the problem:
function Test() { }
var array = new Array(0, 0); // Trigger dense mode
Test.prototype = array;
var test = new Test();
array[0] = 1;
test[0] = 2;
print(array[0]); // Should print 1, not 2
-----
When initially I switched NativeDate to use IdScritable, I made
toGMTString just an alias to toUTCString. Later I realized that it could
cause troubles if someone would check Date.prototype.toGMTString.name to
get "toUTCString" so I made the code to allocate a separated IdFunction
to toUTCString. Now when I read ecma 3 appendixes I see that the initial
behavior is what actually Ecma 3 requires. Here is an extract from B.2.6:
The Function object that is the initial value of
Date.prototype.toGMTString is the same Function
object that is the initial value of Date.prototype.toUTCString.
Sometimes doing nothing is the best solution...
The attached patch fixes that and inlines many 1-3 lines functions as
optimization that java compilers typically do not want to do...
1. Keyword search via Java Hahstable is replaced by explicit "switch"
code generated by idswitch tool. It not only speed up keyword search and
eliminates all Integer objects created to hold keyword tokens and
corresponding Hahstable structures, but it also reduces code size due to
very poor array initialization support in JVM.
2. It replaces the isXDigit method by xDigitToInt that either converts
its argument to 0..15 or returns -1 if it is not a hex digit and updates
the method usage accordingly The patch updates NativeGlobal.js_unescape
to reflect this usage change.
In the attached patch I added documentation, did some inlining in the
get method implementation to gain some speed and overrode defineProperty
so it plays better with id-based properties.
-----
The patch fixes a bug in getIds method where the assignment "result =
tmp" was missed, adds the public method activateIdMap(int maxId) to
IdScriptable and changes setAttributes method not to allow setting of
attributes that are less restrictive then ones returned by
getIdDefaultAttributes. That was supposed to be the case and the patch
makes it explicit.
-----
The patch makes BaseFunction.setImmunePrototypeProperty public so it can
be called from other packages (regexp).
-----
The patch switches NativeRegExp and NativeRegExpCtor to use
IdScriptable. It also changes code in a few places to passes Context and
RegExpImpl directly instead of using Context.getCurrentContext().
The patch also fixes a bug when
for (var i in RegExp) { print(i); }
would not include $1..$9 in the output in violation with Ecma. It was
caused by not overriding ScriptableObject.getIds in
NativeRegExpCtor.
-----
The patch changes NativeCall to use IdScriptable. This is done mostly
for uniformity with other Native* classes plus it would allow to call
NativeCall.init directly and make NativeCall package private.
-----
The patch changes NativeScript to use id-based properties. Due to
inheritance from NativeFunction, id support requires to take into
account the fact that there are instance ids available from
BaseFunction. This is the reason to use "int prototypeIdShift" instead
of "boolean prototypeFlag" so it can store instance id offset.
The patch updates ScriptRuntime.callOrNewSpecial to check against
IdFunction and not FunctionObject for the Script exec method where it
also add finally clause to make sure that Context.exit would always be
called after Context.enter in the evalScript method.
-----
After converting NativeScript and NativeFunction to use IdScriptable,
they get scope argument directly as a parameter of execMethod call, so
cx.ctorScope is not used any more. The patch removes code to set/unset
cx.ctorScope.
-----
[This patch depends on conversion of NativeScript and NativeCall to use
IdScriptable and the patch to remove access of ctorScope from
FunctionObject]
The patch changes Context.initStandardObjects to call NativeCall.init
and NativeScript.init directly plus it unrolls the lazily initialization
loop. Due to rather poor support of an array initialization in Java byte
code, it actually decreases code size while eliminating are creation of
array object. The patch also removes ctorScope field as unused.
-----
The patch makes sure that ids used by NativeGlobal are visible only in
the object instance that initializes global scope and removes some junk
white space at line ends.
-----
To use the idswitch tool to generate map for strings that can not be
part of Id_ Java identifier like $*, I added code to the tool to look
for "// #string=...#" in the id definition line. The attached README
file also contains some documentation about the tool and should go to
idswitch directory.
The patch was made from toolsrc/org/mozilla/javascript/tools via:
cvs diff -u > idswitch_patch
----
The patch changes Notification to extend from BaseFunction and adjusts
Context, FunctionObject and NativeScript accordingly.
----
The patch changes BaseFunction.jsConstructor to use the scope argument
passed to execMethod instead of using cx.ctorScope. This argument is
null in this case because when calling execMethod IdFunction.construct
does not set cx.ctorScope because scope is passed to execMethod as argument.
for classes implementing the Function interface and switch
IdFunction.java to use it. The code in BaseFunction to serve as
Function.prototype is not used yet. The patch modifies NativeCall so it
can be used against BaseFunction.
The patch was made from org/mozilla directory via
diff -uN javascript.0 javascript > BaseFunction_patch
in fields of the object itself instead of using the standard property
hashtable in ScriptableObject.java. This saves 3 object instances per
NativeError (2 slot entries and hashtable array itself) and given the
fact that NativeGlobal defines a few permanent Error instances, it is
visible saving even after taking into account code size increase.
The change also gives a good test of IdScriptable implementation.
-----
This patch introduces the uniform decompile method for NativeFunction
and IdFunction with the signature:
public String decompile(Context cx, int indent, boolean justbody)
instead of NativeFunction.decompile(int indent, boolean toplevel,
boolean justbody) and IdScriptable.toStringForScript(Context cx) and
replaces the special treatment of NativeJavaMethod in
NativeFunction.jsFunction_toString by overriding decompile in
NativeJavaMethod
-----
This patch adds getFunctionName to NativeFunction to return function
name and replaces few places with jsGet_name usage by getFunctionName
The patch was made via
diff -ru javascript.0 javascript > name_patch
from org/mozilla directory
Rhino: behavior update for IdScriptable subclasses
Date:
Fri, 18 May 2001 11:45:00 +0200
From:
Igor Bukanov <igor.bukanov@windriver.com>
Organization:
Wind River
To:
Norris Boyd <nboyd@atg.com>
The attached patch introduces separation between id-base properties in
prototype instances and the rest of objects so it is possible to
allocate some ids for each instance and the rest only for prototype. The
patch adds to each descendants of IdScriptable a special prototypeFlag
which set to true only if object serves as a global prototype and all
methods that check/return ids first check for that flag. (This is the
reason for the patch size: diff is not very well in dealing with
indentation changes.)
In this way ids for prototype properties are completely hidden from
potential subclasses and there is no need to define methods like
getMaximumId in most cases, only if some ids present in each instance,
IdScriptable.maxInstanceId should be overridden to return max id present
in each instance.
The patch also replaces 2 boolean fields in IdScriptable by bit masks in
the setupFlag field.
Subject:
Embedding Rhino in an Applet
Resent-Date:
Thu, 17 May 2001 14:53:05 -0700 (PDT)
Resent-From:
mozilla-jseng@mozilla.org
Date:
Thu, 17 May 2001 16:39:14 -0700
From:
"Chester Kustarz II" <chester@monkey.org>
Organization:
monkey.org
To:
mozilla-jseng@mozilla.org
Newsgroups:
netscape.public.mozilla.jseng
Hello, I am trying to find a scripting language with an interpreter that I
can embed in an applet in order to run test scripts inside the applet. I
have already tried TCL-based Jacl and they do not support running inside an
applet. I then downloaded the Rhino/JS interpreter but am having trouble
getting it to run inside the browser (IE 5.5). Here is the exception I am
getting:
com.ms.security.SecurityExceptionEx[org/mozilla/javascript/ScriptRuntime.<cl
init>]: Reflective access to class java.lang.Thread prohibited.
at com/ms/security/permissions/ReflectionPermission.check
at com/ms/security/PolicyEngine.deepCheck
at com/ms/security/PolicyEngine.checkPermission
at com/ms/security/StandardSecurityManager.chk
at com/ms/security/StandardSecurityManager.checkMemberAccess
at java/lang/Class.checkMemberAccess
at java/lang/Class.getDeclaredMethod
at org/mozilla/javascript/ScriptRuntime.<clinit>
at org/mozilla/javascript/ScriptableObject.getExclusionList
at org/mozilla/javascript/ScriptableObject.defineClass
at org/mozilla/javascript/Context.initStandardObjects
at org/mozilla/javascript/Context.initStandardObjects
at RhinoShellApplet.init
at com/ms/applet/AppletPanel.securedCall0
at com/ms/applet/AppletPanel.securedCall
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
com.ms.security.SecurityExceptionEx[org/mozilla/javascript/Context.initStand
ardObjects]: Unable to access system property:
org.mozilla.javascript.JavaAdapter
at com/ms/security/permissions/PropertyPermission.check
at com/ms/security/PolicyEngine.shallowCheck
at com/ms/security/PolicyEngine.checkCallersPermission
at com/ms/security/StandardSecurityManager.chk
at com/ms/security/StandardSecurityManager.checkPropertyAccess
at java/lang/System.getProperty
at org/mozilla/javascript/Context.initStandardObjects
at org/mozilla/javascript/Context.initStandardObjects
at RhinoShellApplet.init
at com/ms/applet/AppletPanel.securedCall0
at com/ms/applet/AppletPanel.securedCall
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
1. In that patch I forgot to remove "import org.mozilla.classfile.*" and
simply catch Exception in newInvokerMaster which is not a good practice.
The attached patch FunctionObject_patch fixes that and removes other
unused imports.
2. In org.mozilla.classfile.DefiningClassLoader defineClass method first
tries to call via ClassManager the defineClass method in a class loader
that loaded DefiningClassLoader itself. But this would define new
classes in that class loader so they would not be subject of the garbage
collection until a classloader that loads DefiningClassLoader would go
away even if a DefiningClassLoader instance is gone. The
DefiningClassLoader_patch removes that and simply calls super.defineClass.
The patch also change the order of class search in loadClass so the
loader first looks for a class among its defined classes and only after
that in parent loaders.
Regards, Igor
1. In that patch I forgot to remove "import org.mozilla.classfile.*" and
simply catch Exception in newInvokerMaster which is not a good practice.
The attached patch FunctionObject_patch fixes that and removes other
unused imports.
2. In org.mozilla.classfile.DefiningClassLoader defineClass method first
tries to call via ClassManager the defineClass method in a class loader
that loaded DefiningClassLoader itself. But this would define new
classes in that class loader so they would not be subject of the garbage
collection until a classloader that loads DefiningClassLoader would go
away even if a DefiningClassLoader instance is gone. The
DefiningClassLoader_patch removes that and simply calls super.defineClass.
The patch also change the order of class search in loadClass so the
loader first looks for a class among its defined classes and only after
that in parent loaders.
Regards, Igor
> Igor Bukanov wrote:
>
>
>>Norris Boyd wrote:
>>
>>
>>>The intention was to keep classfile and JavaAdapter optional. Those
>>>dependencies crept in. We can use Invoker optionally--perhaps I should do
>>>some performance numbers to see if it's worth it.
>>>
>>I implemented that patch, it splits Invoker.java into Invoker.java and
>>its implementation in optimizer/InvokerImpl.java The reason to put it
>>into optimizer package is that Invoker is very similar in spirit to
>>NativeScript: it generates classes to speed up access and in this way
>>there is no need to have separated option not to use: one can simply
>>remove optimizer all together.
>>
>
> Yes, that sounds great.
>
>
>>
>>I noticed during implementation that JavaAdapter.DefiningClassLoader and
>>optimizer/JavaScriptClassLoader contains the same code, so maybe they
>>can be moved to org.mozilla.classfile package under one name?
>>
>
> Yes, that sounds like a good change too. Thanks for noticing that.
The update is pretty messy: it touches FunctionObject which I changed to
remove the special treatment of NativeWith in the previous patch, and it
also add/removes files.
Here is a description:
DefiningClassLoader.java should go to org/mozilla/classfile. It is the
same code that was in omj/optimizer/JavaScriptClassLoader.java with
class rename and adding public attribute and correspondingly
omj.optimizer/JavaScriptClassLoader.java should be removed. I guess it
would be nice to preserve logs/history in CVS during the move.
InvokerImpl.java should go to omj/optimizer. It is mostly what
omj.Invoker was.
invoker_changes_patch was generated via
cvs diff -u Invoker.java JavaAdapter.java optimizer/Codegen.java
and contains changes against the current CVS
FunctionObject_invoker_patch was generated via
diff -u ../../mozilla.1/javascript/FunctionObject.java FunctionObject.java
and contains changes against that With patch.
Igor
constructor, removes the special treatment of the With object from
IdScriptable and FunctionObject, adds to IdFunction the
initAsConstructor method similar in spirit to
FunctionObject.addAsConstructor (it is called now from IdScriptable and
NativeWith) and replaces in Context.java lazy initialization of
NativeWith by direct call of NativeWith.scopeInit.
The attached patch moves the IdFunction.Master interface to the
separated file IdFunctionMaster and eliminates getParentScope from the
interface: it is simpler to set scope explicitly.
The patch assumes the changes in IdFunction.java from the previous patch
and were produced via:
diff -uP javascript.2000-05-10 javascript
Regards, Igor
The attached patch allows subclasses of IdScriptable to override
hasIdValur/deleteIdValue and uses lazy initialization for idMapData
array to avoid its creation when an IdScriptable descendant does not
have any functions. The patch also touches NativeMath.java to replace in
its scopeInit method
super.scopeInit(cx, scope, sealed);
by
activateIdMap(cx, sealed);
This is the only reason NativeMath needs to call
IdScriptable.scopeInit() which is intended for creation
constructor/prototype pair.
Regards, Igor