src/wtf/trace/providers/webworkerprovider.js
function(scriptUrl) {
    goog.base(this, descriptor);

    /**
     * Tracking ID.
     * @type {number}
     * @private
     */
    this.workerId_ = nextWorkerId++;

    // Create the child worker.
    // If we are injecting generate a shim script and use that.
    var newScriptUrl = scriptUrl;
    if (injecting) {
      newScriptUrl = createInjectionShim(scriptUrl, this.workerId_);
    }
    var scope = workerCtorEvent(scriptUrl, this.workerId_);
    goog.global['Worker'] = originalWorker;
    var previousGlobalWorker = goog.global['Worker'];
    var handle;
    try {
      handle = new originalWorker(newScriptUrl);
    } finally {
      goog.global['Worker'] = previousGlobalWorker;
      wtf.trace.leaveScope(scope);
    }

    /**
     * Handle to the underlying worker instance.
     * @type {!Worker}
     * @private
     */
    this.handle_ = handle;

    /**
     * Event type trackers, by name.
     * @type {!Object.<Function>}
     * @private
     */
    this.trackers_ = {};

    this.setEventHook('error', function(e) {
      wtf.trace.appendScopeData('id', this.workerId_);
    }, this);
    this.setEventHook('message', function(e) {
      wtf.trace.appendScopeData('id', this.workerId_);
    }, this);

    // Always hook onmessage.
    // By doing it here we get first access to the event.
    var self = this;
    this.handle_.addEventListener('message', function(e) {
      // Sniff provider messages.
      if (!e.data['__wtf_worker_msg__']) {
        return;
      }
      e['__wtf_ignore__'] = true;

      var value = e.data['value'];
      switch (e.data['command']) {
        case 'snapshot':
          var result = pendingSnapshots[value['id']];
          delete pendingSnapshots[value['id']];
          if (!result.getError()) {
            result.setValue(value['data']);
          }
          break;
        case 'close':
          goog.array.remove(provider.childWorkers_, self);
          break;
      }
    }, false);

    provider.childWorkers_.push(this);
  }
function(scriptUrl) {
    goog.base(this, descriptor);

    /**
     * Tracking ID.
     * @type {number}
     * @private
     */
    this.workerId_ = nextWorkerId++;

    // Create the child worker.
    // If we are injecting generate a shim script and use that.
    var newScriptUrl = scriptUrl;
    if (injecting) {
      newScriptUrl = createInjectionShim(scriptUrl, this.workerId_);
    }
    var scope = workerCtorEvent(scriptUrl, this.workerId_);
    goog.global['Worker'] = originalWorker;
    var previousGlobalWorker = goog.global['Worker'];
    var handle;
    try {
      handle = new originalWorker(newScriptUrl);
    } finally {
      goog.global['Worker'] = previousGlobalWorker;
      wtf.trace.leaveScope(scope);
    }

    /**
     * Handle to the underlying worker instance.
     * @type {!Worker}
     * @private
     */
    this.handle_ = handle;

    /**
     * Event type trackers, by name.
     * @type {!Object.<Function>}
     * @private
     */
    this.trackers_ = {};

    this.setEventHook('error', function(e) {
      wtf.trace.appendScopeData('id', this.workerId_);
    }, this);
    this.setEventHook('message', function(e) {
      wtf.trace.appendScopeData('id', this.workerId_);
    }, this);

    // Always hook onmessage.
    // By doing it here we get first access to the event.
    var self = this;
    this.handle_.addEventListener('message', function(e) {
      // Sniff provider messages.
      if (!e.data['__wtf_worker_msg__']) {
        return;
      }
      e['__wtf_ignore__'] = true;

      var value = e.data['value'];
      switch (e.data['command']) {
        case 'snapshot':
          var result = pendingSnapshots[value['id']];
          delete pendingSnapshots[value['id']];
          if (!result.getError()) {
            result.setValue(value['data']);
          }
          break;
        case 'close':
          goog.array.remove(provider.childWorkers_, self);
          break;
      }
    }, false);

    provider.childWorkers_.push(this);
  }
function ( scriptUrl ) { goog . base ( this , descriptor ) ; /**
     * Tracking ID.
     * @type {number}
     * @private
     */ this . workerId_ = nextWorkerId ++ ; // Create the child worker. // If we are injecting generate a shim script and use that. var newScriptUrl = scriptUrl ; if ( injecting ) { newScriptUrl = createInjectionShim ( scriptUrl , this . workerId_ ) ; } var scope = workerCtorEvent ( scriptUrl , this . workerId_ ) ; goog . global [ 'Worker' ] = originalWorker ; var previousGlobalWorker = goog . global [ 'Worker' ] ; var handle ; try { handle = new originalWorker ( newScriptUrl ) ; } finally { goog . global [ 'Worker' ] = previousGlobalWorker ; wtf . trace . leaveScope ( scope ) ; } /**
     * Handle to the underlying worker instance.
     * @type {!Worker}
     * @private
     */ this . handle_ = handle ; /**
     * Event type trackers, by name.
     * @type {!Object.<Function>}
     * @private
     */ this . trackers_ = { } ; this . setEventHook ( 'error' , function ( e ) { wtf . trace . appendScopeData ( 'id' , this . workerId_ ) ; } , this ) ; this . setEventHook ( 'message' , function ( e ) { wtf . trace . appendScopeData ( 'id' , this . workerId_ ) ; } , this ) ; // Always hook onmessage. // By doing it here we get first access to the event. var self = this ; this . handle_ . addEventListener ( 'message' , function ( e ) { // Sniff provider messages. if ( ! e . data [ '__wtf_worker_msg__' ] ) { return ; } e [ '__wtf_ignore__' ] = true ; var value = e . data [ 'value' ] ; switch ( e . data [ 'command' ] ) { case 'snapshot' : var result = pendingSnapshots [ value [ 'id' ] ] ; delete pendingSnapshots [ value [ 'id' ] ] ; if ( ! result . getError ( ) ) { result . setValue ( value [ 'data' ] ) ; } break ; case 'close' : goog . array . remove ( provider . childWorkers_ , self ) ; break ; } } , false ) ; provider . childWorkers_ . push ( this ) ; }
Worker shim.
@param {string} scriptUrl Script URL.
@constructor
@extends {wtf.trace.eventtarget.BaseEventTarget}
Worker shim .