how to call the javascript methods from v8?

36 views
Skip to first unread message

swathi jakkam

unread,
Apr 11, 2012, 3:00:09 AM4/11/12
to v8-users
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.


Regards,
swathi.

Peter Enerccio

unread,
Apr 11, 2012, 3:27:02 AM4/11/12
to v8-u...@googlegroups.com
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>);


2012/4/11 swathi jakkam <jakkams...@gmail.com>



--
Bc. Peter Vaňušanik
http://www.bishojo.tk

swathi jakkam

unread,
Apr 11, 2012, 7:13:11 AM4/11/12
to v8-users
HI,

i am not getting clearly. Could you please Explain clearly.
could you write any sample example for accessing java script function
from v8.


regards,
swathi.

On Apr 11, 12:27 pm, Peter Enerccio <enerc...@gmail.com> wrote:
> 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>);
>
> 2012/4/11 swathi jakkam <jakkamswath...@gmail.com>
Reply all
Reply to author
Forward
0 new messages