aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/jsextensions/process.cpp
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@theqtcompany.com>2015-11-11 09:27:31 -0800
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-11-19 11:50:08 +0000
commitb3216a54fc1fc36336648266fd89fc422a02773d (patch)
tree349e0475c168be50f30912b1e5dd082aa5c651b1 /src/lib/corelib/jsextensions/process.cpp
parent5e893162a03cabe3d0c47eff804768b1a7b74969 (diff)
Move shellQuote global function to the Process class.
It isn't used anywhere and isn't documented, so this is completely safe. Change-Id: I347a31a020df0f5926f15607d5db0e65d6e7b345 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/lib/corelib/jsextensions/process.cpp')
-rw-r--r--src/lib/corelib/jsextensions/process.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/corelib/jsextensions/process.cpp b/src/lib/corelib/jsextensions/process.cpp
index 9b1e8f109..2571e1bef 100644
--- a/src/lib/corelib/jsextensions/process.cpp
+++ b/src/lib/corelib/jsextensions/process.cpp
@@ -34,6 +34,7 @@
#include <logging/translator.h>
#include <tools/executablefinder.h>
#include <tools/hostosinfo.h>
+#include <tools/shellutils.h>
#include <QProcess>
#include <QScriptEngine>
@@ -49,6 +50,7 @@ void initializeJsExtensionProcess(QScriptValue extensionObject)
QScriptEngine *engine = extensionObject.engine();
QScriptValue obj = engine->newQMetaObject(&Process::staticMetaObject, engine->newFunction(&Process::ctor));
extensionObject.setProperty(QLatin1String("Process"), obj);
+ obj.setProperty(QStringLiteral("shellQuote"), engine->newFunction(Process::js_shellQuote, 3));
}
QScriptValue Process::ctor(QScriptContext *context, QScriptEngine *engine)
@@ -245,5 +247,21 @@ void Process::writeLine(const QString &str)
(*m_textStream) << '\n';
}
+QScriptValue Process::js_shellQuote(QScriptContext *context, QScriptEngine *engine)
+{
+ if (Q_UNLIKELY(context->argumentCount() < 2)) {
+ return context->throwError(QScriptContext::SyntaxError,
+ QLatin1String("shellQuote expects at least 2 arguments"));
+ }
+ const QString program = context->argument(0).toString();
+ const QStringList args = context->argument(1).toVariant().toStringList();
+ HostOsInfo::HostOs hostOs = HostOsInfo::hostOs();
+ if (context->argumentCount() > 2) {
+ hostOs = context->argument(2).toVariant().toStringList().contains(QLatin1String("windows"))
+ ? HostOsInfo::HostOsWindows : HostOsInfo::HostOsOtherUnix;
+ }
+ return engine->toScriptValue(shellQuote(program, args, hostOs));
+}
+
} // namespace Internal
} // namespace qbs