diff --git a/scriptengines/javascript/scriptenv.cpp b/scriptengines/javascript/scriptenv.cpp index 9b7bb3ef2..4836f0b0f 100644 --- a/scriptengines/javascript/scriptenv.cpp +++ b/scriptengines/javascript/scriptenv.cpp @@ -502,21 +502,24 @@ QScriptValue ScriptEnv::removeEventListener(QScriptContext *context, QScriptEngi return env->removeEventListener(context->argument(0).toString(), context->argument(1)); } -void ScriptEnv::callFunction(QScriptValue &func, const QScriptValueList &args, const QScriptValue &activator) +QScriptValue ScriptEnv::callFunction(QScriptValue &func, const QScriptValueList &args, const QScriptValue &activator) { if (!func.isFunction()) { - return; + return m_engine->undefinedValue(); } QScriptContext *ctx = m_engine->pushContext(); ctx->setActivationObject(activator); - func.call(activator, args); + QScriptValue rv = func.call(activator, args); m_engine->popContext(); if (m_engine->hasUncaughtException()) { emit reportError(this, false); m_engine->clearExceptions(); + return m_engine->undefinedValue(); } + + return rv; } bool ScriptEnv::hasEventListeners(const QString &event) const diff --git a/scriptengines/javascript/scriptenv.h b/scriptengines/javascript/scriptenv.h index 95c795f7e..12af4bac0 100644 --- a/scriptengines/javascript/scriptenv.h +++ b/scriptengines/javascript/scriptenv.h @@ -63,7 +63,7 @@ public: bool addEventListener(const QString &event, const QScriptValue &func); bool removeEventListener(const QString &event, const QScriptValue &func); - void callFunction(QScriptValue &func, const QScriptValueList &args = QScriptValueList(), const QScriptValue &activator = QScriptValue()); + QScriptValue callFunction(QScriptValue &func, const QScriptValueList &args = QScriptValueList(), const QScriptValue &activator = QScriptValue()); bool callEventListeners(const QString &event, const QScriptValueList &args = QScriptValueList()); bool hasEventListeners(const QString &event) const;