• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const cp = require('child_process');
5const fs = require('fs');
6const path = require('path');
7const tmpdir = require('../common/tmpdir');
8
9const names = [
10  'ContextifyScript::New',
11  'RunInThisContext',
12  'RunInContext',
13];
14
15if (process.argv[2] === 'child') {
16  const vm = require('vm');
17  vm.runInNewContext('1 + 1');
18} else {
19  tmpdir.refresh();
20
21  const proc = cp.fork(__filename,
22                       [ 'child' ], {
23                         cwd: tmpdir.path,
24                         execArgv: [
25                           '--trace-event-categories',
26                           'node.vm.script',
27                         ]
28                       });
29
30  proc.once('exit', common.mustCall(() => {
31    const file = path.join(tmpdir.path, 'node_trace.1.log');
32
33    assert(fs.existsSync(file));
34    fs.readFile(file, common.mustCall((err, data) => {
35      const traces = JSON.parse(data.toString()).traceEvents
36        .filter((trace) => trace.cat !== '__metadata');
37      traces.forEach((trace) => {
38        assert.strictEqual(trace.pid, proc.pid);
39        assert(names.includes(trace.name));
40      });
41    }));
42  }));
43}
44