> I've been wondering whether I could prepare a Context with all the object 
and function templates of my library, save it in a binary file (like V8 
does with the startup snapshot) and then load it on demand, in order to 
gain access to my library's code in the currently executing context. Is 
that even possible?

You can create a snapshot with native code.. the problem is that you will 
need to change the v8 source, so you will end up with a fork of v8, and 
will have to 
manuallly change it every time you want to sync with upstream.

See the code the v8 itself generates for methods in javascript

See the src/builtin dir for implementations.. 

Note the differences in wrapping:

TF_BUILTIN -> Uses the TurboFan backend directly, and you are basically 
writing a portable assembly
in C++ code, that TurboFan will translate to machine code according to the 
host machine

Also the trick there is to use 'CodeStubAssembler' which will give you 
access to the TurboFan frontend

For instance in builtins-array-gen.cc the 'ArrayBuiltinCodeStubAssembler' 
class used in TF_BUILTIN(builtin_method, ArrayBuiltinCodeStubAssembler)
inherits from 'CodeStubAssembler'

Then you have 'BUILTIN(builtin_method)' which is implemented in C++

Once you create your methods you will need to change 
'src/builtins/builtins-definitions.h'
and add a reference to the created methods there with 'CPP(Method)' for C++ 
code or 'TFS(Method) / TFJ(Method)' for 
methods created using the turbofan frontend.

Once you create your builtins, and add it to definitions, you will need to 
change src/bootstrap.cc
and add them to the references and possibly to the runtime global object if 
you want..

Note that if you do that, anywhere you use this custom v8 of yours this 
custom runtime will be available...

Thats the only way im aware, that you can embed native code in the snapshot

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to