Closed Bug 215923 Opened 21 years ago Closed 21 years ago

too shallow search for "this" when calling reflected Java methods

Categories

(Rhino Graveyard :: Core, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: igor, Assigned: norrisboyd)

Details

Attachments

(1 file)

When a prototype chain contains more then one wrapped Java object obtained
through Context.toObject(), Rhino uses the first Java object as Java "this" when
scripts calls methods found in other objects.

For example, the following code:

var proto1 = java.lang.Integer(1);
var proto2 = java.lang.Boolean(false);
proto2.__proto__ = proto1;

var o = { __proto__: proto2 };

var ok = (false == o.booleanValue());

ok = ok && (1 == o.intValue());

print(ok);

throws an exception when it applies () to "o.intValue" instead of printing
"true" at the end. It happens because during evaluating of "o.intValue()"
intValue is located in Integer and then it is applied to a Boolean instance.  

This is rather inconsistent since Rhino should either not to look for prototype
chain for Java this (so o.booleanValue() should fail) or look all the whole
prototype chain until it finds one. The first behavior is restrictive even if
adheres better to semantics of JS function calls while the second allows to
build a prototype chain of Java objects to expose all their methods in a
convenient way.
I cimmitted the fix
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: