diff options
Diffstat (limited to 'lib/internal/bootstrap/loaders.js')
-rw-r--r-- | lib/internal/bootstrap/loaders.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index de911eb841..c141c9adcf 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -125,10 +125,15 @@ const config = getBinding('config'); + const codeCache = getInternalBinding('code_cache'); + const compiledWithoutCache = NativeModule.compiledWithoutCache = []; + const compiledWithCache = NativeModule.compiledWithCache = []; + // Think of this as module.exports in this file even though it is not // written in CommonJS style. const loaderExports = { internalBinding, NativeModule }; const loaderId = 'internal/bootstrap/loaders'; + NativeModule.require = function(id) { if (id === loaderId) { return loaderExports; @@ -229,7 +234,29 @@ this.loading = true; try { - const script = new ContextifyScript(source, this.filename); + // (code, filename, lineOffset, columnOffset + // cachedData, produceCachedData, parsingContext) + const script = new ContextifyScript( + source, this.filename, 0, 0, + codeCache[this.id], false, undefined + ); + + // One of these conditions may be false when any of the inputs + // of the `node_js2c` target in node.gyp is modified. + // FIXME(joyeecheung): + // 1. Figure out how to resolve the dependency issue. When the + // code cache was introduced we were at a point where refactoring + // node.gyp may not be worth the effort. + // 2. Calculate checksums in both js2c and generate_code_cache.js + // and compare them before compiling the native modules since + // V8 only checks the length of the source to decide whether to + // reject the cache. + if (!codeCache[this.id] || script.cachedDataRejected) { + compiledWithoutCache.push(this.id); + } else { + compiledWithCache.push(this.id); + } + // Arguments: timeout, displayErrors, breakOnSigint const fn = script.runInThisContext(-1, true, false); const requireFn = this.id.startsWith('internal/deps/') ? |