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
292}292}
293 293
294bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& dest, int destTypeId) {294bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& dest, int destTypeId) {
295 v8::Locker locker(_v8Isolate);
296 v8::Isolate::Scope isolateScope(_v8Isolate);
295 v8::HandleScope handleScope(_v8Isolate);297 v8::HandleScope handleScope(_v8Isolate);
298 v8::Context::Scope contextScope(_v8Context.Get(_v8Isolate));
296 const v8::Local<v8::Value> val = v8Val.constGet();299 const v8::Local<v8::Value> val = v8Val.constGet();
297 300
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
298 // if we're not particularly interested in a specific type, try to detect if we're dealing with a registered type307 // if we're not particularly interested in a specific type, try to detect if we're dealing with a registered type
299 if (destTypeId == QMetaType::UnknownType) {308 if (destTypeId == QMetaType::UnknownType) {
300 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);309 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);
@@ -376,9 +385,10 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de · 75 unmodified lines
376 }385 }
377 // V8TODO386 // V8TODO
378 errorMessage = QString() + "Conversion failure: " + QString(*v8::String::Utf8Value(_v8Isolate, val->ToDetailString(getConstContext()).ToLocalChecked()))387 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);
380 qDebug() << errorMessage;389 qDebug() << errorMessage;
381 Q_ASSERT(false);390
391 //Q_ASSERT(false);
382 //dest = val->ToVariant();392 //dest = val->ToVariant();
383 break;393 break;
384 case QMetaType::Bool:394 case QMetaType::Bool:
@@ -440,16 +450,16 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de · 55 unmodified lines
440 case QMetaType::QVariant:450 case QMetaType::QVariant:
441 if (val->IsUndefined()) {451 if (val->IsUndefined()) {
442 dest = QVariant();452 dest = QVariant();
443 break;453 return true;
444 }454 }
445 if (val->IsNull()) {455 if (val->IsNull()) {
446 dest = QVariant::fromValue(nullptr);456 dest = QVariant::fromValue(nullptr);
447 break;457 return true;
448 }458 }
449 if (val->IsBoolean()) {459 if (val->IsBoolean()) {
450 //V8TODO is it right isolate? What if value from different script engine is used here460 //V8TODO is it right isolate? What if value from different script engine is used here
451 dest = QVariant::fromValue(val->BooleanValue(_v8Isolate));461 dest = QVariant::fromValue(val->BooleanValue(_v8Isolate));
452 break;462 return true;
453 }463 }
454 if (val->IsString()) {464 if (val->IsString()) {
455 //V8TODO is it right context? What if value from different script engine is used here465 //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
457 Q_ASSERT(*string != nullptr);467 Q_ASSERT(*string != nullptr);
458 dest = QVariant::fromValue(QString(*string));468 dest = QVariant::fromValue(QString(*string));
459 //dest = QVariant::fromValue(val->ToString(_v8Context.Get(_v8Isolate)).ToLocalChecked()->);469 //dest = QVariant::fromValue(val->ToString(_v8Context.Get(_v8Isolate)).ToLocalChecked()->);
460 break;470 return true;
461 }471 }
462 if (val->IsNumber()) {472 if (val->IsNumber()) {
463 dest = QVariant::fromValue(val->ToNumber(_v8Context.Get(_v8Isolate)).ToLocalChecked()->Value());473 dest = QVariant::fromValue(val->ToNumber(_v8Context.Get(_v8Isolate)).ToLocalChecked()->Value());
464 break;474 return true;
465 }475 }
466 {476 {
467 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);477 QObject* obj = ScriptObjectV8Proxy::unwrap(v8Val);
468 if (obj) {478 if (obj) {
469 dest = QVariant::fromValue(obj);479 dest = QVariant::fromValue(obj);
470 break;480 return true;
471 }481 }
472 }482 }
473 {483 {
474 QVariant var = ScriptVariantV8Proxy::unwrap(v8Val);484 QVariant var = ScriptVariantV8Proxy::unwrap(v8Val);
475 if (var.isValid()) {485 if (var.isValid()) {
476 dest = var;486 dest = var;
477 break;487 return true;
478 }488 }
479 }489 }
480 errorMessage = QString() + "Conversion to variant failed: " + QString(*v8::String::Utf8Value(_v8Isolate, val->ToDetailString(getConstContext()).ToLocalChecked()))490 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);
482 qDebug() << errorMessage;492 qDebug() << errorMessage;
483 break;493 return false;
484 default:494 default:
485 // check to see if this is a pointer to a QObject-derived object495 // check to see if this is a pointer to a QObject-derived object
486 if (QMetaType::typeFlags(destTypeId) & (QMetaType::PointerToQObject | QMetaType::TrackingPointerToQObject)) {496 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