All files / lib/internal v8_prof_processor.js

94.44% Statements 51/54
66.66% Branches 4/6
66.66% Functions 2/3
94.44% Lines 51/54

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 1x 1x 1x 1x   1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
'use strict';
 
const {
  ArrayPrototypePush,
  ArrayPrototypePushApply,
  ArrayPrototypeSlice,
  StringPrototypeSlice,
} = primordials;
 
const Buffer = require('buffer').Buffer;
const console = require('internal/console/global');
const vm = require('vm');
const { SourceTextModule } = require('internal/vm/module');
 
const natives = internalBinding('natives');
 
async function linker(specifier, referencingModule) {
  // Transform "./file.mjs" to "file"
  const file = StringPrototypeSlice(specifier, 2, -4);
  const code = natives[`internal/deps/v8/tools/${file}`];
  return new SourceTextModule(code, { context: referencingModule.context });
}
 
(async () => {
  const tickArguments = [];
  if (process.platform === 'darwin') {
    ArrayPrototypePush(tickArguments, '--mac');
  } else if (process.platform === 'win32') {
    ArrayPrototypePush(tickArguments, '--windows');
  }
  ArrayPrototypePushApply(tickArguments,
                          ArrayPrototypeSlice(process.argv, 1));
 
  const context = vm.createContext({
    arguments: tickArguments,
    write(s) { process.stdout.write(s); },
    printErr(err) { console.error(err); },
    console,
    process,
    Buffer,
  });
 
  const polyfill = natives['internal/v8_prof_polyfill'];
  const script = `(function(module, require) {
    ${polyfill}
  })`;
 
  vm.runInContext(script, context)(module, require);
 
  const tickProcessor = natives['internal/deps/v8/tools/tickprocessor-driver'];
  const tickprocessorDriver = new SourceTextModule(tickProcessor, { context });
  await tickprocessorDriver.link(linker);
  await tickprocessorDriver.evaluate();
})();