Helma logo
main list history

Comparison of JSAdapter and JOMP

This is a comparison of JSAdapter and JOMP, two approaches to add metaprogramming features to Rhino.

JSAdapter

  • Inheritance not as easy as with plain JS objects. Normal use needs wrapped object, but for prototype use in inheritance chain we need unwrapped adaptee object. As a result we need separate constructors/factory methods for the wrapped and unwrapped object, or wrap the object manually.
  • getDefaultValue is forwarded to the adaptee object, so a toString() that relies on adapter functionality won't work. This is rather easy to fix.

JOMP

  • Adds overhead to all property access methods of the default JS object.
  • Not thread-safe. Making it threadsafe would probably require using a java.lang.ThreadLocal to disable the metaobject during invocation, which would put an even bigger burden on the default JS object.

Test code

This is a script that implements a base and extended object using both techniques, and a patch for adding JOMP support to Rhino.

nametypesize
TestObject.jsapplication/javascript1860 bytes
metaobject.patchtext/x-diff16507 bytes