Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Annotation based host objects

40 views
Skip to first unread message

Hannes Wallnoefer

unread,
Aug 30, 2009, 4:22:07 AM8/30/09
to
I've submitted a patch for writing Rhino host classes using Java
annotations instead of the js*_ naming conventions. The feature is
roughly explained in the first comment of the bug report, and there's
a test case included in the patch.

https://bugzilla.mozilla.org/show_bug.cgi?id=513369

I'd be happy to get some feedback regarding implementation details
such as naming, general design etc. It's the first time I'm writing
annotation classes, so I may have made some beginners mistakes.

Hannes

Hannes Wallnoefer

unread,
Aug 31, 2009, 6:33:57 AM8/31/09
to

Daniel Friesen

unread,
Sep 23, 2009, 5:15:08 AM9/23/09
to
I've started experimenting it in MonkeyScript as well.

What I don't get his the proper way to handle the prototype for a class.
(Try and find the class prototype, or grab Object prototype) doesn't
seam right.

--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

Hannes Wallnoefer

unread,
Sep 23, 2009, 3:48:41 PM9/23/09
to
On Sep 23, 11:15 am, Daniel Friesen <dan...@nadir-seen-fire.com>
wrote:

> I've started experimenting it in MonkeyScript as well.
>
> What I don't get his the proper way to handle the prototype for a class.
> (Try and find the class prototype, or grab Object prototype) doesn't
> seam right.

The prototype is still created using the zero-args constructor of the
class. I haven't changed anything in that regard, the general
procedure is still the one described here:

http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/ScriptableObject.html#defineClass%28org.mozilla.javascript.Scriptable,%20java.lang.Class%29

(BTW, this feature needs documentation, and the API doc for
ScriptableObject.defineClass is one place where it should be
documented, the other one is http://www.mozilla.org/rhino/tutorial.html#javaScriptHostObjects)

If you want to customize prototype/constructor/scope setup, the best
thing is to implement finishInit() as described in the API docs above.
For example, in my CommonJS Binary/B host class, I only set up the
abstract Binary base class in the automatic defineClass, and then
create the ByteArray and ByteString classes in finishInit.

http://github.com/hns/helma-ng/blob/master/src/org/helma/wrappers/Binary.java#L121

Hannes

>
> Hannes Wallnoefer wrote:
> > I've started rewriting Helma NG host objects to the new annotation
> > based format, and it's looking and feeling quite good:
>

> >http://github.com/hns/helma-ng/blob/88ef182f47abbc8df7a1aef0ce60e82bc...
> >http://github.com/hns/helma-ng/blob/88ef182f47abbc8df7a1aef0ce60e82bc...

Daniel Friesen

unread,
Sep 23, 2009, 11:58:19 PM9/23/09
to
Sorry I found out my issue.
I was 2 commits behind the commit that introduced the annotations.
I hadn't updated because the commit right before the one introducing the
annotations broke Rhino.
I cherry-picked the annotation commit in.
0 new messages