Categories
Mozilla

New API Added on NetUtil

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.

By Shawn Wilsher

The man behind the site.

3 replies on “New API Added on NetUtil”

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.

@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.