create blog

go home go home
  1. about
  2. code
  3. wiki
  4. blog

Archive for the ‘Bespin’ Category

Dojo, Profiling, and Function Names

Tuesday, June 23rd, 2009

Since we are using Bespin for a new web project we are working on, it is only natural that we use the Dojo Toolkit as well. But we have had some issues with dojo.declare().

In short, when using dojo.declare(), all functions defined in a class are anonymous functions. It looks something like this:

Uh... What?

Uh... What?

Nasty. Too many “anonymous” functions.

I recalled a write-up about how a new feature had been added to WebKit (and, by extension, Safari 4): functions can have display names just for this purpose.  That would be perfect, except that I’d have to go to each function and add a "this.functionName.displayName = 'somename'", or something like that.

Then I realized that all of the classes are declared through one function: dojo.declare(). So, with a quick modification, I added these lines near the beginning of the function (you can find it in dojo.js.uncompressed.js, if you search for dojo.declare = function):

// preprocess props, updating functions
	for (var i in props)
		if (typeof props[i] == "function")
			props[i].displayName = i;

And now, that profiler output looks much better:

Much nicer output with displayName

Much nicer output with displayName

And that’s it.

Side Note

I tried first to implement it by wrapping dojo.declare kind of like this:

dojo.olddeclare = dojo.declare;
dojo.declare = function(name, base, props) {
    //stuff here
    dojo.olddeclare(name, base props);
};

It didn’t work, I think because of something to do with the arguments.callee and a few other things. So, I settled for modifying the original function.

Update

A thought just occurred to me: you can display the class name quite easily too. Just change the line that sets the display name in the above example to:

props[i].displayName = className + "::" + i;

Notes on Bespin’s Model and Cursor Positions

Wednesday, June 17th, 2009

I am writing this so that I will remember (as I have forgotten some of the things here before). However, since others may find it useful, and since I’d really like any double-checking I can get, I am publishing it.

In a web-based Create Framework related project, we are using Mozilla’s wonderful Bespin text editor. In the process of using it, we sometimes need to modify the editor in some way, perhaps by adding new features, perhaps by finding and fixing bugs.

The following is technical in nature.

(more…)