FreeBASIC and Google Chrome's V8

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Posts: 1525
Joined: May 27, 2005 17:18

FreeBASIC and Google Chrome's V8

Postby jofers » Feb 07, 2009 12:34

So, Google released a browser this year, and it uses a pretty fast just-in-time Javascript engine, called v8. The library is full of C++ templates, Boost-like pseudo-garbage collection and other unportable code, and I like a challenge, so I wrote part of a wrapper library.


Code: Select all

#include ""

Dim scope_ As v8Scope
Dim context As v8Context
Dim source As v8String
Dim script As v8Script
Dim result As v8Value


source = "obj={}; obj['Message'] = 'Hello' + ', World!'"
script.Compile( source )
result = script.Run()
Print *result.getAscii()




Code: Select all

Hello World!

This is sort of a proof of concept, so I only copied enough functions to run Google's hello world example. Because I had to shed features, I tried the following:
1) Context needs to be explicitely entered and exited (before, stack tricks)
2) All context handles are assumed to be persistant (and not local)
3) All object (String, Value, etc) handles are assumed to be local
4) Objects are not actually constructed until they are assigned to respect stack issues.
5) Google doesn't want you using its HandleScope object in the heap, and they actually put in some safeguards in the header by privatizing the new operator. I had to comment this out to make my wrapper.

The only thing there is this example (running a script and printing out results). I didn't include any of the API to bind C++ objects to Javascript objects, but that should come later.

In the meantime, lemme know what you think. If you want to build it, you need to:
1) Build v8
I recommend building as a shared library (you have to specify), unless you want 2mb executables. If someone wants to build and host a Windows DLL, that wouold

2) Comment out all private methods for HandleScope

3) Compile into a static library using g++

4) Then, just run the example with FB

I only tested this for Linux, any Windows guys want to help me out with some testing?
Posts: 298
Joined: Jun 06, 2005 17:53
Location: Nova Scotia, Canada

Re: FreeBASIC and Google Chrome's V8

Postby Lithium » Feb 27, 2012 23:51

Any more progress on this? I'd like to pick this up, as I need it for my game engine. The engine's nearly complete and I have a half finished game with it, starting to run into some weird parsing errors with SpiderMonkey though. Do you have a version newer than this?

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest