You can lookup the function object on the global object in the context like
this:
v8::Local<v8::Function> foo =
v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("foo")));
and then call it like this:
v8::Handle<v8::Value> args[] = { v8::String::New("arg") };
v8::Local<v8::Value> result = foo->Call(foo, 1, args1);
The result will be empty if an exception occoured. You can use a stack
allocated v8::TryCatch in C++ to catch exceptions.
Take a look at the test "FunctionCall" in test/cctest/test-api.cc.
Regards,
Søren
On Fri, May 1, 2009 at 13:35, jimt <[email protected]> wrote:
>
> Hi,
>
> I'm new to V8, and had a simple question.
>
> Suppose I define a simple javascript method ("foo") in my v8 context.
>
> One way to repeatedly call foo from C++ is to evaluate the function
> call (ex. "foo();") with something like ExecuteString(). Is it somehow
> possible to get a more direct reference to the definition of this
> function, so that I may avoid the overhead of compiling the string
> each time before invoking it?
>
> Thanks.
>
> jt
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---