【发布时间】:2020-01-30 14:23:05
【问题描述】:
我有一个v8::Persistent<v8::Function>,需要将其转换为void(__cdecl*) 函数。有人建议我使用包装器,但我不确定如何做到这一点。
【问题讨论】:
我有一个v8::Persistent<v8::Function>,需要将其转换为void(__cdecl*) 函数。有人建议我使用包装器,但我不确定如何做到这一点。
【问题讨论】:
例如这样:
v8::Persistent<v8::Function> func = ...;
v8::Persistent<v8::Context> context = ...;
v8::Isolate* isolate = ...;
void cpp_func(...) {
v8::Local<v8::Context> ctx = v8::Local<v8::Context>::New(isolate, context);
// The "this" inside the JavaScript function:
v8::Local<v8::Object> arg_this = ctx->Global();
// Arguments to the JavaScript function, of type `v8::Local<v8::Value>[]`.
int argc = 0;
int argv = nullptr;
func->Call(ctx, arg_this, argc, argv);
}
V8 的test-api.cc 中还有更多示例。
【讨论】: