Quick summary: The sbIMediaListEnumerationListener interface has changed. Click here for the diff and keep reading for the backstory.
A few weeks ago one of our developers was having difficulty implementing the sbIMediaListEnumerationListener interface in JavaScript — it just didn’t seem to work! Check out the original IDL for this interface then have a look at the implementation code:
var updateListener = {
onEnumerationBegin: function() {
},
onEnumeratedItem: function(list, item) {
item.setProperty(SBProperties.albumArtURL, albumPath);
},
onEnumerationEnd: function() {
}
};
list.enumerateAllItems(updateListener);
Can you spot the problem? The original design of this interface defined both the onEnumerationBegin and onEnumeratedItem methods with a boolean return value that specified if the enumeration should continue. You would return true to continue or false to stop. The mistake here was not returning any value at all, which implicitly returns “undefined” to the caller. This value gets casted to a boolean false, meaning the enumeration should not continue. Whoops!
The fix here is simply to add “return true;” to the two methods. However, we felt that if even our own developers are tripping over this interface, we might want to rethink it a bit. Since continuing the enumeration is the most common case, we wanted to make it simple to do just that.
So bug 6388 was filed and the fix went in today. (See the new version here) We changed the return values of the two methods to integers and now have constants (sbIMediaListEnumerationListener.CONTINUE and sbIMediaListEnumerationListener.CANCEL) to use for the return values. This makes it very easy to tell what the code is doing rather than have to remember what returning true or false actually means.
Also, by making the CONTINUE constant equal to zero, implementations in JavaScript may omit the return statement entirely and the enumeration will continue. This should make it a lot harder for us lazy developers to shoot ourselves in the collective foot.
Has anyone else experienced any rough edges in our interfaces? If so, please let us know!










