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

RESOLVED FIXED in 1.5R5

Status

Rhino
Core
RESOLVED FIXED
15 years ago
14 years ago

People

(Reporter: Igor Bukanov, Assigned: Norris Boyd)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

15 years ago
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.
(Reporter)

Comment 1

15 years ago
Created attachment 129655 [details] [diff] [review]
Fix: search protype chain until an instance of Java "this" class is found
(Reporter)

Comment 2

15 years ago
I cimmitted the fix
Status: NEW → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → FIXED
(Reporter)

Comment 3

14 years ago
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.