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

Object.getOwnPropertyNames/getOwnPropertyDescriptor/getOwnPropertyDescriptors/for-of loop not working with NativeJavaXxxx stuff #1549

Open
p-bakker opened this issue Jul 30, 2024 · 2 comments
Labels
bug Issues considered a bug Java Interop Issues related to the interaction between Java and JavaScript

Comments

@p-bakker
Copy link
Collaborator

=>Object.getOwnPropertyNames(java.math.BigInteger)
org.mozilla.javascript.EcmaError: TypeError: Expected argument of type object, but instead had type function (internal_anon#1)

=>Object.getOwnPropertyDescriptor(java.math.BigInteger, 'valueOf')
org.mozilla.javascript.EcmaError: TypeError: Expected argument of type object, but instead had type function (internal_anon#1)

=>for (var x of java.math.BigInteger) console.log(x)
org.mozilla.javascript.EcmaError: TypeError: [JavaClass java.math.BigInteger] is not iterable (internal_anon#1)
@p-bakker p-bakker added Java Interop Issues related to the interaction between Java and JavaScript bug Issues considered a bug labels Jul 30, 2024
@p-bakker p-bakker changed the title Object.getOwnPropertyNames/getOwnPropertyDescriptor/getOwnPropertyDescriptors/for-of loop dont with NativeJavaXxxx stuff Object.getOwnPropertyNames/getOwnPropertyDescriptor/getOwnPropertyDescriptors/for-of loop not working with NativeJavaXxxx stuff Jul 30, 2024
@tuchida
Copy link
Contributor

tuchida commented Jul 30, 2024

// * NativeJavaClass
Object.getOwnPropertyNames(java.math.BigInteger)
// js: uncaught JavaScript runtime exception: TypeError: Expected argument of type object, but instead had type function
// 	at (unknown):2

// * NativeJavaObject
Object.getOwnPropertyNames(java.math.BigInteger.valueOf(0))
// js: uncaught JavaScript runtime exception: TypeError: Expected argument of type object, but instead had type object
// 	at (unknown):3

// * NativeJavaPackage
Object.getOwnPropertyNames(java.math)
// BigInteger
// 
// <- laoded Only?

// * NativeJavaMap
Object.getOwnPropertyNames(new java.util.HashMap({ a: 1 }))
// js: uncaught JavaScript runtime exception: TypeError: Expected argument of type object, but instead had type object
// 	at (unknown):3
//
// <- Is it 'a' to expect? or methods?

// * java.lang.String
Object.getOwnPropertyNames(java.lang.String.valueOf('abc'))
// js: uncaught JavaScript runtime exception: TypeError: Expected argument of type object, but instead had type object
// 	at (unknown):7
> =>for (var x of java.math.BigInteger) console.log(x)
> org.mozilla.javascript.EcmaError: TypeError: [JavaClass java.math.BigInteger] is not iterable (internal_anon#1)

I don't see a problem with NativeJavaClass being non-iterative. NativeJavaObject that I want to make iterable were supported by #846.

@tonygermano
Copy link
Contributor

I independently found this problem and mentioned it in #1615 (comment). The main problem is that Object.getOwnPropertyNames (and many other static methods on the built-in Object) requires the object being acted upon to be an instance of ScriptableObject, while most of the NativeJavaXxxx classes do not extend ScriptableObject.

I believe this is incorrect, as ScriptableObject is only supposed to be a reference implementation. However, our current interfaces do not really allow for correct implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues considered a bug Java Interop Issues related to the interaction between Java and JavaScript
Projects
None yet
Development

No branches or pull requests

3 participants