• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Tests that vm.createScript and runInThisContext correctly handle errors
3// thrown by option property getters.
4// See https://github.com/nodejs/node/issues/12369.
5
6const common = require('../common');
7const assert = require('assert');
8const execFile = require('child_process').execFile;
9
10const scripts = [];
11
12['filename', 'cachedData', 'produceCachedData', 'lineOffset', 'columnOffset']
13  .forEach((prop) => {
14    scripts.push(`vm.createScript('', {
15      get ${prop} () {
16        throw new Error('xyz');
17      }
18    })`);
19  });
20
21['breakOnSigint', 'timeout', 'displayErrors']
22  .forEach((prop) => {
23    scripts.push(`vm.createScript('').runInThisContext({
24      get ${prop} () {
25        throw new Error('xyz');
26      }
27    })`);
28  });
29
30scripts.forEach((script) => {
31  const node = process.execPath;
32  execFile(node, [ '-e', script ], common.mustCall((err, stdout, stderr) => {
33    assert(stderr.includes('Error: xyz'), 'createScript crashes');
34  }));
35});
36