Closed Bug 491433 Opened 15 years ago Closed 6 years ago

__lookupSetter__ doesn't work well with host objects

Categories

(Rhino Graveyard :: Core, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INACTIVE

People

(Reporter: djgredler, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
Build Identifier: Rhino 1.7R2

Calling __lookupSetter__ to get a setter defined in a Java host object returns a MemberBox, which is not a JavaScript-usable Function -- so you can't .call() the returned setter, for example.

The code below illustrates the problem; test1() works as expected, but test2() does not:

public class LookupSetterTest {

    @Test
    public void test1() throws Exception {
        test("Foo.__defineSetter__('x', function() {}); typeof Foo.__lookupSetter__('x');");
    }

    @Test
    public void test2() throws Exception {
        test("typeof (new Foo()).__lookupSetter__('s')");
    }

    private void test(String src) throws Exception {
        Context cx = Context.enter();
        try {
            Scriptable scope = cx.initStandardObjects();
            ScriptableObject.defineClass(scope, Foo.class);
            Object result = cx.evaluateString(scope, src, "test", 1, null);
            Assert.assertEquals("function", result);
        } finally {
            Context.exit();
        }
    }

    public static class Foo extends ScriptableObject {
        private static final long serialVersionUID = 2997084265543252674L;
        private String s;
        public Foo() { /* Empty. */ }
        public String jsGet_s() { return this.s; }
        public void jsSet_s(String s) { this.s = s; }
        public String getClassName() { return "Foo"; }
    }

}

Reproducible: Always

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

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