-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Sourceless vm.Script compilation/load #26026
Copy link
Copy link
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stalev8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stalev8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Is your feature request related to a problem? Please describe.
Not exactly a problem, but a capability that I'd like to have in Node.js out of the box (Otherwise we need to recompile it).
Describe the solution you'd like
Currently
pkgis adding a flag"sourceless"that allows compiling avm.Scriptwithout requiring keeping the sources around. When you load the compiled script, it works and has no JS sources attached.It does so with this patch:
https://github.com/zeit/pkg-fetch/blob/master/patches/node.v10.4.1.cpp.patch
There's much more going on in the patch, like adding pkg's bootstrap code, or using its wrapped fs/child_process functions, which is not the issue here and is not of interest for this feature request.
A cleaner patch file, exported to a gist by me can be found here: v10.x v11.x
Describe alternatives you've considered
I've tried passing dummy scripts to
new vm.Scriptwhen loading the cached data, but thecachedDatais rejected.It also has the culprit of CPU compatibility, as by default node only loads the
cachedDataif the CPU features matches exactly, for performance reasons. Whereaspkgallows loading as long as the current CPU has at least the features of the CPU it compiled on. So it has binary compatibility, but may not use new CPU features.I'm aware of the fact that loading sourceless compiled scripts will have some kind of a performance hit, but it's acceptable in cases where you want to have complete obfuscation, or if you want to avoid the load/parse/compile time of a huge JS script, or any other case where you might want/need to transport binaries instead of sources.