The transition from QtScript to QML introduced a propensity to crashing somewhere deep in Qt (in the V4 JIT engine to be exact), at often unexpected moments while editing texts, for users of certain versions of Qt5. It seems these crashes do not occur with Qt 5.9.1 and newer, but not everyone can update (readily) to that version.
Upstream bug report: https://bugreports.qt.io/browse/QTBUG-63045
I have tried to trace the JavaScript expressions that trigger the crashes I've seen myself, come up with a fix or at least a suitable and acceptable workaround (see https://bugs.kde.org/show_bug.cgi?id=385413). This review is for a patch that contains a fix for a specific crash as well as a general workaround.
As far as I can tell the crashes I get (when hitting enter at the end of a line in documents using C style indentation) occur when unwinding the script interpreter stack, for instance when exiting from a while loop (or the equivalent for loop). This particular crash can be avoided by returning early from the procedure containing the loop, instead of exiting from the loop and returning via the shared return statement; see the patch to cstyle.js.
Gentoo have come up with a blunt-force "solution": build QtDeclarative with the V4 JIT disabled. It works just as well to launch applications that are susceptible to the crash with the QV4_FORCE_INTERPRETER env. variable set which has less undesirable effects but is also more cumbersome.
My patch explores an even less invasive approach: it uses the env. variable to disable the JIT when KTextEditor scripts are loaded/parsed, resetting (or unsetting) the variable when the crucial operation is done. The env.var manipulation is done in a dedicated KateScript subclass and is a noop for Qt version 5.9.1 and up.
BUG: 385413