January 14, 2013
BXR - my implementation of mxr

I would like to share with you a new tool, which was written over the weekend: bxr.

This tool implements a subset of the functionalities of mxr.mozilla.org using a local database and it can be used as a standalone application or combined with vim.

This is how I use it:

$ cd ~/Sources/m/central # this is a checkout of mozilla-central
$ bxr create .

With this command, bxr indexes the source tree and creates the database (.bxr.db). This operation should be done each time the tree is updated. It takes about 25 minutes.

Then, for searching, just type:

$ bxr identify nsIDOMFile

Result for: nsIDOMFile

File: ./content/base/public/nsDOMFile.h
Line: 37 -> class nsDOMFileBase : public nsIDOMFile,

File: ./ipc/glue/InputStreamUtils.cpp
Line: 14 -> #include "nsIDOMFile.h"
....

At the moment BXR can be used to:

  • identify, to search for the definitions of particular functions, variables, etc.
  • search, to search in the source code.
  • file, to find files whose name matches a pattern

I love working with this tool alongside vim using a plugin. This allows me to do:

:BI nsIDOMFile
:BF ArchiveReader
:BS ArchiveReader::V

This app is just an experiment. I am still working on it. What I want to do is to reduce the size of the database (right now 800~Mb are required for indexing mozilla-central…). I hope to have something stable and usable soon!

October 4, 2012
Transferable objects for FF

A short introduction: if you want to send data to/from a Web Worker, you have to use postMessage() method. Internally what happens is that the data is duplicated using the structured cloned algorithm and then the copy is sent.

To make this sharing faster, HTML5 specs add a new concept: transferable objects, data is transferred from one context to another without copy. Note: data is no longer available once transferred to the new context. Right now we can transfer just ArrayBuffers, but maybe in the future we will support other data types.

I wrote this patch (Bug 720083) and it will be available in the nightly build soon. Here a demo/benchmark app: demo. Here another one: demo2.

Have fun!

August 18, 2012
Archive API for DOM Blob!

I’m glad to present my first DOM API: The ArchiveReader. This new object allows to open ZIP files and read the content from javascript. Here the webIDL:

interface ArchiveRequest : DOMRequest
{
  [infallible]
  readonly attribute ArchiveReader reader;

  // In case of a getFilenames() request, the result is an array of DOMString
  // In case of a getFile() request, the result is a DOM File
}

[Constructor(Blob blob)]
interface ArchiveReader
{
  ArchiveRequest getFilenames();
  ArchiveRequest getFile(DOMString filename);
};

Ok, maybe this is not clear enough… an example is better: archivereader_example.html (keep in mind that this is a new API and it is just landed in the latest firefox nightly build so probably it won’t work with your browser).

The use of this API is extremely simple: * Create a new ArchiveReader starting from a DOM blob or a DOM file. * Use getFile() or getFilenames(). The return value of these two methods is an ArchiveRequest object.

Note: This API is completely asynchronous.

var blob = ...;
var reader = ArchiveReader(blob);

// how to extract the list of files contained in the archive:
var h = reader.getFilenames();
h.onerror = function() { ... }
h.onsuccess = function() {
  for (var i = 0; i < this.result.length; ++i) {
    something(this.result[i]); // this.result[i] is a DOMString
  }
}

// how to extract a specific file:
var hf = reader.getFile('image.png');
hf.onerror = function() { ... }
hf.onsuccess = function() {
  // this.result is a DOM File
  alert('Filename: ' + this.result.name + '\n' +
        'ContentType: ' + this.result.type + '\n' +
        'Size: ' + this.result.size);
}

The result of a getFile() is a DOM File and it can be used in many ways: FileReader, ArchiveReader, window.URL, etc. Read the example to see how to show images and plain/text files.

Note: this API is a draft. Any update will be posted on https://wiki.mozilla.org/WebAPI/ArchiveAPI

11:34pm  |   URL: http://tmblr.co/ZN3mauRh240a
Filed under: mozilla API 
August 6, 2012
MXR, a command-line tool for mxr.mozilla.org

My fist post is about a tool that I wrote last weekend. It’s a command-line interface for MXR website (Mozilla Cross-Reference) written in Ruby. Here the code: https://github.com/bakulf/mxr

I love MXR and I think it’s an extremely important resource for all the mozillian’ developers. It is a useful web application, however sometimes it’s preferable to have a command-line interface when using a terminal and working on a piece of code.

Here the list of features:

  • it supports any feature of the MXR website: identify, search, file, browse
  • it works in shell mode too.
  • It colourizes the output (-c option)
  • It guesses the right operation to do (it means that you can write ‘identify’ or ‘ident’, or ‘ide’ or ‘i’)
  • In shell mode it offers an easy way to browse the source code using the ID shown by the previous command. Example:
mxr> i nsIDOMFile
Result for: nsIDOMFile

File: (0) content/base/public/nsIDOMFile.idl
Line: (1) 65 -> interface nsIDOMFile : nsIDOMBlob   
    
File: (2) content/base/src/nsFormData.h
Line: (3) 14 -> class nsIDOMFile;  
...
mxr> b 1

…and the file nsIDOMFile.idl line 65 will be shown.

That’s it. It works on my machine and I’m happy with it. Patches are appreciated :)

6:04pm  |   URL: http://tmblr.co/ZN3mauQt1o_X
Filed under: mozilla ruby 
Liked posts on Tumblr: More liked posts »