Files
node/test/code-cache/test-code-cache-generator.js
Joyee Cheung dfd7e99425 src: make a Environment-independent proxy class for NativeModuleLoader
This patch splits `NativeModuleLoader` into two parts - a singleton
that only relies on v8 and `node::Mutex` and a proxy class for
the singleton (`NativeModuleEnv`) that provides limited access to
the singleton as well as C++ bindings for the Node.js binary.
`NativeModuleLoader` is then no longer aware of `Environment`.

PR-URL: https://github.com/nodejs/node/pull/27160
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2019-04-13 17:24:51 +08:00

53 lines
1.3 KiB
JavaScript

'use strict';
// This test verifies that the binary is compiled with code cache and the
// cache is used when built in modules are compiled.
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { spawnSync } = require('child_process');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const readline = require('readline');
const generator = path.join(
__dirname, '..', '..', 'tools', 'generate_code_cache.js'
);
tmpdir.refresh();
const dest = path.join(tmpdir.path, 'cache.cc');
// Run tools/generate_code_cache.js
const child = spawnSync(
process.execPath,
['--expose-internals', generator, dest]
);
assert.ifError(child.error);
if (child.status !== 0) {
console.log(child.stderr.toString());
assert.strictEqual(child.status, 0);
}
// Verifies that:
// - NativeModuleEnv::InitializeCodeCache()
// are defined in the generated code.
// See src/node_native_module_env.h for explanations.
const rl = readline.createInterface({
input: fs.createReadStream(dest),
crlfDelay: Infinity
});
let hasCacheDef = false;
rl.on('line', common.mustCallAtLeast((line) => {
if (line.includes('InitializeCodeCache(')) {
hasCacheDef = true;
}
}, 2));
rl.on('close', common.mustCall(() => {
assert.ok(hasCacheDef);
}));