Closed
Bug 121966
Opened 23 years ago
Closed 23 years ago
Should "eval()" work with java.lang.String?
Categories
(Rhino Graveyard :: Core, enhancement)
Rhino Graveyard
Core
Tracking
(Not tracked)
VERIFIED
INVALID
1.5R3
People
(Reporter: steve, Assigned: norrisboyd)
References
()
Details
The following does not work as I'd assume it would:
js> s = new java.lang.String("print('hey')");
print('hey')
js> eval(s)
print('hey')
In order to evaluate the java.lang.String, it must be a JavaScript string:
js> eval("" + s)
hey
Came across this when experimenting with sending code over sockets,
remote code/message execution stuff. Quite cool.
Should be easy enough to add to Rhino; even I could probably figure out
how to do it. Not sure what the "right thing" to do is; the work-around is
certainly reasonable in any case and one can argue it offers a slight bit of
security, but it's slightly inconsistent in that one would expect Strings to be
strings...
Assignee | ||
Comment 2•23 years ago
|
||
I believe this is the correct behavior, although you could argue the language
should have been designed differently. Note that even the built-in JavaScript
String object shows the same behavior:
js> eval(new String("3 + 4"))
3 + 4
Here's the relevant ECMA section:
15.1.2 Function Properties of the Global Object
15.1.2.1 eval (x)
When the eval function is called with one argument x, the following steps are taken:
1. If x is not a string value, return x.
....
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Comment 3•23 years ago
|
||
Marking Verified. Steve, thank you for this report -
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•