On Sat, Dec 31, 2011 at 11:49 AM, JustinYu <[email protected]> wrote:
> V8EXPORT Local<Value>Object::CallAsFunction(Handle<Object> recv,
> int argc,
> Handle<Value> argv[]);
>
> what does the first argument means? How can i use this quesiton .
>
> I just want to Call Back the JS function which send into my function
> as an argument.
>
That's not the function you want for this case. Assuming JS code which
looks like:
myNativeCallback( function(){...} );
you want something like:
Local<Function> f( Function::Cast( args[0] ) ); // achtung: will crash if
arg is-not-a Function!
f->Call( args.This(), 0, 0 );
The arguments to Call() are the same as for Object::CallAsFunction(). The
1st argument (recv in your example) is the "this" object for the call. You
can normally set it to whatever you like (whatever you define as "correct"
for your use case).
Always be sure to check if the arg is-a Function:
Handle<Value> arg = args[0];
if( !arg.IsEmpty() && arg->IsFunction() ) { ... }
because if you use any of the [V8Type]::Cast() variants on a different type
then v8 will assert and crash your app. (PS: i don't know if 'arg' in the
above example will ever possibly be IsEmpty() (because the API docs are
IsEmpty() ;) but it doesn't hurt to check.)
--
----- stephan beal
http://wanderinghorse.net/home/stephan/
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users