graal icon indicating copy to clipboard operation
graal copied to clipboard

Value.GetMemberKeys() does not include functions in class

Open MichaelHaibinXie opened this issue 7 years ago • 9 comments

I have a function in class, Value.GetMember("functionName") returns true, however Value.getMemberKeys() does not include "functionName" in the keys.

Here is the code that I tried, any idea?

----------Test.java----------- Value v = polyglot.eval(Source.newBuilder("js", new File(jsHome + "/college.js")).build()); Value v1 = polyglot.eval("js", "new College()"); // *****************this returns true System.out.println("is there setName member? " + v1.hasMember("setName"));

// ******************Problem: this does not contain setName function System.out.println("all member keys: " + v1.getMemberKeys());

----------College.js----------- class College { constructor() { this.name = "defaultcollege"; this.students = []; }

setName(name) {
    this.name = name;
}

getName() {
    return this.name;
}

addStudent(student) {
    this.students.push(student);
}

getStudents() {
    return this.students;
}

toString() {
    return this.name + this.students;
}

}

MichaelHaibinXie avatar Sep 18 '18 21:09 MichaelHaibinXie

Yes. Non enumerable JS properties currently don't show up in the member keys. We will change that but it needs some extension to our interop protocol, which will take a bit.

chumer avatar Sep 19 '18 11:09 chumer

I use CE RC5 version and looks like it works. One follow up question, is there any way to scan parameters of a function? in the example if I get Value representing the fuction by Value.getMember("setName"), can I scan parameters from the Value. I saw it has a member arguments, but when I try to getMember("arguments") it throws exception.

MichaelHaibinXie avatar Sep 19 '18 21:09 MichaelHaibinXie

To be more specific, originally I was using ee rc6 when having this issue.

MichaelHaibinXie avatar Sep 19 '18 21:09 MichaelHaibinXie

@MichaelHaibinXie yes it temporarily worked for RC5. But we had to roll back for RC6 as we have seen problems with this behavior.

What exception does getMember it throw?

chumer avatar Sep 20 '18 09:09 chumer

I dont have the exception now as I switched to RC5. I will post later if I see it again. Thanks for help.

Is there a way to scan parameters of member that is a function?

MichaelHaibinXie avatar Sep 21 '18 17:09 MichaelHaibinXie

@chumer Was this ever fixed? I still seem to be seeing the same problem in community RC14. If not, any estimate on when or if it might ever get fixed? To be clear i'm referring to the original problem reported in this issue, i.e. "Value.getMemberKeys() does not include functions in class"

quinton-hoole avatar Mar 23 '19 02:03 quinton-hoole

@quinton-hoole-2 Unfortunately no. It takes longer because it involves some interop protocol changes. The way to do this atm is by calling a JavaScript method that returns all the symbols. You can then read/write or invoke them.

chumer avatar Mar 28 '19 13:03 chumer

Thanks @chumer. We'll use that workaround in the mean time.

quinton-hoole avatar Mar 28 '19 15:03 quinton-hoole

Tracking internally as Issue GR-20913

boris-spas avatar Jan 29 '20 09:01 boris-spas

hi @MichaelHaibinXie , this issue has been inactive for more than 180 days. We’ll close it to focus on current issues. In case it’s still relevant, please reopen it and we’ll take another look. Thank you!

spavlusieva avatar Nov 23 '23 15:11 spavlusieva