Improve overloaded method invocation when null is passed. #1352
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We often have to deal with overloaded methods like
When invoking such methods from rhino, everything is fine, as long as the value is not undefined or null
Currently, there's no way to pass null to an overloaded value, as javascript cannot determine, which method should be called.
Possible fix
Adjusting the conversion weight for
JSTYPE_UNDEFINED
andJSTYPE_NULL
:Converting them to String should weight less than converting them to Object (this means, that
setValue(String)
will be preferred)Note and room for discussion
I know, the choiche to favor String over Object is closely related to our use-case (and I'm OK if we can find a consent in which order such conversion should happen)
What I really want is to invoke overloaded methods with "null" values.
Unfortunately I cannot do a
setValue((String)null)
orsetValue((Object)null)
in javascriptIt may be possible to construct some hacky null type for java classes (e.g.
String.null
Integer.null
and so on)