如何将对象传递给V8中的JavaScriptcallback
我正在做一个Node模块,并试图传递一个将ObjectWrap
作为参数的子类的实例传递给JavaScriptcallback。
在其他地方,我已经能够成功地展开JavaScript对象到同一个类,使用:
GitCommit *commit = ObjectWrap::Unwrap<GitCommit>(args[0]->ToObject());
我该怎么做呢? 我想将一个GitCommit
实例GitCommit
给一个JavaScriptcallback,如:
Local<Value> argv[] = { // Error code Local<Value>::New(Integer::New(0)), // The commit commit // Instance of GitCommit : ObjectWrap }; // Both error code and the commit are passed, JS equiv: callback(error, commit) ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
这可能吗? 如果有的话,请给我一个例子,或链接到相关文件?
所以你正在编写一个节点插件。 尝试:
Handle<Value> argv[] = { // Error code Integer::New(0), // The commit commit->handle_ // Instance of GitCommit : ObjectWrap }; // Both error code and the commit are passed, JS equiv: callback(error, commit) ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);