class Point
{
public:
int x_, y_;
Point(int x, int y):x_(x), y_(y){}
void Test(Local<Object> & obj)
{
//Local<Value> value = ref->Get(String::New("onconnect"));
printf("%d", ref->Get(String::New("getX")));
}
};
Handle<Value> PointConstructor(const Arguments& args)
{
Point *p = new Point(x, y);
object->SetInternalField(0, External::New(p));
p->Test();
return object;
}
...
Handle<String> script = String::New("var p = new Point(20, 0); p.onconnect = function(){}; log(p.getX())");
Handle<Script> compiled_script = Script::Compile(script);
方法“测试”mybe是一个异步调用,在anthor线程中运行,当它运行完成时我调用了js方法“onconnect” 我如何在方法Test()?
中调用js mothod:onconnect答案 0 :(得分:1)
我是从内存中写的,某些类型或通话可能略有不同。假设测试收到Point参考:
void Test(Local<Object> obj)
{
String funName = String::New("onconnect");
if (obj->Has(funName)){
Local<Value> fun = obj->Get(funName);
// would suggest to check additionally whether it actually is a function
Local<Value> args[] = {}; // empty arguments
Local<Value> result = fun->AsObject()->CallAsFunction(obj, 0, args);
}
}