Java interop for primitive types #1502
tonygermano
started this conversation in
General
Replies: 1 comment 1 reply
-
|
Also see #996 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I was creating PR #1501 I noticed a couple things that I thought were worthy of bringing up for discussion.
char
Java
chargets converted to a jsnumber, but whenisJavaPrimitiveWrapis false in the Context's WrapFactory,java.lang.Charactergets converted to a jsstringinstead. This seems inconsistent, but it's been this way forever.long
Java
longgets converted to anumber, and likewise whenisJavaPrimitiveWrapis false,java.lang.Longalso gets converted to anumber(see below for some quirks regarding this.) This causes a java widening conversion to occur, and an unavoidable loss of precision when the value is outside of the range of[Number.MIN_SAFE_INTEGER - Number.MAX_SAFE_INTEGER]. This can make it challenging to impossible to work with classes likejava.util.UUID.Now that we have
BigIntsupport, which obviously did not exist when this class was first written, I wonder if we should give the option to convertlongtobigintso that Rhino can support true 64-bit integer interop with java. I think it would make sense to do this as a WrapFactory flag likeisJavaPrimitiveWrap. Likewise, I think bigint values should be automatically truncated (by calling BigInteger::longValue) when passed to java methods requesting along.Here are the current quirks I mentioned:
Beta Was this translation helpful? Give feedback.
All reactions