diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-04-12 14:55:37 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-04-13 13:24:40 (GMT) |
commit | 058ba4d19b296464f87504bdc2a2076ee1368e57 (patch) | |
tree | df97586ad78a8402e25672eb5d187b1223160a44 /src/script/api | |
parent | 70141f27e6151f7d7e635ef4ac99fb1f38a1f881 (diff) | |
download | Qt-058ba4d19b296464f87504bdc2a2076ee1368e57.zip Qt-058ba4d19b296464f87504bdc2a2076ee1368e57.tar.gz Qt-058ba4d19b296464f87504bdc2a2076ee1368e57.tar.bz2 |
Make qsTr work in global scope
Search up the call stack to find the first non-empty source URL.
Also and add an autotest for the QtScript translator functions
since there was none (their presence was checked, but not their
behavior...).
Task-number: QTBUG-9775
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 2422108..ccd3e56 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -41,6 +41,7 @@ #include <QtCore/qstringlist.h> #include <QtCore/qmetaobject.h> +#include "CodeBlock.h" #include "Error.h" #include "JSArray.h" #include "JSLock.h" @@ -699,9 +700,18 @@ JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *exec, JSC::JSObject*, JS return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): third argument (n) must be a number"); #ifndef QT_NO_QOBJECT QString context; - QScriptContext *ctx = QScriptEnginePrivate::contextForFrame(exec); - if (ctx && ctx->parentContext()) - context = QFileInfo(QScriptContextInfo(ctx->parentContext()).fileName()).baseName(); + // The first non-empty source URL in the call stack determines the translation context. + { + JSC::ExecState *frame = exec->removeHostCallFrameFlag(); + while (frame) { + if (frame->codeBlock() && frame->codeBlock()->source() + && !frame->codeBlock()->source()->url().isEmpty()) { + context = QFileInfo(frame->codeBlock()->source()->url()).baseName(); + break; + } + frame = frame->callerFrame()->removeHostCallFrameFlag(); + } + } #endif QString text(args.at(0).toString(exec)); #ifndef QT_NO_QOBJECT |