Closed Bug 453997 Opened 17 years ago Closed 7 years ago

Handle varargs methods in Java => Javascript

Categories

(Rhino Graveyard :: Core, defect)

head
x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INACTIVE

People

(Reporter: otaylor, Unassigned)

Details

Attachments

(2 files)

When calling methods on Java objects, Java Varargs are handled as expected. If you have a Java method format(String fmt, Object... arg) then you can call it as format("Hello %s", "World"), instead of ("Hello %s", ["World"]). However, going the other way, if I have an interface with the same format() method, then the mapping into JavaScript is unexpected and inconsistent with that. 'format' : function formatImpl(fmt) { // fmt is "Hello %s" // arguments[1] is ["World"], should be "World" } I'll attach a patch that implements this. I think the patch is pretty solid. There is obviously some potential for incompatibility, but my feeling that the combination of varargs and implementing Java interfaces from Java is pretty rare (Otherwise, someone would have complained already.), so there is little code to break. One conceivably controversial part of the patch is that it never wraps primitive types when converting Java variable arguments to JavaScript. Even if WrapFactory.javaPrimitiveWrap is has the default value of true. My feeling here is that if I write a function 'void doSomething(Integer i)' in Java then I had something weird in mind, and presenting that 'i' as a wrapped Java object might make sense. But if I write 'format("%d bottles of beer on the wall, 99)' then I had nothing strange in mind, and 99 should just be a number in JavaScript. The patch I'll attach is incremental on top of the patch in bug 453990. The test case I'll attach is a patch to the test case in bug 453990. (Bug 453990 is an attempt to avoid have extraneous bug fixes mixed in here.

Closing. Bug management is now done here:
https://github.com/mozilla/rhino

Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: