History

Fixes for code review

ksuprynowicz committed 4 years ago

Commit 586bd7f1 parent e9bfdd416 files · +142 −117Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp (1 of 16 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp+11−7
@@ -199,6 +199,7 @@ int ScriptEngineQtScript::computeCastPenalty(QScriptValue& val, int destTypeId) · 198 unmodified lines
199199 if (val.isNumber()) {
200200 switch (destTypeId){
201201 case QMetaType::Bool:
202+ // Conversion to bool is acceptable, but numbers are preferred
202203 return 5;
203204 break;
204205 case QMetaType::UInt:
@@ -211,20 +212,24 @@ int ScriptEngineQtScript::computeCastPenalty(QScriptValue& val, int destTypeId) · 6 unmodified lines
211212 case QMetaType::ULongLong:
212213 case QMetaType::LongLong:
213214 case QMetaType::UShort:
215+ // Perfect case. JS doesn't have separate integer and floating point type
214216 return 0;
215217 break;
216218 case QMetaType::QString:
217219 case QMetaType::QByteArray:
218220 case QMetaType::QDateTime:
219221 case QMetaType::QDate:
222+ // Conversion to string should be avoided, it's probably not what we want
220223 return 100;
221224 break;
222225 default:
226+ // Other, not predicted cases
223227 return 5;
224228 }
225229 } else if (val.isString() || val.isDate() || val.isRegExp()) {
226230 switch (destTypeId){
227231 case QMetaType::Bool:
232+ // Conversion from to bool should be avoided if possible, it's probably not what we want
228233 return 100;
229234 case QMetaType::UInt:
230235 case QMetaType::ULong:
@@ -236,12 +241,15 @@ int ScriptEngineQtScript::computeCastPenalty(QScriptValue& val, int destTypeId) · 5 unmodified lines
236241 case QMetaType::ULongLong:
237242 case QMetaType::LongLong:
238243 case QMetaType::UShort:
244+ // Conversion from to number should be avoided if possible, it's probably not what we want
239245 return 100;
240246 case QMetaType::QString:
247+ // Perfect case
241248 return 0;
242249 case QMetaType::QByteArray:
243250 case QMetaType::QDateTime:
244251 case QMetaType::QDate:
252+ // String to string should be slightly preferred
245253 return 5;
246254 default:
247255 return 5;
@@ -249,6 +257,7 @@ int ScriptEngineQtScript::computeCastPenalty(QScriptValue& val, int destTypeId) · 1 unmodified line
249257 } else if (val.isBool() || val.isBoolean()) {
250258 switch (destTypeId){
251259 case QMetaType::Bool:
260+ // Perfect case
252261 return 0;
253262 break;
254263 case QMetaType::UInt:
@@ -261,12 +270,14 @@ int ScriptEngineQtScript::computeCastPenalty(QScriptValue& val, int destTypeId) · 6 unmodified lines
261270 case QMetaType::ULongLong:
262271 case QMetaType::LongLong:
263272 case QMetaType::UShort:
273+ // Using function with bool parameter should be preferred over converted bool to nimber
264274 return 5;
265275 break;
266276 case QMetaType::QString:
267277 case QMetaType::QByteArray:
268278 case QMetaType::QDateTime:
269279 case QMetaType::QDate:
280+ // Bool probably shouldn't be converted to string if there are better alternatives
270281 return 50;
271282 break;
272283 default:
@@ -292,13 +303,6 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 19 unmodified lines
292303 }
293304 }
294305 }
295−/* if (QMetaType(destTypeId).name() == "MenuItemProperties") {
296− qDebug() << "castValueToVariant MenuItemProperties " << destTypeId << "map size: " << _customTypes.size();
297− for (auto iter = _customTypes.keyBegin(); iter != _customTypes.keyEnd(); iter++){
298− qDebug() << (*iter);
299− }
300− printf("castValueToVariant MenuItemProperties");
301− }*/
302306
303307 if (destTypeId == qMetaTypeId<ScriptValue>()) {
304308 dest = QVariant::fromValue(ScriptValue(new ScriptValueQtWrapper(this, val)));

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