summaryrefslogtreecommitdiff
path: root/test/code-cache/test-code-cache.js
blob: a4378343010ee61382dd31a1c6370b5529bbcf0a (plain)
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
'use strict';

// Flags: --expose-internals
// This test verifies that the binary is compiled with code cache and the
// cache is used when built in modules are compiled.

require('../common');
const assert = require('assert');
const {
  types: {
    isUint8Array
  }
} = require('util');
const {
  builtinSource,
  codeCache,
  cannotUseCache,
  compiledWithCache,
  compiledWithoutCache
} = require('internal/bootstrap/cache');

assert.strictEqual(
  typeof process.config.variables.node_code_cache_path,
  'string'
);

assert.deepStrictEqual(compiledWithoutCache, []);

const loadedModules = process.moduleLoadList
  .filter((m) => m.startsWith('NativeModule'))
  .map((m) => m.replace('NativeModule ', ''));

for (const key of loadedModules) {
  assert(compiledWithCache.includes(key),
         `"${key}" should've been compiled with code cache`);
}

for (const key of Object.keys(builtinSource)) {
  if (cannotUseCache.includes(key)) continue;
  assert(isUint8Array(codeCache[key]) && codeCache[key].length > 0,
         `Code cache for "${key}" should've been generated`);
}