Port kpac from QtScript
ClosedPublic

Authored by carewolf on Sep 9 2019, 4:18 PM.

Details

Summary

Migrate the QtScript code to QJS classes.

Warning: untested

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
carewolf created this revision.Sep 9 2019, 4:18 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 9 2019, 4:18 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
carewolf requested review of this revision.Sep 9 2019, 4:18 PM
dfaure accepted this revision.Sep 10 2019, 11:36 AM

I'll trust your expertise with such ports.
I wouldn't know how to test this either.

This revision is now accepted and ready to land.Sep 10 2019, 11:36 AM
This revision was automatically updated to reflect the committed changes.
kossebau added inline comments.
src/kpac/script.cpp
316

Hi @carewolf . Curious: Why all the non-const-ref QString argument types here?

Is there a need to do that with Q_INVOKABLE methods somehow?
Asking because clazy falgs these, compare D25039

carewolf added inline comments.Oct 31 2019, 12:13 AM
src/kpac/script.cpp
316

Not really. I prefer to do it that way for invokable as the value will be copied, but const ref works too.

kossebau added inline comments.Oct 31 2019, 12:28 AM
src/kpac/script.cpp
316

So why would it be preferable to have the value be copied there? In general, one prefers to avoid copies, so what is the different motvation here?

carewolf added inline comments.Oct 31 2019, 8:03 AM
src/kpac/script.cpp
316

Invokables can be called asynchronously (queued), if you take a reference and the isn't evaluated immediatly the reference might be invalid by the time the call is evaluated.

kossebau added inline comments.Oct 31 2019, 1:38 PM
src/kpac/script.cpp
316

With queued signals, any const-reference arguments are passed via an internal value-copy IIRC, so references are not out-dated.
Can the same technique not be expected with any usages of invocables, like from scripting engines?

carewolf added inline comments.Oct 31 2019, 5:19 PM
src/kpac/script.cpp
316

Sure, as I said, I only write it this way because a copy should be taken, and while Qt can work around declaring an async argument as a reference, I still consider it bad style to make that mistake.

In any case the difference is basically academic when it comes reference counted Qt containers. You can save some nanoseconds on doing a reference pass when it isn't async, but I have wasted more time hunting down obscure bugs caused by using references in cross-thread methods in other frameworks, so I prefer this. Feel free to change it if you like though. As I said it is just a best practice/coding style for me, and not necessary for Qt invokables.

kossebau added inline comments.Nov 1 2019, 3:06 PM
src/kpac/script.cpp
316

Okay, think I understood. Thanks for your answers :)