Skip navigation

Did you know about the handy NetUtil object available when you import NetUtil.jsm? I bet you didn’t since it’s fairly new! There’s no MDC page yet, but the API is getting even better. Bug 508902 added a new method on NetUtil to create nsIURI objects. NetUtil will cache the IO Service so the calling site doesn’t have to. As more code starts to use this, fewer objects will have to cache the IO Service themselves.

The API mirrors nsIOService‘s newURI method with one minor improvement; the last two arguments are optional. Most callers in JavaScript tend to pass null for those last two arguments anyway, but when using NetUtil.newURI, they just have to pass the spec which should be easier.

New JavaScript code that needs to create nsIURI objects should start using this method.

3 Comments

    • Dao
    • Posted September 3, 2009 at 11:24 (11:24 am)
    • Permalink

    The last two arguments have always been optional, afaik, regardless of what some callers did.

    There’s also a makeURI function that can be used in the browser.xul scope.

  1. I checked what ioService API I’m using – mostly newURI of course but also newChannel and newFileURI. Particularly for that latter a wrapper that accepts both nsIFile and plain path strings would be nice.

  2. @Wladimir
    Ryan Flint is exposing nsIIOService on NetUtil in bug 514415, but I can easily see us extending newURI to also take an nsIFile object as well as make a more useful newChannel for JavaScript too. Would you like to file the bug for that? If you make the patch, I can promise a quick review too!


Comments are closed.