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

Metaobject Protocol for JavaScript

49 views
Skip to first unread message

t...@bias2build.com

unread,
Dec 21, 2007, 9:23:04 PM12/21/07
to dev-tech-js-...@lists.mozilla.org
Hi,

I'm not sure if there will be much interest in this or not... I've been
experimenting with adding a metaobject protocol to JavaScript, and I
modified Rhino to implement it. I've put up a page that gives an
overview:

http://www.bias2build.com/thesis/javascript_mop_expanded.html

The cool thing is that it was relatively simple to put together --
JavaScript's design seems to let you do a lot with pretty minimal changes.
I've been pleased with the result so far.

Feedback is welcome. Am I missing any big pieces in what a MOP should
cover? Does this seem straightforward to use? I appreciate any insights.

Thanks, and happy holidays.

--Tom

Norris Boyd

unread,
Dec 30, 2007, 1:50:43 PM12/30/07
to

This is interesting, thanks... I don't know if you know about it, but
Rhino now has __noSuchMethod__, which is an analog to method_missing:

Rhino 1.7 release 1 Pre 2007 12 26
js> obj = { __noSuchMethod__: function f(name, args)
{ print(name,args); } }
[object Object]
js> obj.fooBar(3,4)
fooBar 3,4

--N

Norris Boyd

unread,
Dec 30, 2007, 4:07:26 PM12/30/07
to

Apologies... I see from your you do know about this from your link.
Just missed it before.

--N

Hannes Wallnoefer

unread,
Jan 10, 2008, 10:24:58 AM1/10/08
to
On Dec 22 2007, 3:23 am, t...@bias2build.com wrote:
> Hi,
>
> I'm not sure if there will be much interest in this or not... I've been
> experimenting with adding a metaobject protocol to JavaScript, and I
> modified Rhino to implement it. I've put up a page that gives an
> overview:
>
> http://www.bias2build.com/thesis/javascript_mop_expanded.html
>
> The cool thing is that it was relatively simple to put together --
> JavaScript's design seems to let you do a lot with pretty minimal changes.
> I've been pleased with the result so far.

I find this very intriguing. I've been playing around with JSAdapter
from the Phobos project (that's also bundled with the Rhino in Java
6), and I've just committed support for it to Helma as an experimental
feature.

http://blogs.sun.com/sundararajan/entry/self_javascript_and_jsadapter

All currently implemented meta-object features in Rhino are piecemeal
in one way or other. Getter/setter support only works for explicitly
handled properties, __noSuchMethod__ only supports method invocation,
not property access. It's a good thing we have these, because they
make Rhino compatible with Spidermonkey, but they're just not powerful/
generic enough. JSAdapter is so far the most complete solution, but it
requires another adapter/wrapper and can't be used with plain
javascript objects directly.

With a metaobject protocol like this, it becomes practical to
implement host objects in Javascript instead of Java. IMO, being able
to write a framework in the target (embedded) language rather than the
host language is a great boon. This is one of the main advantages the
Ruby guys have on us. Imagine if Rails was written completely in C
instead of Ruby! Yet, most Rhino embeddings are more or less pure
Java.

I really hope this or something similar can become part of Rhino.

hannes

Hannes Wallnoefer

unread,
Jan 15, 2008, 6:52:54 AM1/15/08
to

I did some more testing, comparing your solution with the JSAdapter
approach. I wrote my findings down here:

http://dev.helma.org/wiki/Comparison+of+JSAdapter+and+JOMP/

The problems I see with JOMP is that it adds overhead to each and
every JS object property access, and that it is not thread-safe. Helma
is a multithreaded server application, so concurrent property access
is pretty much the norm. Apart from that, I'd definitely prefer JOMP
over JSAdapter because it feels much more like pure Javascript.

hannes

0 new messages