From 186c2fb6d88c473c6b811f36c87656785131b2d7 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 27 Jun 2018 22:31:01 +0800 Subject: 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 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Gus Caplan Reviewed-By: John-David Dalton Reviewed-By: Colin Ihrig --- lib/internal/bootstrap/loaders.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/internal/bootstrap/loaders.js') diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index c141c9adcf..e85d5de9b7 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -118,6 +118,7 @@ this.exportKeys = undefined; this.loaded = false; this.loading = false; + this.script = null; // The ContextifyScript of the module } NativeModule._source = getBinding('natives'); @@ -165,11 +166,14 @@ return nativeModule.exports; }; + NativeModule.isDepsModule = function(id) { + return id.startsWith('node-inspect/') || id.startsWith('v8/'); + }; + NativeModule.requireForDeps = function(id) { if (!NativeModule.exists(id) || // TODO(TimothyGu): remove when DEP0084 reaches end of life. - id.startsWith('node-inspect/') || - id.startsWith('v8/')) { + NativeModule.isDepsModule(id)) { id = `internal/deps/${id}`; } return NativeModule.require(id); @@ -241,6 +245,8 @@ codeCache[this.id], false, undefined ); + this.script = script; + // One of these conditions may be false when any of the inputs // of the `node_js2c` target in node.gyp is modified. // FIXME(joyeecheung): -- cgit v1.2.3