• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const tmpdir = require('../common/tmpdir');
4const assert = require('assert');
5
6// Attempts to test that the source map JS code run on process shutdown
7// does not call any user-defined JS code.
8
9const { Worker, workerData, parentPort } = require('worker_threads');
10
11if (!workerData) {
12  tmpdir.refresh();
13  process.env.NODE_V8_COVERAGE = tmpdir.path;
14
15  // Count the number of some calls that should not be made.
16  const callCount = new Int32Array(new SharedArrayBuffer(4));
17  const w = new Worker(__filename, { workerData: { callCount } });
18  w.on('message', common.mustCall(() => w.terminate()));
19  w.on('exit', common.mustCall(() => {
20    assert.strictEqual(callCount[0], 0);
21  }));
22  return;
23}
24
25const { callCount } = workerData;
26
27function increaseCallCount() { callCount[0]++; }
28
29// Increase the call count when a forbidden method is called.
30Object.getPrototypeOf((new Map()).entries()).next = increaseCallCount;
31Map.prototype.entries = increaseCallCount;
32Object.keys = increaseCallCount;
33Object.create = increaseCallCount;
34Object.hasOwnProperty = increaseCallCount;
35for (const property of ['_cache', 'lineLengths', 'url']) {
36  Object.defineProperty(Object.prototype, property, {
37    get: increaseCallCount,
38    set: increaseCallCount
39  });
40}
41
42parentPort.postMessage('done');
43