src/wtf/trace/providers/webworkerprovider.js
function createInjectionShim(scriptUrl, workerId) {
    // Hacky handling for blob URLs.
    // Unfortunately Chrome doesn't like importScript on blobs inside of the
    // workers, so we need to embed it.
    var resolvedScriptUrl = null;
    var scriptContents = null;
    if (goog.string.startsWith(scriptUrl, 'blob:')) {
      var xhr = new (goog.global['XMLHttpRequest']['raw'] || XMLHttpRequest)();
      xhr.open('GET', scriptUrl, false);
      xhr.send();
      scriptContents = xhr.response;
    } else {
      resolvedScriptUrl = goog.Uri.resolve(baseUri, scriptUrl).toString();
    }

    var shimScriptLines = [
      'this.WTF_WORKER_ID = ' + workerId + ';',
      'this.WTF_WORKER_BASE_URI = "' + goog.global.location.href + '";',
      'importScripts("' + wtfUrl + '");',
      'wtf.trace.prepare({',
      '});',
      'wtf.trace.start();'
    ];

    // Add the script import or directly embed the contents.
    if (resolvedScriptUrl) {
      shimScriptLines.push('importScripts("' + resolvedScriptUrl + '");');
    } else if (scriptContents) {
      shimScriptLines.push('// Embedded: ' + scriptUrl);
      shimScriptLines.push(scriptContents);
    }

    var shimBlob = new Blob([shimScriptLines.join('\n')], {
      'type': 'text/javascript'
    });
    var shimScriptUrl = goog.fs.createObjectUrl(shimBlob);

    return shimScriptUrl;
  }
function createInjectionShim(scriptUrl, workerId) {
    // Hacky handling for blob URLs.
    // Unfortunately Chrome doesn't like importScript on blobs inside of the
    // workers, so we need to embed it.
    var resolvedScriptUrl = null;
    var scriptContents = null;
    if (goog.string.startsWith(scriptUrl, 'blob:')) {
      var xhr = new (goog.global['XMLHttpRequest']['raw'] || XMLHttpRequest)();
      xhr.open('GET', scriptUrl, false);
      xhr.send();
      scriptContents = xhr.response;
    } else {
      resolvedScriptUrl = goog.Uri.resolve(baseUri, scriptUrl).toString();
    }

    var shimScriptLines = [
      'this.WTF_WORKER_ID = ' + workerId + ';',
      'this.WTF_WORKER_BASE_URI = "' + goog.global.location.href + '";',
      'importScripts("' + wtfUrl + '");',
      'wtf.trace.prepare({',
      '});',
      'wtf.trace.start();'
    ];

    // Add the script import or directly embed the contents.
    if (resolvedScriptUrl) {
      shimScriptLines.push('importScripts("' + resolvedScriptUrl + '");');
    } else if (scriptContents) {
      shimScriptLines.push('// Embedded: ' + scriptUrl);
      shimScriptLines.push(scriptContents);
    }

    var shimBlob = new Blob([shimScriptLines.join('\n')], {
      'type': 'text/javascript'
    });
    var shimScriptUrl = goog.fs.createObjectUrl(shimBlob);

    return shimScriptUrl;
  }
function createInjectionShim ( scriptUrl , workerId ) { // Hacky handling for blob URLs. // Unfortunately Chrome doesn't like importScript on blobs inside of the // workers, so we need to embed it. var resolvedScriptUrl = null ; var scriptContents = null ; if ( goog . string . startsWith ( scriptUrl , 'blob:' ) ) { var xhr = new ( goog . global [ 'XMLHttpRequest' ] [ 'raw' ] || XMLHttpRequest ) ( ) ; xhr . open ( 'GET' , scriptUrl , false ) ; xhr . send ( ) ; scriptContents = xhr . response ; } else { resolvedScriptUrl = goog . Uri . resolve ( baseUri , scriptUrl ) . toString ( ) ; } var shimScriptLines = [ 'this.WTF_WORKER_ID = ' + workerId + ';' , 'this.WTF_WORKER_BASE_URI = "' + goog . global . location . href + '";' , 'importScripts("' + wtfUrl + '");' , 'wtf.trace.prepare({' , '});' , 'wtf.trace.start();' ] ; // Add the script import or directly embed the contents. if ( resolvedScriptUrl ) { shimScriptLines . push ( 'importScripts("' + resolvedScriptUrl + '");' ) ; } else if ( scriptContents ) { shimScriptLines . push ( '// Embedded: ' + scriptUrl ) ; shimScriptLines . push ( scriptContents ) ; } var shimBlob = new Blob ( [ shimScriptLines . join ( '\n' ) ] , { 'type' : 'text/javascript' } ) ; var shimScriptUrl = goog . fs . createObjectUrl ( shimBlob ) ; return shimScriptUrl ; }
Creates a shim script that injects WTF.
@param {string} scriptUrl Source script URL.
@param {number} workerId Unique worker ID.
@return {string} Shim script URL.
Creates a shim script that injects WTF .