Saturday, November 15, 2008

Joose now passes all tests under Rhino

Joose has been running alright under Rhino, but there have always been some failing tests due to different behavior in Rhino when compared to most other JavaScript engines.

Most JS engines traverse objects in declaration order. That means when you loop over an JS object like
isa: "SuperClass",
does: "Role",
methods: {
test: function () {}

the loop will return the properties in the object in the order "isa", "does", "methods".

Now because object literals are used to initialize Joose classes this traversion order can be really important when Joose is initializing classes. While all JS engines used in web browsers use the de-facto-standard traversion order, Rhino traverses objects in random order. It is important to state that the ECMAscript standard does specifically not define the traversion order, so from a standards point of view Rhino is right on this one.

While we might add automatic detection of Rhino to Joose, for now you will have to define this.CHAOTIC_TRAVERSION_ORDER = true in global scope before loading Joose to enable the work-around.

This work-around works like this. No matter how you write your class declarations, Joose will always evaluate the class properties "isa", "does", "has", "method", "methods" first (and in that order).

To try out Joose under Rhino check out Joose from svn and run playground/rhino/rhino_test.js with Rhino.

No comments: