Files
node/test/code-cache/test-code-cache.js
Joyee Cheung 186c2fb6d8 build: create V8 code cache after script is run
This patch makes it possible to generate the code cache
for the builtins directly from the original script object
(instead of compiling a new one) and after the script has
been run (via `NativeModule.require`). Before this patch
only the top level functions (the wrapped ones)
are included in the cache, after this patch the inner
functions in those modules will be included as well.

Also blacklists modules from dependencies like V8 and
node-inspect since we cannot guarantee that they are suitable
to be executed directly.

PR-URL: https://github.com/nodejs/node/pull/21567
Refs: https://github.com/nodejs/node/issues/21563
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-07-27 14:51:27 +08:00

41 lines
1010 B
JavaScript

'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 {
cachableBuiltins,
codeCache,
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 cachableBuiltins) {
assert(isUint8Array(codeCache[key]) && codeCache[key].length > 0,
`Code cache for "${key}" should've been generated`);
}