[-chromium-discuss, +v8-dev] Another reason to implement library code in JavaScript is that calling from JavaScript to JavaScript is fast in V8. Calling from JavaScript to general C++ code is somewhat like a context switch: we have to run code on both entry and exit for garbage collection, to handle allocation failures, and to properly throw and handle JavaScript exceptions.
On Wed, Dec 1, 2010 at 10:02 AM, William Hesse <[email protected]> wrote: > Regarding the JavaScript files in the V8 source code: > 1. They are in JS rather than C because they are simpler to code in JS. JS > provides facilities like property assignment, object allocation, etc. at a > native level with the correct semantics needed to implement the complicated > builtin functions. The compiler should do a good job optimizing these > functions for performance. > > 2. If snapshots are used, some are compiled at browser compile time, and > put in a snapshot. Others are lazily compiled. If snapshots are not used, > they are compiled at browser runtime. > > 3. Extending V8 with C language functions, to be called from the built-in > JS files, is easy using the "intrinsics" or "builtins" notation: functions > starting with % or %_ are compiled as a call to a C function (%) or by > calling a custom C function at compile time (%_). These are in > src/runtime.h. The best way for an embedder to add C functions to V8, > though, is through the API. A function template can be created that > specifies a C function to be called when a function is called, or when > properties of an object are accessed. Functions or objects created from > this template then call that C code at runtime. This does not require > changes to the V8 source. > > This thread will also be posted to the v8-dev mailing list. > > -- > Chromium Discussion mailing list: [email protected] > View archives, change email options, or unsubscribe: > http://groups.google.com/a/chromium.org/group/chromium-discuss > -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
