Debugging support

The 2.1 release introduced support for WebKit’s displayName property for profiling and debugging JavaScript. Essentially, it is a workaround for the fact that JavaScript objects and functions do not have names directly attached to them, and can be referenced by any number of variables, thus making objects and functions basically anonymous.

WebKit’s profiler and debugger improves the situation by using the displayName assigned to a Function object if one has been assigned. jsclass generates display names for methods and inner classes, so long as you specify a name for the outermost class. Class (and module) names are optional and are specified using the first argument to the Class and Module constructors. For example:

Foo = new Module('Foo', {
    sleep: function() { /* ... */ },

    extend: {
        eatFood: function() { /* ... */ },

        InnerClass: new Class({
            haveVisions: function() { /* ... */ }
        })
    }
});

The name does not have to be the same as the variable you assign the module to, although it will probably be more helpful if the names are the same. The name given is not used for variable assignment, though.

Given the above definition, we now find displayName set on the methods and the inner class:

Foo.instanceMethod('sleep').displayName
// -> "Foo#sleep" 

Foo.eatFood.displayName
// -> "Foo.eatFood" 

Foo.InnerClass.displayName
// -> "Foo.InnerClass" 

Foo.InnerClass.instanceMethod('haveVisions').displayName
// -> "Foo.InnerClass#haveVisions"

Further debugging support is provided by the StackTrace module.