I did some searching around the NodeJS and v8 code.
First on NodeJS repository I found where the source code is first loaded executing on src/node.cc, line 1128:
Local<Value> ExecuteString(Handle<String> source, Handle<Value> filename)
Which first compiles the string, (and later executes), using:
Local<v8::Script> script = v8::Script::Compile(source, filename);
Taking a look at the v8 source code at deps/v8/include/v8.h, line 639, the Compile function returns:
Compiled script object, bound to the context that was active
when this function was called. When run it will always use this
context.
I am not sure what the script being bound to the context implies, but I would argue that it is not just a binary object that you can save and transfer to another machine without having to transfer the whole context.
EDIT: Taking a deeper look at v8.h, there is also a ScriptData class, that pre-compiles a script to make the compilation faster, and that can be used with the Script class, but the Script class still requires the original source when loading the script. (Maybe for when printing errors, it knows where the error origin.)
In summary, I do not think it is possible without much work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…