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

Custom .toSting behavior for (overloaded) Java methods in the shell (for easier development/debugging) #1554

Open
tuchida opened this issue Aug 2, 2024 · 1 comment
Labels
Debugging JavaScript Issues related to tools for debugging JavaScript with Rhino Java Interop Issues related to the interaction between Java and JavaScript

Comments

@tuchida
Copy link
Contributor

tuchida commented Aug 2, 2024

ref. #1537 (comment)
Debugging with JavaScript toString is subject to the constraints of the ECMA 262 specification. Therefore, it is difficult to debug JavaObject/JavaClass/JavaMethod, etc. without violating the specification.
With console.log, the implementation can decide on a useful format.
https://console.spec.whatwg.org/#printer

This is a prototype. If it looks good to you, brush up and make a Pull Requst.
https://github.com/mozilla/rhino/compare/master...tuchida:debugging-java-using-console?expand=1

$ ./gradlew run -q --console=plain --args="-version 200"
Rhino 1.7.16-SNAPSHOT
js> console.log(java.util.Arrays.copyOf)
INFO [JavaMethod copyOf]
  float[] copyOf(float[],int)
  char[] copyOf(char[],int)
  long[] copyOf(long[],int)
  byte[] copyOf(byte[],int)
  int[] copyOf(int[],int)
  double[] copyOf(double[],int)
  java.lang.Object[] copyOf(java.lang.Object[],int)
  boolean[] copyOf(boolean[],int)
  short[] copyOf(short[],int)
  java.lang.Object[] copyOf(java.lang.Object[],int,java.lang.Class)

js> console.log(java.math.BigInteger)
INFO [JavaClass java.math.BigInteger]
  java.math.BigInteger(int,byte[])
  java.math.BigInteger(java.lang.String,int)
  java.math.BigInteger(byte[],int,int)
  java.math.BigInteger(byte[])
  java.math.BigInteger(int,byte[],int,int)
  java.math.BigInteger(int,int,java.util.Random)
  java.math.BigInteger(int,java.util.Random)
  java.math.BigInteger(java.lang.String)

js> console.log(new java.math.BigInteger(0))
INFO [JavaObject java.math.BigInteger]
  0
js> console.log(new java.util.HashMap({ a: 1, b: 2 }))
INFO [JavaMap java.util.HashMap]
  {a=1.0, b=2}
@p-bakker p-bakker added Java Interop Issues related to the interaction between Java and JavaScript Debugging JavaScript Issues related to tools for debugging JavaScript with Rhino labels Aug 7, 2024
@tuchida tuchida closed this as completed Aug 12, 2024
@p-bakker p-bakker reopened this Sep 1, 2024
@p-bakker p-bakker changed the title Debugging Java using console Custom .toSting behavior for (overloaded) Java methods in the shell (for easier development/debugging) Sep 6, 2024
@p-bakker
Copy link
Collaborator

p-bakker commented Sep 6, 2024

Also see #1420, which is another case that requires custom toString handling in the shell

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

No branches or pull requests

2 participants