Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value.GetMemberKeys() does not include functions in class #678

Closed
MichaelHaibinXie opened this issue Sep 18, 2018 · 10 comments
Closed

Value.GetMemberKeys() does not include functions in class #678

MichaelHaibinXie opened this issue Sep 18, 2018 · 10 comments
Assignees
Labels
tracking This issue has an analogue in an internal issue tracker truffle

Comments

@MichaelHaibinXie
Copy link

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;
}

}

@chumer
Copy link
Member

chumer commented Sep 19, 2018

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.

@MichaelHaibinXie
Copy link
Author

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
Copy link
Author

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

@chumer
Copy link
Member

chumer commented Sep 20, 2018

@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?

@MichaelHaibinXie
Copy link
Author

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?

@quinton-hoole
Copy link

quinton-hoole commented Mar 23, 2019

@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"

@chumer
Copy link
Member

chumer commented Mar 28, 2019

@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.

@quinton-hoole
Copy link

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

@boris-spas
Copy link
Member

Tracking internally as Issue GR-20913

@boris-spas boris-spas added the tracking This issue has an analogue in an internal issue tracker label Jan 29, 2020
@wirthi wirthi assigned chumer and unassigned wirthi Jul 18, 2022
@spavlusieva
Copy link
Member

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 spavlusieva closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracking This issue has an analogue in an internal issue tracker truffle
Projects
None yet
Development

No branches or pull requests

7 participants