summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/qscriptengine.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 2417d80..58c8d83 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -42,6 +42,7 @@
#include <math.h>
+#include "CodeBlock.h"
#include "Error.h"
#include "JSLock.h"
#include "Interpreter.h"
@@ -792,9 +793,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
JSC::UString 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
JSC::UString text = args.at(0).toString(exec);
#ifndef QT_NO_QOBJECT