Closed
Bug 72021
Opened 24 years ago
Closed 23 years ago
The ScriptRuntime class tries to convert even the String values to JavaNativeObject
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R4
People
(Reporter: anup, Assigned: norrisboyd)
Details
Attachments
(1 file, 1 obsolete file)
515 bytes,
text/plain
|
Details |
The rhino script engine converts every java object that the application passes
(if it is not a Scriptable object) to the JavaNativeObject. Our applaiction
passes a String object to script runtime and it converts it to the
NativeJavaObject. Now if the user tries to increment or decrement the string
object in the script the runtime callls the "doubleValue" method by default to
convert the string to number and this fails since there is no method
named "doubleValue" implemented in the class String.
However if the user directly declares a String object inside the script the
script runtime recognizes it as such and deals with it correctly.
I think the script runtime should also recognize the String object returned by
the application that is using it. And should do the correct conversion to
number and boolean in the same way that it does for the String objects defined
inside the script.
Comment 1•24 years ago
|
||
I have come across the same problem. Below is a sample of scripts which will
reproduce the problem when run in the Rhino shell Main:-
a = new java.lang.String("TEST");
a <= "TEST";
Below is a work around by changing 'a' to javascript string:-
a = new java.lang.String("TEST");
b = new String(a);
b <= "TEST";
Comment 3•23 years ago
|
||
In the current Rhino tip it is possible to convert java.lang.String returned by
Java methods directly to JS String via simple:
Context cx = Context.enter();
cx.getWrapFactory().setJavaPrimitiveWrap(false);
See API documentation for
org.mozilla.javascript.WrapFactory#isJavaPrimitiveWrap() in the current tip for
details.
Note that this does not make to work:
a = new java.lang.String("TEST");
a <= "TEST";
as WrapFactory#setJavaPrimitiveWrap(boolean) does not affect explicit
constructor calls, but if one wish to completely replace Java String, he can
override WrapFactory#wrapNewObject to return new JS String object for Java
String. See the following attachment for details.
Comment 4•23 years ago
|
||
With this MyWrap class that example works as expected:
Rhino 1.5 release 4 0000 00 00 (in progress)
js> var cx = Packages.org.mozilla.javascript.Context.getCurrentContext();
js> var wrap = new Packages.MyWrap(cx);
js> var a = new java.lang.String("TEST");
js> a <= "TEST";
true
Attachment #28699 -
Attachment is obsolete: true
Comment 5•23 years ago
|
||
I mark the bug as fixed as the required functionality is already available with
minimal setup.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Comment 6•23 years ago
|
||
Marking Verified. Anup, please reopen if you disagree -
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•