Helma logo
main list history

Metamethods

Update: as of 2008/10/15, metamethod support has been removed from Helma. It had too much of a performance impact, and most things can be achieved by other means, often reducing complexity.

Since I have gotten a more frustrated with JSAdapter lately, I have started working on a new metaprogramming extension to Rhino which I call Metamethods. It is based on JOMP, but looks for methods in the target object itself rather than a separate meta object. It is also thread-safe and adds a method to control behavior of the equals operator (==).

In detail, Metamethods looks for the following methods in a JavaScript object:

  • __has__(property): this method is called when checking for a property
  • __get__(property): this method is called when getting a property
  • __set__(property, value): this method is called when setting a property
  • __delete__(property): this method is called when deleting a property
  • __getIds__(): this method is called when iterating over property ids
  • __hasInstance__(object): this method is called when the instanceof operator is used
  • __equals__(object): this method is called when the == operator is used

Currently you have to manually patch and build Rhino to use Metamethods using the patch attached to this page.

Update 1: The patch is in the current svn/git snapshots, but of course you can still use the patch to build it by yourself.

Update 2: Due to a very silly bug, __set__ methods were called without the second argument in the initial version. This is fixed in the new patch as well as git/svn repositories.

nametypesize
metamethods.patchtext/x-diff15772 bytes
metamethods-2.patchtext/x-diff15210 bytes
metamethods-test.jsapplication/x-javascript515 bytes

This patch is against the current Rhino CVS snapshot. Let me know if it fails to apply to earlier versions of Rhino.