On Jul 31, 4:31 am, Norris Boyd <[EMAIL PROTECTED]> wrote:
> On Jul 30, 3:16 pm, Ivan Voras <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 30, 11:43 pm, Norris Boyd <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 30, 4:22 pm, Ivan Voras <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > I'm trying to create a Java class that will be used in JS with a
> > > > varargs constructor.
>
> > > > As I understand it, I can't declare a jsConstructor and have it work
> > > > with varargs. The next thing I tried was, following the documentation
> > > > of FunctionObject, to create a constructor with the arguments (Context
> > > > cx, Object[] args, Function ctorObj, boolean inNewExpr), create a
> > > > FunctionObject for this constructor and add it with scope.put(). This
> > > > also doesn't work: I get a ClassCastException in the JS line that
> > > > creates the object: something tries to cast the new class object to
> > > > the class of the scope it's in (and they're unrelated - thus the
> > > > exception).
>
> > > > As an alternative, I see the addAsConstructor() method of the
> > > > FunctionObject but whatever I give as the prototype argument makes it
> > > > fail in different ways.
>
> > > > So, how to create a hosted Java class accessible to the JS code with a
> > > > varargs constructor?
>
> > > More easily, you could use a Java constructor with variable argument
> > > lists, 
> > > seehttp://developer.mozilla.org/en/docs/New_in_Rhino_1.6R6#Support_for_c...
>
> > > Will that work for you?
>
> > If you mean define a jsConstructor with varargs argument, like "public
> > void jsConstructor(Object ... args)", then no, it doesn't work. The
> > exception I get is "Unsupported parameter type "[Ljava.lang.Object;"
> > in method "jsConstructor"."
>
> > This is Rhino 1.7.
>
> No, I meant simply define a plain Java class, but with Java
> constructor with Java varargs:
>
> public class Foo {
>   public Foo(Object... arguments) { ... }
>
> }
>
> Then wrap Foo objects with
> org.mozilla.javascript.Context.javaToJS(fooObject).

Thanks, I'll try that.

> (Incidentally, you should be able to define JavaScript constructors
> using jsConstructor if you use ScriptableObject.defineClass to process
> the class. But the way I outlined above is much easier.)

I'm already using defineClass and it works in the general case, only
not with varargs (as described above - I get Unsupported parameter
type exception).
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to