node/lib/internal/bootstrap/cache.js
Joyee Cheung 44a5fe1457
process: specialize building and storage of process.config
Instead of treating config.gypi as a JavaScript file, specialize
the processing in js2c and make the serialized result a real JSON
string (with 'true' and 'false' converted to boolean values) so
we don't have to use a custom deserializer during bootstrap.

In addition, store the JSON string separately in NativeModuleLoader,
and keep it separate from the map of the builtin source code, so
we don't have to put it onto `NativeModule._source` and delete it
later, though we still preserve it in `process.binding('natives')`,
which we don't use anymore.

This patch also makes the map of builtin source code and the
config.gypi string available through side-effect-free getters
in C++.

PR-URL: https://github.com/nodejs/node/pull/24816
Reviewed-By: Gus Caplan <me@gus.host>
2018-12-11 06:40:09 +08:00

75 lines
2.0 KiB
JavaScript

'use strict';
// This is only exposed for internal build steps and testing purposes.
// We create new copies of the source and the code cache
// so the resources eventually used to compile builtin modules
// cannot be tampered with even with --expose-internals.
const { NativeModule } = require('internal/bootstrap/loaders');
const { source, compileCodeCache } = internalBinding('native_module');
const { hasTracing } = process.binding('config');
const depsModule = Object.keys(source).filter(
(key) => NativeModule.isDepsModule(key) || key.startsWith('internal/deps')
);
// Modules with source code compiled in js2c that
// cannot be compiled with the code cache.
const cannotUseCache = [
'sys', // Deprecated.
'internal/v8_prof_polyfill',
'internal/v8_prof_processor',
'internal/per_context',
'internal/test/binding',
// TODO(joyeecheung): update the C++ side so that
// the code cache is also used when compiling these two files.
'internal/bootstrap/loaders',
'internal/bootstrap/node'
].concat(depsModule);
// Skip modules that cannot be required when they are not
// built into the binary.
if (process.config.variables.v8_enable_inspector !== 1) {
cannotUseCache.push(
'inspector',
'internal/util/inspector',
);
}
if (!hasTracing) {
cannotUseCache.push('trace_events');
}
if (!process.versions.openssl) {
cannotUseCache.push(
'crypto',
'https',
'http2',
'tls',
'_tls_common',
'_tls_wrap',
'internal/crypto/certificate',
'internal/crypto/cipher',
'internal/crypto/diffiehellman',
'internal/crypto/hash',
'internal/crypto/keygen',
'internal/crypto/pbkdf2',
'internal/crypto/random',
'internal/crypto/scrypt',
'internal/crypto/sig',
'internal/crypto/util',
'internal/http2/core',
'internal/http2/compat',
'internal/streams/lazy_transform',
);
}
module.exports = {
cachableBuiltins: Object.keys(source).filter(
(key) => !cannotUseCache.includes(key)
),
getSource(id) { return source[id]; },
getCodeCache: compileCodeCache,
cannotUseCache
};