History

Fixed evaluateInClosure and other V8 stuff

ksuprynowicz committed 3 years ago

Commit 70d4a431 parent cc20ced8 files · +378 −191Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8_cast.cpp (1 of 8 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8_cast.cpp+21−11
@@ -292,9 +292,18 @@ int ScriptEngineV8::computeCastPenalty(const V8ScriptValue& v8Val, int destTypeI · 291 unmodified lines
292292 }
293293
294294 bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& dest, int destTypeId) {
295+ v8::Locker locker(_v8Isolate);
296+ v8::Isolate::Scope isolateScope(_v8Isolate);
295297 v8::HandleScope handleScope(_v8Isolate);
298+ v8::Context::Scope contextScope(_v8Context.Get(_v8Isolate));
296299 const v8::Local<v8::Value> val = v8Val.constGet();
297300
301+ // Conversion debugging:
302+ if (destTypeId == QMetaType::QVariant && val->IsBoolean()) {
303+ //It's for placing breakpoint here
304+ qDebug() << "Conversion Debug: " << scriptValueDebugDetailsV8(v8Val);
305+ }
306+
298307 // if we're not particularly interested in a specific type, try to detect if we're dealing with a registered type
299308 if (destTypeId == QMetaType::UnknownType) {
300309 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);
@@ -376,9 +385,10 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de · 75 unmodified lines
376385 }
377386 // V8TODO
378387 errorMessage = QString() + "Conversion failure: " + QString(*v8::String::Utf8Value(_v8Isolate, val->ToDetailString(getConstContext()).ToLocalChecked()))
379− + "to variant. Destination type: " + QMetaType::typeName(destTypeId);
388+ + "to variant. Destination type: " + QMetaType::typeName(destTypeId) +" details: "+ scriptValueDebugDetailsV8(v8Val);
380389 qDebug() << errorMessage;
381− Q_ASSERT(false);
390+
391+ //Q_ASSERT(false);
382392 //dest = val->ToVariant();
383393 break;
384394 case QMetaType::Bool:
@@ -440,16 +450,16 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de · 55 unmodified lines
440450 case QMetaType::QVariant:
441451 if (val->IsUndefined()) {
442452 dest = QVariant();
443− break;
453+ return true;
444454 }
445455 if (val->IsNull()) {
446456 dest = QVariant::fromValue(nullptr);
447− break;
457+ return true;
448458 }
449459 if (val->IsBoolean()) {
450460 //V8TODO is it right isolate? What if value from different script engine is used here
451461 dest = QVariant::fromValue(val->BooleanValue(_v8Isolate));
452− break;
462+ return true;
453463 }
454464 if (val->IsString()) {
455465 //V8TODO is it right context? What if value from different script engine is used here
@@ -457,30 +467,30 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de · 1 unmodified line
457467 Q_ASSERT(*string != nullptr);
458468 dest = QVariant::fromValue(QString(*string));
459469 //dest = QVariant::fromValue(val->ToString(_v8Context.Get(_v8Isolate)).ToLocalChecked()->);
460− break;
470+ return true;
461471 }
462472 if (val->IsNumber()) {
463473 dest = QVariant::fromValue(val->ToNumber(_v8Context.Get(_v8Isolate)).ToLocalChecked()->Value());
464− break;
474+ return true;
465475 }
466476 {
467477 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);
468478 if (obj) {
469479 dest = QVariant::fromValue(obj);
470− break;
480+ return true;
471481 }
472482 }
473483 {
474484 QVariant var = ScriptVariantV8Proxy::unwrap(v8Val);
475485 if (var.isValid()) {
476486 dest = var;
477− break;
487+ return true;
478488 }
479489 }
480490 errorMessage = QString() + "Conversion to variant failed: " + QString(*v8::String::Utf8Value(_v8Isolate, val->ToDetailString(getConstContext()).ToLocalChecked()))
481− + " Destination type: " + QMetaType::typeName(destTypeId);
491+ + " Destination type: " + QMetaType::typeName(destTypeId) + " Value details: " + scriptValueDebugDetailsV8(v8Val);
482492 qDebug() << errorMessage;
483− break;
493+ return false;
484494 default:
485495 // check to see if this is a pointer to a QObject-derived object
486496 if (QMetaType::typeFlags(destTypeId) & (QMetaType::PointerToQObject | QMetaType::TrackingPointerToQObject)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t