Raw Access to V8

Think CEF could benefit from a new feature or capability? Discuss CEF feature requests here.

Raw Access to V8

Postby chromuser » Thu Dec 10, 2009 4:31 pm

I'd like some way to allow raw access to V8 (or an api that is compatible with v8).

I have a project that will require both a javascript api in browser and the same javascript api without a browser (ie: a simple script file). Having to port the work on the non-browser script api to match that CEF would be difficult and time-consuming.

Any idea if this is possible/likely to be included in CEF?
If not, any idea how to implement this anyways?

Thanks for the work on CEF, by the way!
chromuser
Newbie
 
Posts: 4
Joined: Thu Dec 10, 2009 4:24 pm

Re: Raw Access to V8

Postby magreenblatt » Thu Dec 10, 2009 10:44 pm

What does your non-browser script do and when is it executed? You can call CefFrame::ExecuteJavaScript() using any browser window to execute arbitrary JS code that you specify. The executed JS code can even communicate with a V8 extension that you create in order to call back into native code.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Raw Access to V8

Postby chromuser » Fri Dec 11, 2009 12:23 am

In case I wasn't clear, the javascript api without a browser is more of scripting api for for accessing files, starting programs, interacting with a console etc. etc. (it's completely separate from CEF).
Basically it allows one to use ecmascript/javascript to interact with the OS.

We then want to embed into CEF what we've already created in v8 so that if we change anything in the api, we don't need to update two modules of code. Plus, I'd assume using the raw objects that we've created for the v8 engine would be faster than creating javascript functions/objects to act as interfaces which then call native functions.
chromuser
Newbie
 
Posts: 4
Joined: Thu Dec 10, 2009 4:24 pm

Re: Raw Access to V8

Postby magreenblatt » Tue Dec 15, 2009 12:23 pm

You could probably build V8 as a DLL that is linked from both CEF and your application. See the V8 build instructions:
http://code.google.com/p/v8/wiki/BuildingOnWindows
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Raw Access to V8

Postby chromuser » Tue Dec 15, 2009 11:03 pm

I don't understand. How would this allow raw access to the browser V8 (javascript) engine?
chromuser
Newbie
 
Posts: 4
Joined: Thu Dec 10, 2009 4:24 pm

Re: Raw Access to V8

Postby magreenblatt » Wed Dec 16, 2009 9:34 am

The V8 engine is a separate project that Chromium/CEF builds as a library and links against statically. In order to use V8 directly from your application your application needs to link against V8 as well. Building V8 as a dynamic library (DLL) will allow both Chromium/CEF and your application to share the same code module. When using V8 directly from your application you will have a V8 context separate from the browser's V8 context. The V8 project page has information on how to use V8 directly from an application.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Raw Access to V8

Postby chromuser » Wed Dec 16, 2009 1:03 pm

Sorry, I realize I wasn't using the correct terminology (we made our v8 design nearly a year ago, so it's been since I worked with V8).
What I meant by raw access to the V8 Engine was that I wanted raw access to the browser V8 context so that we can add our V8 object templates (that we've already created separately for scripting) to a webpage.

As an example, we have a V8 object template (in C++) named File with a readAll method. In our stand alone scripting console we can do:
Code: Select all
var file = new File("D:/exampleData.txt");
windows.messageBox(file.readAll());


Now, we'd like to take our object template and be able to use it in the browser (by adding our object template to the browser context):
Code: Select all
var file = new File("D:/exampleData.txt");
document.getElementById('example').innerHTML = file.readAll()

Rather than recreate this functionality using "native function", if we had the browser V8 context, we could add the objects directly.

Perhaps now you understand what we would like to do?
I should have refreshed myself on V8 terminology before posting - sorry about that.

If you don't understand, here's my last ditch attempt:
We have a library which contains various V8 object and function templates. We already use this library with an application which allows us to script programs using javascript.
Now what we want to do is easily add this library to the browser context so that we can use those same objects and templates in html/javascript without modifying the library [too much].
chromuser
Newbie
 
Posts: 4
Joined: Thu Dec 10, 2009 4:24 pm

Re: Raw Access to V8

Postby magreenblatt » Wed Dec 16, 2009 2:05 pm

You could modify the CefV8Object class to expose the underlying V8 object and then bind your V8 objects to the browser window object in CefHandler::HandleJSBinding(). You will probably still need to build V8 as a dynamic library and link against it from both CEF and your application in order for everything to work correctly. Be aware, though, that this approach is fragile, unsupported, and will not work with future versions of CEF that run the renderer in a separate process.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Raw Access to V8

Postby magreenblatt » Wed Dec 16, 2009 2:07 pm

Perhaps a better approach would be to build your V8 library as part of CEF project if it can be separated from your application? There are lots of examples of built-in V8 extensions in the Chromium sources.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Raw Access to V8

Postby Benvie » Thu Aug 09, 2012 1:40 am

Resurrecting this really old thread because I have the precise same question. Specifically, I want to have Node.js and CEF built against the same V8, and I want to expose the browser global to node similar to how Node wraps multiple V8 contexts and provides a module to JS for doing this. Do you have any recommendation on what would be the least fragile way to go about getting direct access to the V8 context handle for this purpose?

We are already working with CEF loaded in the same thread as Node.js and already are juggling both contexts at once, but we'd really like to bridge the gap, get them running on the same V8, and open up one side to the other in JSLand directly instead of the hack we're using now.
Benvie
Techie
 
Posts: 20
Joined: Wed Aug 10, 2011 2:58 pm

Next

Return to Feature Request Forum

Who is online

Users browsing this forum: No registered users and 11 guests