Skip to content

Sourceless vm.Script compilation/load #26026

@danielgindi

Description

@danielgindi

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 pkg is adding a flag "sourceless" that allows compiling a vm.Script without 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.Script when loading the cached data, but the cachedData is rejected.
It also has the culprit of CPU compatibility, as by default node only loads the cachedData if the CPU features matches exactly, for performance reasons. Whereas pkg allows 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stalev8 engineIssues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions