如何为 v8::P ersistent<v8::Function> 创建到 c++ 函数的包装器
How do I create wrapper for a v8::Persistent<v8::Function> to a c++ function
我有一个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 中还有更多的例子。
相关文章:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 在 G++ v8.2.0 中使用 std::experimental::可选
- 如何为 v8::P ersistent<v8::Function> 创建到 c++ 函数的包装器
- v8::HandleScope::CreateHandle() # 中的致命错误无法在没有 HandleScope 的情
- 如何将节点 V8 字符串转换为 C++ 字符串
- 在 C++ 中嵌入 V8 会导致与 libcpp 相关的"unrecognized external symbol"错误
- 当我使用 V8 库中的 GetInternalField() 时出现分段错误
- 在 v8 JavaScript 中重复调用C++是否有巨大的开销?
- 我可以使用谷歌 v8 在回调函数中获取 JavaScript 函数C++源文本吗?
- 与纯 V8 相比,NodeJS 是否有任何性能缺陷或显著开销?
- V8垃圾收集器回调,用于测量GC活动
- 如何在 C++ 中从 V8 调用 Javascript 函数
- 如何将 v8::FunctionCallbackInfo<v8::Value> 数组从一个隔离复制到另一个隔离?
- 使用导入的函数从嵌入式v8调用webassembly
- v8 源代码中 ArrayMap 函数的回调 fn 参数是什么?
- 如何在 v8 Javascript 中的多个函数中使用相同的上下文?
- 如何使用 v8 本机插件将 C++ 数组交付到 Node.js
- 存储/传递 v8 承诺解析器供以后使用的最佳实践?(结合C++线程)
- v8 不再支持 v8::Value::ToNumber 了吗?
- 如何将wchar_t转换为 V8 字符串?