All files / lib/agents chakra.js

68.18% Statements 15/22
58.82% Branches 10/17
100% Functions 3/3
66.67% Lines 14/21

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    1x 1x 1x       38x             34x       34x       34x       33x   33x   9x       9x               9x       1x   1x  
'use strict';
 
const fs = require('fs');
const runtimePath = require('../runtime-path');
const ConsoleAgent = require('../ConsoleAgent');
 
class ChakraAgent extends ConsoleAgent {
  constructor(options) {
    super(options);
    // This is disabled until we can guarantee that
    // the build of ChakraCore is --test-build
    // this.args.push('-Test262');
  }
 
  async evalScript(code, options = {}) {
    Iif (options.module && this.args[0] !== '-module') {
      this.args.unshift('-module');
    }
 
    Iif (!options.module && this.args[0] === '-module') {
      this.args.shift();
    }
 
    return super.evalScript(code, options);
  }
 
  parseError(str) {
    const error = super.parseError(str);
 
    if (!error) { return error }
 
    Iif (error.name === 'JavascriptError') {
      error.name = 'Error';
    }
 
    Iif (error.name === 'CustomError') {
      const match = error.message.match(/\w+: /);
      if (match) {
        error.name = match[0].slice(0, -2);
        error.message = error.message.slice(match[0].length);
      }
    }
 
    return error;
  }
}
 
ChakraAgent.runtime = fs.readFileSync(runtimePath.for('chakra'), 'utf8');
 
module.exports = ChakraAgent;