有没有办法从 CEF 调用新的运算符?

Is there a way to invoke the new operator from CEF?

我想在 V8 上下文中创建一个 CustomEvent 对象。我尝试使用 .create() 但浏览器不允许我以这种方式创建它。您可以从 CEF 中调用新的操作员吗?

这就是我尝试调用它的方法:

(C++代码)

CefRefPtr<CefV8Value> globalObj = context->GetGlobal();

CefRefPtr<CefV8Value> customEvent = globalObj->GetValue("CustomEvent");
CefRefPtr<CefV8Value> prototype = customEvent->GetValue("prototype");

CefV8ValueList prototypeArgs;
prototypeArgs.push_back(prototype);
prototypeArgs.push_back();

CefRefPtr<CefV8Value> object = globalObj->GetValue("Object");
CefRefPtr<CefV8Value> create = object->GetValue("create");
CefRefPtr<CefV8Value> event = create->ExecuteFunction(NULL, prototypeArgs);

我真的很想有一个简单的方法从 C++ 调用

(Javascript代码)

new CustomEvent("test");

使用CefV8Context::Eval执行您需要的javascript代码。

CefRefPtr<CefV8Value> returnValue;
CefRefPtr<CefV8Exception> exception;
context->Eval("new CustomEvent('test');", returnValue, exception);