Closed Bug 398375 Opened 17 years ago Closed 5 years ago

InterfaceAdapter and java.lang.Object methods

Categories

(Rhino Graveyard :: Core, enhancement)

1.7R1
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED INACTIVE

People

(Reporter: mozilla.bugs, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
Build Identifier: 1_7R1pre

When passing a function as an interface a proxy is created which not only delegates interface methods calls to the function but also calls to methods defined in java.lang.Object.
It follows that those proxies can't be used in a HashMap or a HashSet (hashCode and equals going through the js function).

(Calls can be discriminated by using arguments[arguments.length - 1] which contains the method name but it's awkward and seems to violate the constraint that all methods must have the same signatures.)


Reproducible: Always

Steps to Reproduce:
package bug;
public class Foo {
  Set d = new HashSet();
  public add(Callable c) {
    s.add(c);
  }
}
-------------
var f = new Packages.bug.Foo();
f.add(new function() { return true; });
Actual Results:  
Exception while trying to convert true into an int (hashCode return type).

Expected Results:  
The proxy being added to the set.
Attached patch Proposed patch.Splinter Review
Delegate only interfaces methods to the js function, use identity for "equals", delegate other methods to the target (java) object.
Version: other → 1.7R1
Severity: normal → enhancement

Closing. Bug management is now done here:
https://github.com/mozilla/rhino

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: