fix isolate on wrong thread
This commit is contained in:
parent
c01bd1e98c
commit
ac39073551
@ -63,11 +63,13 @@ DoricJSEngine::DoricJSEngine(QObject *parent) : QObject(parent) {
|
||||
// inject timer set & clear
|
||||
DoricTimerExtension *timerExtension =
|
||||
new DoricTimerExtension([this](long timerId) {
|
||||
auto result = QtConcurrent::run(&mJSThreadPool, [this, timerId] {
|
||||
QVariantList arguments;
|
||||
arguments.push_back(QVariant((int)timerId));
|
||||
this->invokeDoricMethod(DoricConstant::DORIC_TIMER_CALLBACK,
|
||||
arguments);
|
||||
});
|
||||
});
|
||||
mJSE->injectGlobalJSFunction(DoricConstant::INJECT_TIMER_SET,
|
||||
timerExtension, "setTimer");
|
||||
mJSE->injectGlobalJSFunction(DoricConstant::INJECT_TIMER_CLEAR,
|
||||
@ -98,8 +100,7 @@ void DoricJSEngine::prepareContext(QString contextId, QString script,
|
||||
mJSE->loadJS(packageContextScript(contextId, script), "Context://" + source);
|
||||
}
|
||||
|
||||
void DoricJSEngine::invokeDoricMethod(QString method,
|
||||
QVariantList arguments) {
|
||||
void DoricJSEngine::invokeDoricMethod(QString method, QVariantList arguments) {
|
||||
return mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, method, arguments);
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@ v8::Local<v8::Value> String2JS(std::string string) {
|
||||
|
||||
v8::Local<v8::Value> Variant2JS(QVariant variant) {
|
||||
v8::Isolate *isolate = v8::Isolate::GetCurrent();
|
||||
|
||||
v8::EscapableHandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context = isolate->GetEnteredOrMicrotaskContext();
|
||||
|
||||
@ -87,6 +88,8 @@ v8::Local<v8::Value> Variant2JS(QVariant variant) {
|
||||
result.ToChecked();
|
||||
}
|
||||
jsValue = array;
|
||||
} else if (variant.type() == QVariant::Int) {
|
||||
jsValue = v8::Number::New(isolate, variant.toDouble());
|
||||
}
|
||||
return handle_scope.Escape(jsValue);
|
||||
}
|
||||
|
Reference in New Issue
Block a user