JavaScript components should avoid nsIPropertyBag like the plague

I’ve been bitten by this a dozen times over the years. I try to find a simple data interface for getting a bunch of strings out, and I see nsIPropertyBag. I think to myself, “Hmm. That’s a pretty good choice.” Then I implement it, watch it QueryInterface for my component, and then watch it not call my getProperty() method. Why? XPConnect returns its own nsIPropertyBag object first when I try to call getProperty(). So my call goes to a different object than the one I intended.

I never, ever learn.

2 thoughts on “JavaScript components should avoid nsIPropertyBag like the plague”

  1. Doesn’t the XPConnect interface just expose all your JS object’s properties via the property bag?
    That said, not forwarding to the “real” property bag sounds like a bug to me. Filed?

Comments are closed.