// this C++ function is callable from JS
Handle<Value>myFunction(Argments& args) {
v8::Local<v8::Value> func = args[x];
v8::Persistent<v8::Function> func =
v8::Persistent<v8::Function>::Cast(obj);
v8::Handle<v8::Value> returnObj =
func->Call(v8::Context::GetCurrent()->Global(),
<argcount>, <args>);
return Undefined();
}
In your main code, you make it accessible to JavaScript:
globalObject->Set("myFunction", FunctionTemplate::New(myFunction));
You set the globalObject when you create your context.
The JavaScript code can do:
myFunc(JS_fun);
If you'd like to see a straightforward use of v8, you might look at my
project:
http://silkjs.org
Cheers
On Wed, Apr 11, 2012 at 9:52 PM, swathi jakkam <[email protected]>wrote:
> Hi,
>
> how to call the javascript methods from v8?
> i wrote one function in javascript.I want call that function from
> v8.could you please give the solution.
>
> for example:I wrote the code in js file below:
>
> function JS_fun(num) {
> var JS_Dial = {};
>
> JS_Dial.fun_name = "sum";
> JS_Dial.phonenum = num;
>
> var JSON_Str = JSON.stringify(JS_Dial);
> print(JSON_Str);
>
> }
>
> here JS_fun() is implemented in javascript.i need how call this
> JS_fun() from v8.
>
>
> some one said
> ---------------------
> Depends on how do you get a function, you can get it from an argument
> then
> it would be:
> v8::Local<v8::Value> func = args[x];
>
> I think there is a way to get it from Global context too.
>
> and if you have a function object you call it like that:
> v8::Persistent<v8::Function> func =
> v8::Persistent<v8::Function>::Cast(obj);
>
> v8::Handle<v8::Value> returnObj =
> func->Call(v8::Context::GetCurrent()->Global(),
> <argcount>, <args>);
>
>
> but, i am not getting clearly. Could you please Explain clearly.
> could you write any sample example for accessing java script function.
>
>
> Regards,
> swathi.
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users