B2G/gecko/netwerk/test/httpserver/test/test_async_response_sending.js
/**
 * Returns a constructor for an input or output stream callback that will wrap
 * the one provided to it as an argument.
 *
 * @param wrapperCallback : (nsIInputStreamCallback | nsIOutputStreamCallback) : void
 *   the original callback object (not a function!) being wrapped
 * @param name : string
 *   either "onInputStreamReady" if we're wrapping an input stream callback or
 *   "onOutputStreamReady" if we're wrapping an output stream callback
 * @returns function(nsIInputStreamCallback | nsIOutputStreamCallback) : (nsIInputStreamCallback | nsIOutputStreamCallback)
 *   a constructor function which constructs a callback object (not function!)
 *   which, when called, first calls the original callback provided to it and
 *   then calls wrapperCallback
 */
Returns a constructor for an input or output stream callback that will wrap
the one provided to it as an argument.

@param wrapperCallback : (nsIInputStreamCallback | nsIOutputStreamCallback) : void
the original callback object (not a function!) being wrapped
@param name : string
either "onInputStreamReady" if we're wrapping an input stream callback or
"onOutputStreamReady" if we're wrapping an output stream callback
@returns function(nsIInputStreamCallback | nsIOutputStreamCallback) : (nsIInputStreamCallback | nsIOutputStreamCallback)
a constructor function which constructs a callback object (not function!)
which, when called, first calls the original callback provided to it and
then calls wrapperCallback
Returns a constructor for an input or output stream callback that will wrap the one provided to it as an argument . @param wrapperCallback : ( nsIInputStreamCallback | nsIOutputStreamCallback ) : void the original callback object ( not a function! ) being wrapped @param name : string either " onInputStreamReady " if we ' re wrapping an input stream callback or " onOutputStreamReady " if we ' re wrapping an output stream callback @returns function ( nsIInputStreamCallback | nsIOutputStreamCallback ) : ( nsIInputStreamCallback | nsIOutputStreamCallback ) a constructor function which constructs a callback object ( not function! ) which when called first calls the original callback provided to it and then calls wrapperCallback
function createStreamReadyInterceptor(wrapperCallback, name)
{
  return function StreamReadyInterceptor(callback)
  {
    this.wrappedCallback = callback;
    this[name] = function streamReadyInterceptor(stream)
    {
      dumpn("*** StreamReadyInterceptor." + name);
      try
      {
        dumpn("*** calling original " + name + "...");
        callback[name](stream);
      }
      catch (e)
      {
        dumpn("!!! error running inner callback: " + e);
        throw e;
      }
      finally
      {
        dumpn("*** calling wrapper " + name + "...");
        wrapperCallback[name](stream);
      }
    }
  };
}
function createStreamReadyInterceptor ( wrapperCallback , name ) { return function StreamReadyInterceptor ( callback ) { this . wrappedCallback = callback ; this [ name ] = function streamReadyInterceptor ( stream ) { dumpn ( "*** StreamReadyInterceptor." + name ) ; try { dumpn ( "*** calling original " + name + "..." ) ; callback [ name ] ( stream ) ; } catch ( e ) { dumpn ( "!!! error running inner callback: " + e ) ; throw e ; } finally { dumpn ( "*** calling wrapper " + name + "..." ) ; wrapperCallback [ name ] ( stream ) ; } } } ; }
Returns a constructor for an input or output stream callback that will wrap
 the one provided to it as an argument.
Returns a constructor for an input or output stream callback that will wrap the one provided to it as an argument .