B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
 * Register a message type that gets associated with a specific set of callbacks
 * keyed by 'cmd' for received messages.
 */
Register a message type that gets associated with a specific set of callbacks
keyed by 'cmd' for received messages.
Register a message type that gets associated with a specific set of callbacks keyed by ' cmd ' for received messages .
function registerInstanceType(type) {
  var uid = 0;
  var instanceMap = {};
  listeners[type] = function receiveInstanceMessage(data) {
    var instanceListener = instanceMap[data.uid];
    if (!instanceListener)
      return;
    instanceListener(data);
  };
  return {
    register: function(instanceListener) {
      var thisUid = uid++;
      instanceMap[thisUid] = instanceListener;
      return {
        sendMessage: function sendInstanceMessage(cmd, args) {
          window.postMessage({ type: type, uid: thisUid,
                               cmd: cmd, args: args });
        },
        unregister: function unregisterInstance() {
          delete instanceMap[thisUid];
        }
      };
    },
  };
}
function registerInstanceType ( type ) { var uid = 0 ; var instanceMap = { } ; listeners [ type ] = function receiveInstanceMessage ( data ) { var instanceListener = instanceMap [ data . uid ] ; if ( ! instanceListener ) return ; instanceListener ( data ) ; } ; return { register : function ( instanceListener ) { var thisUid = uid ++ ; instanceMap [ thisUid ] = instanceListener ; return { sendMessage : function sendInstanceMessage ( cmd , args ) { window . postMessage ( { type : type , uid : thisUid , cmd : cmd , args : args } ) ; } , unregister : function unregisterInstance ( ) { delete instanceMap [ thisUid ] ; } } ; } , } ; }
Register a message type that gets associated with a specific set of callbacks
 keyed by 'cmd' for received messages.
Register a message type that gets associated with a specific set of callbacks keyed by ' cmd ' for received messages .
//dump('\x1b[34mw => M: send: ' + type + ' ' + thisUid + ' ' + cmd + '\x1b[0m\n');