JavaAdapter method lookup does not follow prototype chain

RESOLVED FIXED

Status

Rhino
Core
P3
normal
RESOLVED FIXED
18 years ago
18 years ago

People

(Reporter: Matthias Radestock, Assigned: Norris Boyd)

Tracking

Details

Attachments

(2 attachments)

(Reporter)

Description

18 years ago
Define a simple Java interface as follows:

public interface Foo {
    public int bar(int x);
}

and then run the following Javascript program:

var foo = {}
foo.__proto__.bar = function(x) { return x; }
foo.bar(10);	//=> 10
var f = new JavaAdapter(Packages.Foo,foo);
f.bar(10);	//=> 0

The invocation of "bar" on "f" returns 0 instead of 10. That is because 
JavaAdapters do not follow the prototype chain on attribute/method lookup.

btw, we get "0" because of another problem - a failed method lookup results in 
"undefined" being returned, which gets converted to 0 by the JavaAdapter.
(Reporter)

Comment 1

18 years ago
Created attachment 13053 [details] [diff] [review]
fix for both problems - I haven't done any extensive testing on this, but it *does* fix the test case
(Assignee)

Comment 2

18 years ago
Created attachment 13057 [details] [diff] [review]
Another proposed patch
(Assignee)

Comment 3

18 years ago
I believe my changes to your patch handle the case where the function isn't 
defined more rigorously. (Curse my initial laziness to not fix the TODO.)

What do you think?
Status: NEW → ASSIGNED
(Reporter)

Comment 4

18 years ago
Norris, your fix looks good to me.
(Reporter)

Updated

18 years ago
Depends on: 49350
(Assignee)

Comment 5

18 years ago
Cool. Thanks for all your help with these. You're fast with the patches!

I'll run regression tests on this change tonight and check it in tomorrow if all 
goes well.
(Assignee)

Comment 6

18 years ago
Sorry--a little slow on this.

Checking in now.
Status: ASSIGNED → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.