How can i call a JavaScript object's method from C++'?

65 views
Skip to first unread message

袁涛

unread,
Nov 1, 2012, 4:41:52 AM11/1/12
to v8-u...@googlegroups.com
like this
class MyClass 
{
     //setter
     //gettter
     public:
     void TestA()
     {

     }
}

Then set FunctionTemplate to js
js can use this: var a = MyClass(); a.fn= function() {}

my question is : in TestA how can i invoke a.fn?
TestA is not call by js , no args , mybe it's a async method
how can i get the Local<object>?

Yang Guo

unread,
Nov 5, 2012, 3:28:57 AM11/5/12
to v8-u...@googlegroups.com
You can use the context to get the global object, use the global object to get to object a (a is a property of the global object), use a to get to function fn (fn is a property of a), then cast it to v8::Function and use its Call method. Take a look at test/cctest/test-api.cc and search for FunctionCall.

Yang
Reply all
Reply to author
Forward
0 new messages