Hi,

I want to use v8 to run very simple scripts. For example add numbers.
I have 3 classes in c++:
* First is a Client, what accept requests and send a result.
* Second is a V8 class.
* Third is a Function, what store a v8::Context , or a v8::Script in
Functions, the name of function(string), and the source of
function(string).

When my Client initialize the functions, it use my V8's Compile
method, what set globals and compile the source, what return by a
Function. It is clear. I want to compile just once, because Client
will get many request.

When an accept is arrived to the Client, it want to use my V8's Run
method, what looks like this :

<code>
int MyV8::Run(Function, ...) {
.......
        v8::HandleScope scope;
        v8::Context::Scope context_scope(functions.get_context());
//1. version It crashed
        v8::Local<v8::Value> result = (functions.get_script())->Run();
//2. version It is OK
        v8::Handle<v8::String> source =
v8::String::New(functions.get_source().c_str());
        v8::Handle<v8::Script> script= v8::Script::Compile(source);
        v8::Local<v8::Value> result = script->Run();
.......
}
 </code>

I don't understand why can't I use the first version. The script is
Persistent, so that is on the heap, and the context is the
same(because global variables are correct in the 2. version.),
moreover script isn't empty.
The 2. version works, but isn't it waste much time to compile again
the source?
Is there any other way?
Can I find a script in the context?
Would it work with Context::Scope?


greetings kod

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to